class ComputerPlayer

Attributes

mark[R]

Public Class Methods

new(mark, board, display) click to toggle source
# File lib/ttt_malisa/computer_player.rb, line 4
def initialize(mark, board, display)
  @board = board
  @display = display
  @mark = mark
end

Public Instance Methods

move() click to toggle source
# File lib/ttt_malisa/computer_player.rb, line 10
def move
  @display.make_move_message(@mark)
  index = retrieve_computer_index(1)
  @display.computer_thinking
  sleep 1
  @display.computer_move(index + 1)
  @board.valid_move?(index) ? @board.mark(index, @mark) : move
end
retrieve_computer_index(seed) click to toggle source
# File lib/ttt_malisa/computer_player.rb, line 19
def retrieve_computer_index(seed)
  srand(seed)
  available_move = @board.available_moves
  available_move[0]
end