Class: TicTacToe::Strategy::Minimax
- Inherits:
-
Object
- Object
- TicTacToe::Strategy::Minimax
- Defined in:
- lib/tic_tac_toe/strategies/minimax_strategy.rb
Overview
The game tree needs a evaluator for generating rankings, an initial game state, and a player
Constant Summary collapse
- MAXDEPTH =
6
- PositiveInfinity =
+1.0/0.0
- NegativeInfinity =
-1.0/0.0
Instance Method Summary collapse
- #best_move ⇒ Object
-
#initialize(board, player) ⇒ Minimax
constructor
A new instance of Minimax.
Constructor Details
#initialize(board, player) ⇒ Minimax
Returns a new instance of Minimax.
30 31 32 33 |
# File 'lib/tic_tac_toe/strategies/minimax_strategy.rb', line 30 def initialize(board, player) @start_board = board @player = player end |
Instance Method Details
#best_move ⇒ Object
35 36 37 38 39 |
# File 'lib/tic_tac_toe/strategies/minimax_strategy.rb', line 35 def best_move @start_board.empty_positions.max_by do |column, row| score(@start_board.clone.play_at(column, row, @player), next_turn(@player)) end end |