PerfectPlayer
com.phasmidsoftware.gambit.examples.tictactoe.PerfectPlayer
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):
- A mutable score map
Map[TicTacToe, Int]is allocated. - 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). Traversal.dfsis called withDfsOrder.PostfromTicTacToe.start. The defaultgiven VisitedSet[TicTacToe]ensures each position is evaluated exactly once (DAG, not tree).- The completed score map drives
chooseMove.
Minimax convention:
- X maximises (score +1 = X wins, 0 = draw, -1 = O wins).
- O minimises.
TicTacToe.playeris 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.playerfor the node just settled.
Scores in the map are from X's perspective throughout.
Attributes
- Graph
-
- Supertypes
Members list
In this article