-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpiece.rb
More file actions
39 lines (30 loc) · 691 Bytes
/
Copy pathpiece.rb
File metadata and controls
39 lines (30 loc) · 691 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
class Piece
attr_reader :color, :picture
attr_accessor :pos
def initialize(color, pos, board)
@color, @pos, @board = color, pos, board
end
def moves
raise "Not implemented"
end
def valid_moves
moves.select { |pos| !move_into_check?(pos) }
end
def my_teammate(pos)
@color == @board.color_of_piece_at(pos)
end
def other_team(pos)
if @color == "black"
opponent_color = "white"
else
opponent_color = "black"
end
opponent_color == @board.color_of_piece_at(pos)
end
private
def move_into_check?(pos)
dup_board = @board.deep_dup
dup_board.move!(@pos, pos)
dup_board.in_check?(@color)
end
end