com.anji.ttt
Class TttBestPlayer
java.lang.Object
com.anji.ttt.TttBestPlayer
- All Implemented Interfaces:
- BoardPlayer, Configurable, Player
- public class TttBestPlayer
- extends java.lang.Object
- implements BoardPlayer, Configurable
"Best" tic-tac-toe subject. See move()
for details.
- Author:
- Philip Tucker
Method Summary |
java.lang.String |
getPlayerId()
|
void |
init(Properties props)
|
int |
move(int[] boardState)
Play according to the following criteria, in order of preference:
If the board is empty, move randomly
If winning move is available, make it
If opponent has winning move, block it
Try to fork opponent
Try to block forking by opponent
Play in center if open
Play randomly in open corner
Play randomly
|
void |
reset()
reset player state; after a call to reset, the player should be in the same state as it was
when created; i.e., it has no memory of previous games played |
java.lang.String |
toString()
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
TttBestPlayer
public TttBestPlayer()
getPlayerId
public java.lang.String getPlayerId()
- Specified by:
getPlayerId
in interface Player
- Returns:
- String unique ID
- See Also:
Player.getPlayerId()
move
public int move(int[] boardState)
- Play according to the following criteria, in order of preference:
- If the board is empty, move randomly
- If winning move is available, make it
- If opponent has winning move, block it
- Try to fork opponent
- Try to block forking by opponent
- Play in center if open
- Play randomly in open corner
- Play randomly
- Specified by:
move
in interface BoardPlayer
- Parameters:
boardState
-
- Returns:
- next move
- See Also:
BoardPlayer.move(int[])
init
public void init(Properties props)
throws java.lang.Exception
- Specified by:
init
in interface Configurable
- Parameters:
props
- configuration parameters
- Throws:
java.lang.Exception
- See Also:
Configurable.init(com.anji.util.Properties)
reset
public void reset()
- Description copied from interface:
Player
- reset player state; after a call to reset, the player should be in the same state as it was
when created; i.e., it has no memory of previous games played
- Specified by:
reset
in interface Player
- See Also:
Player.reset()
toString
public java.lang.String toString()
- See Also:
Object.toString()