antichess
Class AIPlayer<M extends Move,B extends Board<M>>

java.lang.Object
  extended by antichess.AIPlayer<M,B>
All Implemented Interfaces:
GamePlayer<M>, Runnable

public class AIPlayer<M extends Move,B extends Board<M>>
extends Object
implements GamePlayer<M>, Runnable

A AIPlayer is a GamePlayer that uses a GameAI to make moves.


Constructor Summary
AIPlayer(B board, Player player, GameAI<M,B> ai)
          Creates a new AIPlayer object
 
Method Summary
 boolean automaticallyTimed()
          If a GamePlayer is automatically timed the time is handled by the GameController if it is not automatically timed, the time for a move needs to be handled by the GamePlayer
 void gameEnded()
          Tell the AI thread to quit
 M getMove(GameController controller)
          Asks the player for a move, if the player has a move the move is returned, if the player doesn't, null is returned immediately Once this GamePlayer is able to return a valid move it calls notifyControllerHasMove() on the controller.
 Player getPlayerType()
           
 void run()
           The thread in the run() method is responsible for actually asking the GameAI to make moves.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AIPlayer

public AIPlayer(B board,
                Player player,
                GameAI<M,B> ai)
Creates a new AIPlayer object

Parameters:
board -
player -
Method Detail

run

public void run()

The thread in the run() method is responsible for actually asking the GameAI to make moves.

The thread spends most of its time sleeping. When getMove is called, it sets controller and calls notify() to wake the thread. Once the thread wakes and observes controller to be non-null, it computes a move using the GameAI. When the move returns, it sets the internal move variable, calls notify() on the Game controller, and then sets the controller back to null.

Specified by:
run in interface Runnable

getMove

public M getMove(GameController controller)
Description copied from interface: GamePlayer
Asks the player for a move, if the player has a move the move is returned, if the player doesn't, null is returned immediately Once this GamePlayer is able to return a valid move it calls notifyControllerHasMove() on the controller.

Specified by:
getMove in interface GamePlayer<M extends Move>
See Also:
GamePlayer.getMove(GameController)

gameEnded

public void gameEnded()
Tell the AI thread to quit

Specified by:
gameEnded in interface GamePlayer<M extends Move>

getPlayerType

public Player getPlayerType()
Specified by:
getPlayerType in interface GamePlayer<M extends Move>
Returns:
Player for this

automaticallyTimed

public boolean automaticallyTimed()
Description copied from interface: GamePlayer
If a GamePlayer is automatically timed the time is handled by the GameController if it is not automatically timed, the time for a move needs to be handled by the GamePlayer

Specified by:
automaticallyTimed in interface GamePlayer<M extends Move>
Returns:
true;