Class: Players::Computer

Inherits:
Player
  • Object
show all
Defined in:
lib/ttt-cli/players/computer.rb

Constant Summary

Constants included from Emoji

Emoji::DASH, Emoji::O, Emoji::X

Instance Attribute Summary collapse

Attributes inherited from Player

#board, #enemy, #name, #token

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ Computer

Returns a new instance of Computer.



7
8
9
10
11
12
13
14
15
# 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

Instance Attribute Details

#difficultyObject (readonly)

Returns the value of attribute difficulty.



5
6
7
# File 'lib/ttt-cli/players/computer.rb', line 5

def difficulty
  @difficulty
end

Instance Method Details

#make_move(board) ⇒ Object



17
18
19
20
21
# 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