Algorithm
Development Kit 1.0

algs.model.problems.tictactoe.model
Class IntelligentAgent

java.lang.Object
  extended by algs.model.problems.tictactoe.model.Player
      extended by algs.model.problems.tictactoe.model.IntelligentAgent
All Implemented Interfaces:
IPlayer

public class IntelligentAgent
extends Player

Represents an Intelligent Tic Tac Toe playing agent that relies on the provided algorithm to select a move.

Since it relies on using a search algorithm to locate best move given what opponent is capable of doing, then it must know who the opponent is.

Since:
1.0
Version:
1.0, 6/15/08
Author:
George Heineman

Field Summary
 
Fields inherited from class algs.model.problems.tictactoe.model.Player
logic, mark, OMARK, score, XMARK
 
Constructor Summary
IntelligentAgent(char mark, IEvaluation algorithm)
          Construct an agent that selects the next move using the provided logic in the algorithm.
 
Method Summary
 IGameMove decideMove(IGameState gameState)
          Make an intelligent move given the board state, game logic, and player making the move.
 void opponent(IPlayer opponent)
          Set the opponent for this agent, which is needed because the search for the best move is going to need the opposing player.
 
Methods inherited from class algs.model.problems.tictactoe.model.Player
eval, getMark, getOpponentMark, hashCode, logic, logic, score, score, toString, validMoves
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

IntelligentAgent

public IntelligentAgent(char mark,
                        IEvaluation algorithm)
Construct an agent that selects the next move using the provided logic in the algorithm.

Note that whoever constructs this player must later set the opponent.

Parameters:
mark - mark to be used by player.
algorithm - Algorithm to use when selecting the move.
Method Detail

opponent

public void opponent(IPlayer opponent)
Set the opponent for this agent, which is needed because the search for the best move is going to need the opposing player.

Parameters:
opponent -

decideMove

public IGameMove decideMove(IGameState gameState)
Make an intelligent move given the board state, game logic, and player making the move. If no move can be made (because the game is already DRAWN or the game has been won) then null is returned. We can only look ahead 'ply' number of moves.

Specified by:
decideMove in class Player
Returns:
a randomly selected best move to make, or null if game is already won or drawn.

Algorithm Development Kit 1.0

This code supports the Algorithms in a Nutshell book, published by O'Reilly Media, Inc. in November 2008. Please visit the book web page to learn of any changes to the code repository or to record a potential defect.