update to work with robot-smartness changes. At this point the UI's

unchanged and I'm trying to mimic the old per-game setting using the
new per-robot setting internally.  Still need to change the UI to
allow move than just a boolean choice.
This commit is contained in:
Andy2 2011-01-10 20:46:05 -08:00
parent a656bb8f0c
commit ceab787cdd
3 changed files with 43 additions and 14 deletions

View file

@ -330,7 +330,7 @@ public class GameConfig extends XWActivity
};
check.setOnCheckedChangeListener( lstnr );
Utils.setChecked( m_curDialog, R.id.robot_check, lp.isRobot );
Utils.setChecked( m_curDialog, R.id.robot_check, lp.isRobot() );
Utils.setChecked( m_curDialog, R.id.remote_check, ! lp.isLocal );
}
@ -340,7 +340,7 @@ public class GameConfig extends XWActivity
lp.name = Utils.getText( m_curDialog, R.id.player_name_edit );
lp.password = Utils.getText( m_curDialog, R.id.password_edit );
lp.isRobot = Utils.getChecked( m_curDialog, R.id.robot_check );
lp.setIsRobot( Utils.getChecked( m_curDialog, R.id.robot_check ) );
lp.isLocal = !Utils.getChecked( m_curDialog, R.id.remote_check );
}
@ -459,7 +459,7 @@ public class GameConfig extends XWActivity
check.setOnCheckedChangeListener( lstnr );
Utils.setChecked( this, R.id.use_timer, m_gi.timerEnabled );
Utils.setChecked( this, R.id.smart_robot, 0 < m_gi.robotSmartness );
Utils.setChecked( this, R.id.smart_robot, m_gi.getRobotsAreSmart() );
String fmt = getString( m_notNetworkedGame ?
R.string.title_game_configf
@ -831,8 +831,7 @@ public class GameConfig extends XWActivity
m_gi.timerEnabled = Utils.getChecked( this, R.id.use_timer );
m_gi.gameSeconds = 60 * m_gi.nPlayers *
Utils.getInt( this, R.id.timer_minutes_edit );
m_gi.robotSmartness
= Utils.getChecked( this, R.id.smart_robot ) ? 1 : 0;
m_gi.setRobotsAreSmart( Utils.getChecked( this, R.id.smart_robot ) );
int position = m_phoniesSpinner.getSelectedItemPosition();
m_gi.phoniesAction = CurGameInfo.XWPhoniesChoice.values()[position];

View file

@ -49,13 +49,13 @@ public class CurGameInfo {
public boolean timerEnabled;
public boolean allowPickTiles;
public boolean allowHintRect;
public int robotSmartness;
public XWPhoniesChoice phoniesAction;
public boolean confirmBTConnect; /* only used for BT */
// private int[] m_visiblePlayers;
// private int m_nVisiblePlayers;
private boolean m_inProgress;
private boolean m_smart;
public CurGameInfo( Context context )
{
@ -79,7 +79,6 @@ public class CurGameInfo {
timerEnabled = CommonPrefs.getDefaultTimerEnabled( context );
allowPickTiles = false;
allowHintRect = false;
robotSmartness = 1;
// Always create MAX_NUM_PLAYERS so jni code doesn't ever have
// to cons up a LocalPlayer instance.
@ -90,7 +89,7 @@ public class CurGameInfo {
if ( isNetworked ) {
players[1].isLocal = false;
} else {
players[0].isRobot = true;
players[0].setIsRobot( 1 );
}
}
@ -110,7 +109,6 @@ public class CurGameInfo {
timerEnabled = src.timerEnabled;
allowPickTiles = src.allowPickTiles;
allowHintRect = src.allowHintRect;
robotSmartness = src.robotSmartness;
int ii;
for ( ii = 0; ii < MAX_NUM_PLAYERS; ++ii ) {
@ -133,6 +131,21 @@ public class CurGameInfo {
m_inProgress = inProgress;
}
public boolean getRobotsAreSmart()
{
return m_smart;
}
public void setRobotsAreSmart( boolean smart )
{
m_smart = smart;
for ( int ii = 0; ii < nPlayers; ++ii ) {
if ( players[ii].isRobot() ) {
players[ii].setIsRobot( smart ? 1 : 100 );
}
}
}
/** return true if any of the changes made would invalide a game
* in progress, i.e. require that it be restarted with the new
* params. E.g. changing a player to a robot is harmless for a
@ -152,7 +165,7 @@ public class CurGameInfo {
for ( int ii = 0; ii < nPlayers; ++ii ) {
LocalPlayer me = players[ii];
LocalPlayer him = other.players[ii];
matter = me.isRobot != him.isRobot
matter = me.isRobot() != him.isRobot()
|| me.isLocal != him.isLocal
|| !me.name.equals( him.name );
if ( matter ) {
@ -198,7 +211,7 @@ public class CurGameInfo {
LocalPlayer lp = players[ii];
if ( lp.isLocal || serverRole == DeviceRole.SERVER_STANDALONE ) {
names[ii] = lp.name;
if ( lp.isRobot ) {
if ( lp.isRobot() ) {
names[ii] += " " + context.getString( R.string.robot_name );
}
} else {

View file

@ -22,18 +22,19 @@ package org.eehouse.android.xw4.jni;
import android.content.Context;
import org.eehouse.android.xw4.R;
import junit.framework.Assert;
public class LocalPlayer {
public String name;
public String password;
public int secondsUsed;
public boolean isRobot;
public int robotIQ;
public boolean isLocal;
public LocalPlayer( Context context, int num )
{
isLocal = true;
isRobot = false;
robotIQ = 0; // human
String fmt = context.getString( R.string.playerf );
name = String.format( fmt, num + 1 );
password = "";
@ -42,7 +43,7 @@ public class LocalPlayer {
public LocalPlayer( final LocalPlayer src )
{
isLocal = src.isLocal;
isRobot = src.isRobot;
robotIQ = src.robotIQ;
if ( null != src.name ) {
name = new String(src.name);
}
@ -51,5 +52,21 @@ public class LocalPlayer {
}
secondsUsed = src.secondsUsed;
}
public boolean isRobot()
{
return robotIQ > 0;
}
public void setIsRobot( boolean isRobot )
{
robotIQ = isRobot ? 1 : 0;
}
public void setIsRobot( int iq )
{
Assert.assertTrue( iq > 0 );
robotIQ = iq;
}
}