replace robot smart checkbox with a spinner having three settings.

Keep the kludge whereby the settings in all the players are kept the
same.
This commit is contained in:
Andy2 2011-01-13 06:48:50 -08:00
parent d2ddc5cee7
commit 9ebbbb0fec
6 changed files with 67 additions and 19 deletions

View file

@ -199,10 +199,12 @@
/>
</LinearLayout>
<CheckBox android:id="@+id/smart_robot"
<Spinner android:id="@+id/smart_robot"
android:prompt="@string/robot_spinner_prompt"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/smart_robot"
android:drawSelectorOnTop="true"
android:entries="@array/robot_levels"
/>
<Spinner android:id="@+id/phonies_spinner"

View file

@ -73,6 +73,12 @@
<item>@string/phonies_disallow</item>
</string-array>
<string-array name="robot_levels">
<item>@string/robot_smartest</item>
<item>@string/robot_smarter</item>
<item>@string/robot_smart</item>
</string-array>
<string-array name="connect_frequencies">
<item>@string/connect_thirty_seconds</item>
<item>@string/connect_five_mins</item>

View file

@ -177,8 +177,6 @@
<string name="settings_label">Other settings</string>
<string name="minutes_label">Minutes per player</string>
<string name="smart_robot">Smart robot</string>
<string name="download_dicts">Download more...</string>
<string name="confirm_save_title">Confirm save</string>
@ -230,6 +228,11 @@
<string name="phonies_ignore">Ignore phonies</string>
<string name="phonies_warn">Warn if phonies</string>
<string name="phonies_disallow">Disallow phonies</string>
<string name="robot_spinner_prompt">How smart is the robot player?</string>
<string name="robot_smart">Smart robot</string>
<string name="robot_smarter">Smarter robot</string>
<string name="robot_smartest">Smartest robot</string>
<string name="menu_prefs">Settings</string>
<string name="gamel_menu_dicts">Dictionaries</string>
<string name="menu_revert_all">Restore all</string>
@ -257,7 +260,8 @@
<string name="default_dict">Game dictionary</string>
<string name="default_phonies">Handle phonies</string>
<string name="phonies_spinner_prompt">Handle phonies (words not in dictionary)</string>
<string name="phonies_spinner_prompt">How to handle \"phonies\"
(words not in dictionary)</string>
<string name="board_size">Board size</string>
<string name="default_timerenabled">Use game timer</string>

View file

@ -91,6 +91,7 @@ public class GameConfig extends XWActivity
// private Spinner m_connectSpinner;
private Spinner m_phoniesSpinner;
private Spinner m_dictSpinner;
private Spinner m_smartnessSpinner;
private String[] m_dictItems;
private String[] m_dicts;
private int m_browsePosition;
@ -443,6 +444,9 @@ public class GameConfig extends XWActivity
m_phoniesSpinner = (Spinner)findViewById( R.id.phonies_spinner );
m_phoniesSpinner.setSelection( m_gi.phoniesAction.ordinal() );
m_smartnessSpinner = (Spinner)findViewById( R.id.smart_robot );
setSmartnessSpinner();
Utils.setChecked( this, R.id.hints_allowed, !m_gi.hintsNotAllowed );
Utils.setInt( this, R.id.timer_minutes_edit,
m_gi.gameSeconds/60/m_gi.nPlayers );
@ -459,8 +463,6 @@ 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, m_gi.getRobotsAreSmart() );
String fmt = getString( m_notNetworkedGame ?
R.string.title_game_configf
: R.string.title_gamenet_configf );
@ -665,6 +667,28 @@ public class GameConfig extends XWActivity
});
}
private void setSmartnessSpinner()
{
int setting = -1;
switch ( m_gi.getRobotSmartness() ) {
case 1:
setting = 0;
break;
case 50:
setting = 1;
break;
case 99:
case 100:
setting = 2;
break;
default:
Utils.logf( "setSmartnessSpinner got %d from getRobotSmartness()",
m_gi.getRobotSmartness() );
Assert.fail();
}
m_smartnessSpinner.setSelection( setting );
}
// private void configConnectSpinner()
// {
// m_connectSpinner = (Spinner)findViewById( R.id.connect_spinner );
@ -831,11 +855,13 @@ 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.setRobotsAreSmart( Utils.getChecked( this, R.id.smart_robot ) );
int position = m_phoniesSpinner.getSelectedItemPosition();
m_gi.phoniesAction = CurGameInfo.XWPhoniesChoice.values()[position];
position = m_smartnessSpinner.getSelectedItemPosition();
m_gi.setRobotSmartness(position * 49 + 1);
if ( !m_notNetworkedGame ) {
m_car.ip_relay_seeksPublicRoom = m_joinPublicCheck.isChecked();
Utils.logf( "ip_relay_seeksPublicRoom: %s",

View file

@ -55,7 +55,7 @@ public class CurGameInfo {
// private int[] m_visiblePlayers;
// private int m_nVisiblePlayers;
private boolean m_inProgress;
private boolean m_smart;
private int m_smartness;
public CurGameInfo( Context context )
{
@ -79,6 +79,7 @@ public class CurGameInfo {
timerEnabled = CommonPrefs.getDefaultTimerEnabled( context );
allowPickTiles = false;
allowHintRect = false;
m_smartness = 0; // needs to be set from players
// Always create MAX_NUM_PLAYERS so jni code doesn't ever have
// to cons up a LocalPlayer instance.
@ -89,7 +90,7 @@ public class CurGameInfo {
if ( isNetworked ) {
players[1].isLocal = false;
} else {
players[0].setIsRobot( 1 );
players[0].setRobotSmartness( 1 );
}
}
@ -131,17 +132,26 @@ public class CurGameInfo {
m_inProgress = inProgress;
}
public boolean getRobotsAreSmart()
public int getRobotSmartness()
{
return m_smart;
}
public void setRobotsAreSmart( boolean smart )
{
m_smart = smart;
if ( m_smartness == 0 ) {
m_smartness = 1; // default if no robots
for ( int ii = 0; ii < nPlayers; ++ii ) {
if ( players[ii].isRobot() ) {
players[ii].setIsRobot( smart ? 1 : 100 );
m_smartness = players[ii].robotIQ;
break; // should all be the same
}
}
}
return m_smartness;
}
public void setRobotSmartness( int smartness )
{
m_smartness = smartness;
for ( int ii = 0; ii < nPlayers; ++ii ) {
if ( players[ii].isRobot() ) {
players[ii].robotIQ = smartness;
}
}
}

View file

@ -63,7 +63,7 @@ public class LocalPlayer {
robotIQ = isRobot ? 1 : 0;
}
public void setIsRobot( int iq )
public void setRobotSmartness( int iq )
{
Assert.assertTrue( iq > 0 );
robotIQ = iq;