-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpiece.rb
52 lines (37 loc) · 996 Bytes
/
piece.rb
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
43
44
45
46
47
48
49
# encoding: utf-8
class MethodUndefinedError < StandardError
end
class Piece
attr_accessor :position, :color, :board
def initialize(position, color, board)
@position, @color, @board = position, color, board
end
def remove
@position = nil
end
def update_position(new_position)
@position = new_position
end
def available_moves
raise MethodUndefinedError.new("available_moves method not yet implemented")
end
def valid_moves
# available_moves
available_moves.delete_if do |move|
dup_board = board.board_dup
dup_board.move!(@position, move)
dup_board.in_check?(@color)
end
end
def confirm_move_not_in_check?(new_position)
dup_board = board.board_dup
dup_board.move!(@position, new_position)
!dup_board.in_check?(@color)
end
def to_s
raise MethodUndefinedError.new("to_s method not yet implemented")
end
def position_in_bounds?(pos)
pos[0].between?(0,7) && pos[1].between?(0,7)
end
end