-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhumanplayer.rb
More file actions
35 lines (30 loc) · 823 Bytes
/
humanplayer.rb
File metadata and controls
35 lines (30 loc) · 823 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
class HumanPlayer
attr_reader :piece_color, :player_no
def initialize(piece_color, display)
@piece_color, @display = piece_color, display
@player_no = @piece_color == :white ? "One" : "Two"
end
def make_move(board)
begin
move = []
until move.length == 2
move << get_pos
end
board.move_piece(piece_color, *move)
rescue ArgumentError => move_error
puts move_error
move.each { |pos| board[pos].toggle_selected }
retry
ensure
board[move.last].toggle_selected if move.length > 0
end
end
def get_pos
input = nil
until input.is_a?(Array)
input = @display.cursor.get_input
@display.render
end
input
end
end