Class: AI
- Inherits:
-
Object
- Object
- AI
- Defined in:
- lib/ai.rb
Instance Attribute Summary collapse
-
#current_player ⇒ Object
readonly
Returns the value of attribute current_player.
Instance Method Summary collapse
- #computer_move(board, player) ⇒ Object
- #get_best_move(board, player) ⇒ Object
-
#initialize(player) ⇒ AI
constructor
A new instance of AI.
Constructor Details
#initialize(player) ⇒ AI
Returns a new instance of AI.
9 10 11 |
# File 'lib/ai.rb', line 9 def initialize(player) @current_player = player end |
Instance Attribute Details
#current_player ⇒ Object (readonly)
Returns the value of attribute current_player.
8 9 10 |
# File 'lib/ai.rb', line 8 def current_player @current_player end |
Instance Method Details
#computer_move(board, player) ⇒ Object
13 14 15 16 17 |
# File 'lib/ai.rb', line 13 def computer_move(board, player) test_board = board.dup test_board.all_cells = board.all_cells.dup get_best_move(test_board, player) end |
#get_best_move(board, player) ⇒ Object
19 20 21 22 23 |
# File 'lib/ai.rb', line 19 def get_best_move(board, player) ranked_moves = rank_possible_moves(board, player) move = ranked_moves.max_by {|cell, score| score} move.first end |