-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrook.rb
56 lines (56 loc) · 1.79 KB
/
rook.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
52
53
54
55
56
require './piece'
require './utils'
require './major_attacking_move'
require './major_move'
class Rook<Piece
def initialize(piecePosition,alliance,firstMove)
super(piecePosition,alliance,firstMove)
@CandidateMoves=Array[-8,-1,1,8]
end
def to_s
'r'
end
def calculateLegalMoves(board)
legalMoves=Array.new
@CandidateMoves.each do |currentCandidate|
candidateDestination=@piecePosition
while(Utils.isValidCoordinate(candidateDestination)&&!isException(candidateDestination,currentCandidate))
candidateDestination+=currentCandidate
if (Utils.isValidCoordinate(candidateDestination))
candidateDestinationTile = board.getTile(candidateDestination)
if (!candidateDestinationTile.isTileOccupied?)
legalMoves.push(MajorMove.new(board,self,candidateDestination))
else
pieceAtDestination=candidateDestinationTile.getPiece
pieceAtDestinationAlliance=pieceAtDestination.getPieceAlliance
if(@pieceAlliance!=pieceAtDestinationAlliance)
legalMoves.push(MajorAttackingMove.new(board,self,candidateDestination,pieceAtDestination))
end
break
end
end
end
end
legalMoves
end
def isException(currentPosition,candidateMove)
((Utils.column?(1,currentPosition) && (candidateMove==-1)) \
||(Utils.column?(8,currentPosition) && (candidateMove==1)))
end
def isKing?
false
end
def movePiece(move)
Rook.new(move.getDestination,move.getPiece.getPieceAlliance,false)
end
def getValue
500
end
def getBonus
if(@pieceAlliance==White.new)
return Utils.whiteRookBonus[@piecePosition]
else
return Utils.blackRookBonus[@piecePosition]
end
end
end