Class: Reversi::Player::Human

Inherits:
BasePlayer show all
Defined in:
lib/reversi/player/human.rb

Instance Attribute Summary

Attributes inherited from BasePlayer

#board, #my_color, #opponent_color

Instance Method Summary collapse

Methods inherited from BasePlayer

#count_disks, #next_moves, #put_disk, #status

Constructor Details

#initialize(color, _board) ⇒ Human

Returns a new instance of Human.



4
5
6
7
8
9
10
11
# File 'lib/reversi/player/human.rb', line 4

def initialize(color, _board)
  super

  case color
  when Reversi::Board::DISK[:black] then @color = :black
  when Reversi::Board::DISK[:white] then @color = :white
  end
end

Instance Method Details

#move(board) ⇒ Object



13
14
15
16
17
18
19
20
# File 'lib/reversi/player/human.rb', line 13

def move(board)
  return if next_moves.empty?
  puts board.to_s
  input_move
  printf "\e[#{18}A"; STDOUT.flush
  puts board.to_s; sleep 0.5
  printf "\e[#{18}A"; STDOUT.flush
end