class Players::Computer

Attributes

difficulty[R]

Public Class Methods

new(params) click to toggle source
Calls superclass method Player::new
# File lib/ttt-cli/players/computer.rb, line 7
def initialize(params)
  super(params)
  @name = 'Computer' unless params[:name]
  @game = params[:game]
  @board = @game.board
  @enemy = @game.first_player unless params[:enemy]
  @difficulty = @game.difficulty
  @ai = AI.create(@game, @difficulty, self)
end

Public Instance Methods

make_move(board) click to toggle source
# File lib/ttt-cli/players/computer.rb, line 17
def make_move(board)
  move = position
  sleep 0.6
  board.fill_cell(move, @token) unless board.cell_taken?(move)
end

Private Instance Methods

position() click to toggle source
# File lib/ttt-cli/players/computer.rb, line 25
def position
  @ai.move_generate
end