-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstepping_piece.rb
48 lines (37 loc) · 923 Bytes
/
stepping_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
require_relative 'piece.rb'
class SteppingPiece < Piece
def initialize(color, pos, board)
super
end
def moves
all_possible_moves = []
move_dirs.each do |offset|
x = @pos[0] + offset[0]
y = @pos[1] + offset[1]
all_possible_moves << [x, y] if @board.on_board?([x, y]) && !my_teammate([x, y])
end
all_possible_moves
end
end
class Knight < SteppingPiece
KNIGHT_DIRS = [[2, 1], [2, -1], [-2, 1], [-2, -1],
[1, 2], [1, -2], [-1, 2], [-1, -2]]
def initialize(color, pos, board)
super
@picture = color == "black" ? "♞" : "♘"
end
def move_dirs
KNIGHT_DIRS
end
end
class King < SteppingPiece
KING_DIRS = [[-1, -1], [-1, 1], [1, -1], [1, 1],
[1, 0], [0, 1], [-1, 0], [0, -1]]
def initialize(color, pos, board)
super
@picture = color == "black" ? "♚" : "♔"
end
def move_dirs
KING_DIRS
end
end