com.phasmidsoftware.gambit.examples.connect4
Members list
Type members
Classlikes
A Connect Four AI player using the alpha-beta pruning optimization technique for minimax search. The player aims to determine the optimal moves for winning or forcing a draw in the game.
A Connect Four AI player using the alpha-beta pruning optimization technique for minimax search. The player aims to determine the optimal moves for winning or forcing a draw in the game.
Value parameters
- depth
-
The maximum depth of the search tree used in alpha-beta pruning. Defaults to 6.
- keyFn
-
An optional function that generates a unique key for the Transposition Table (TT), to identify equivalent game states. Defaults to None. Uses contextual abstractions: -
statefor managing the transformation of game states. -gamefor game-specific logic, including rules and evaluation utilities. -ttCacheas a caching mechanism for storing precomputed game states during alpha-beta expansion for performance optimization. Extends: - AlphaBetaPlayer, a generic implementation of alpha-beta search AI for turn-based games, parameterized by the game state, result, move, player type, and Transposition Table key type. - me
-
Specifies the player's identity in the game. True indicates the player is X, false indicates the player is O.
Attributes
- Supertypes
-
class Objecttrait Matchableclass Any
Connect Four board state using a column-major bitboard representation.
Connect Four board state using a column-major bitboard representation.
Two Longs (xBits, oBits) represent the pieces of each player. Bit index for cell (row, col) = col * 7 + row, where row 0 is the bottom. Sentinel bits at positions 6, 13, 20, 27, 34, 41, 48 are never set during play; they prevent horizontal win detection from wrapping across columns.
heights tracks the next available row index per column (0..5). A column is full when heights(col) == Connect4.rows.
You can read more about the game here: https://en.wikipedia.org/wiki/Connect_Four
Value parameters
- heights
-
next available row per column
- oBits
-
bit positions of O's pieces
- xBits
-
bit positions of X's pieces
Attributes
- Companion
- object
- Supertypes
-
trait Serializabletrait Producttrait Equalsclass Objecttrait Matchableclass AnyShow all
Attributes
- Supertypes
-
class Objecttrait Matchableclass Any
Factory for a Connect Four GameRunner.
Factory for a Connect Four GameRunner.
Attributes
- Supertypes
-
class Objecttrait Matchableclass Any
- Self type
-
Connect4GameRunner.type
State[Connect4, Connect4] typeclass instance for Connect4.
State[Connect4, Connect4] typeclass instance for Connect4.
P = S = Connect4: the proto-state and state are the same type. construct takes (newState, previousState) and returns newState.
Attributes
- Supertypes
- Self type
-
Connect4State.type
Runs a round-robin tournament between all Connect Four player types and prints the league table to stdout.
Runs a round-robin tournament between all Connect Four player types and prints the league table to stdout.
Player parameters (depths, iteration counts, exploration constant) are read from application.conf via com.phasmidsoftware.gambit.game.GambitConfig. Edit the config file to tune contestants without recompiling.
Players entered:
- RandomPlayer
- HeuristicPlayer (one-ply greedy)
- AlphaBeta(d=d1) (minimax, depth from config)
- AlphaBeta(d=d2) (minimax, deeper depth from config)
- MCTS(i=i1) (Monte Carlo, iteration count from config)
- MCTS(i=i2) (Monte Carlo, higher iteration count from config)
Attributes
- Supertypes
-
class Objecttrait Matchableclass Any
- Self type
-
Connect4Tournament.type
Value members
Concrete methods
Demonstrates Connect4 games between player types, printing the board state and heuristic score after each move.
Demonstrates Connect4 games between player types, printing the board state and heuristic score after each move.
Each matchup is played twice — home (X) and away (O) — to account for the first-mover advantage X enjoys in Connect Four.
Matchups: MCTS vs Random, MCTS vs Heuristic, Heuristic vs Random.
Attributes
Play a single Connect4 game, printing each move with board and heuristic.
Play a single Connect4 game, printing each move with board and heuristic.
Attributes
Render a Connect4 board with its heuristic score. Adds column index header for readability.
Render a Connect4 board with its heuristic score. Adds column index header for readability.
Attributes
Givens
Givens
The Game typeclass instance for Connect Four.
The Game typeclass instance for Connect Four.
S = Connect4 M = Int (column index, 0..6) Pl = Boolean (true = X, moves first; false = O, moves second)