PerfectPlayer

com.phasmidsoftware.gambit.examples.tictactoe.PerfectPlayer
class PerfectPlayer(implicit state: State[Board, TicTacToe]) extends Player[TicTacToe, Int, Boolean]

A perfect TicTacToe player built by running a full minimax evaluation over the game DAG using Visitor's post-order DFS.

Construction (once, on first use):

  1. A mutable score map Map[TicTacToe, Int] is allocated.
  2. A given Evaluable[TicTacToe, Int] closes over the map; for terminal positions it scores directly; for internal positions it reads children's scores from the map (already populated in post-order).
  3. Traversal.dfs is called with DfsOrder.Post from TicTacToe.start. The default given VisitedSet[TicTacToe] ensures each position is evaluated exactly once (DAG, not tree).
  4. The completed score map drives chooseMove.

Minimax convention:

  • X maximises (score +1 = X wins, 0 = draw, -1 = O wins).
  • O minimises.
  • TicTacToe.player is true when it was X's turn to produce this board (i.e., X just moved), so when choosing the next move, we look at whose turn it is, which is !ttt.player for the node just settled.

Scores in the map are from X's perspective throughout.

Attributes

Graph
Supertypes
trait Player[TicTacToe, Int, Boolean]
class Object
trait Matchable
class Any

Members list

Value members

Concrete methods

override def chooseMove(ttt: TicTacToe, random: Random): Option[Int]

Choose a move from the given state. Returns None if no move is available (terminal position).

Choose a move from the given state. Returns None if no move is available (terminal position).

Value parameters

random

a Random instance.

s

the current state.

Attributes

Returns

Some(move) or None.

Definition Classes

Inherited methods

def gameOver(result: GameResult[Boolean], me: Boolean): Unit

Called at the end of a game with the full result and this player's identity. Default implementation is a no-op. Override to implement learning or logging.

Called at the end of a game with the full result and this player's identity. Default implementation is a no-op. Override to implement learning or logging.

Value parameters

me

this player's identity, used to extract the relevant score.

result

the game result (all players' scores).

Attributes

Inherited from:
Player