-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplayer.rb
More file actions
42 lines (37 loc) · 721 Bytes
/
player.rb
File metadata and controls
42 lines (37 loc) · 721 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
36
37
38
39
40
41
42
class Player
attr_accessor :color
attr_reader :name
MOVE_MAP = {
"a" => 0,
"b" => 1,
"c" => 2,
"d" => 3,
"e" => 4,
"f" => 5,
"g" => 6,
"h" => 7,
"8" => 0,
"7" => 1,
"6" => 2,
"5" => 3,
"4" => 4,
"3" => 5,
"2" => 6,
"1" => 7
}
def initialize(name)
@name = name
end
def play_turn
puts "#{@name} (#{@color}), make a move"
move = gets.chomp
parse_move(move)
end
private
def parse_move(move)
start, ending = move.split(',')
start_move = [MOVE_MAP[start[1]], MOVE_MAP[start[0]]]
ending_move = [MOVE_MAP[ending[1]], MOVE_MAP[ending[0]]]
[start_move, ending_move]
end
end