-
Notifications
You must be signed in to change notification settings - Fork 0
/
Pawn.rb
51 lines (45 loc) · 1.12 KB
/
Pawn.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
50
51
require_relative 'Piece'
class Pawn < Piece
def initialize x,y,board,color
super x,y,board,color,2
@moved = false
end
def check_possible_moves
@possible_moves = []
if @alive
if @color == 'black'
advance = -1
else
advance = 1
end
if @x+advance<=8 and @x+advance>0
if @board[@x+advance][@y].piece == nil
move = [@x+advance,@y,1]
@possible_moves << move
end
if !@moved and @board[@x+2*advance][@y].piece == nil
move = [@x+2*advance,@y,2]
@possible_moves << move
@moved = true
end
if @y+1<=8 and @board[@x+advance][@y+1].piece and @board[@x+advance][@y+1].piece.color != @color
move = [@x+advance,@y+1,@board[@x+advance][@y+1].piece.value]
@possible_moves << move
end
if @y-1>0 and @board[@x+advance][@y-1].piece and @board[@x+advance][@y-1].piece.color != @color
move = [@x+advance,@y-1,@board[@x+advance][@y-1].piece.value]
@possible_moves << move
end
end
end
@possible_moves
end
def move move
if super(move) == true
return true
end
if @x==8 or @x==0
return piece = Queen.new(@x,@y,@board,@color)
end
end
end