Class: TicTacToe::Player::Computer

Inherits:
Object
  • Object
show all
Includes:
MoveJson
Defined in:
lib/tic_tac_toe/players/computer_player.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from MoveJson

#move_json

Constructor Details

#initialize(params, solver = Strategy::MinimaxStrategy) ⇒ Computer

Returns a new instance of Computer.



10
11
12
13
# File 'lib/tic_tac_toe/players/computer_player.rb', line 10

def initialize(params, solver=Strategy::MinimaxStrategy)
  @letter = params['letter'] || params[:letter]
  @solver = solver
end

Instance Attribute Details

#letterObject (readonly)

Returns the value of attribute letter.



8
9
10
# File 'lib/tic_tac_toe/players/computer_player.rb', line 8

def letter
  @letter
end

Instance Method Details

#get_move(board) ⇒ Object



15
16
17
# File 'lib/tic_tac_toe/players/computer_player.rb', line 15

def get_move(board)
  @solver.new(board, @letter).solve
end

#has_next_move?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/tic_tac_toe/players/computer_player.rb', line 19

def has_next_move?
  true
end

#typeObject



23
24
25
# File 'lib/tic_tac_toe/players/computer_player.rb', line 23

def type
  Player::COMPUTER
end