-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpawn_promotion.rb
More file actions
42 lines (41 loc) · 1.06 KB
/
pawn_promotion.rb
File metadata and controls
42 lines (41 loc) · 1.06 KB
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
require './move'
require './board'
class PawnPromotion<Move
def initialize(move,promotedPiece)
super(move.getBoard,move.getPiece,move.getDestination)
@pawnMove=move
@pawn=move.getPiece
@promotedPiece=promotedPiece
end
def isAttack
@pawnMove.isAttack
end
def getAttackedPiece
@pawnMove.getAttackedPiece
end
def execute
movedBoard=@pawnMove.execute
newBoard=Board.new
movedBoard.getCurrentPlayer.getOpponent.getLivePieces.each do |piece|
if (@movedPiece!=piece)
newBoard.setPiece(piece)
end
end
movedBoard.getCurrentPlayer.getLivePieces.each do |piece|
newBoard.setPiece(piece)
end
newBoard.setPiece(@promotedPiece)
newBoard.setTurn(movedBoard.getCurrentPlayer.getAlliance)
newBoard.build
newBoard
end
def ==(move)
if(move.instance_of? PawnPromotion)
return (@movedPiece==move.getPiece && @destination==move.getDestination)
end
false
end
def to_s
"#{@pawnMove.to_s}=#{@promotedPiece.to_s.upcase}"
end
end