-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmove.rb
More file actions
76 lines (76 loc) · 1.95 KB
/
move.rb
File metadata and controls
76 lines (76 loc) · 1.95 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
require './board'
class Move
def initialize(board,movedPiece,destination)
@board=board
@movedPiece=movedPiece
@destination=destination
end
def getPiece
@movedPiece
end
def getBoard
@board
end
def getDestination
@destination
end
def execute
newBoard=Board.new
@board.getCurrentPlayer.getLivePieces.each do |piece|
if (@movedPiece!=piece)
newBoard.setPiece(piece)
end
end
@board.getCurrentPlayer.getOpponent.getLivePieces.each do |piece|
newBoard.setPiece(piece)
end
newBoard.setPiece(@movedPiece.movePiece(self))
newBoard.setTurn(@board.getCurrentPlayer.getOpponent.getAlliance)
newBoard.build
newBoard
end
def getCoordinate
@movedPiece.getPiecePosition
end
def createMove(board,coordinate,destinationCoordinate)
board.getAllLegalMoves.each do |move|
if(move.getDestination==destinationCoordinate and move.getCoordinate==coordinate)
return move
end
end
end
def isAttack
false
end
def isCastlingMove
false
end
def getAttackedPiece
nil
end
def disambiguation
same=0
col=0
row=0
@board.getCurrentPlayer.getLegalMoves.each do |move|
if(move.getDestination==@destination && move!=self && @movedPiece.samePiece?(move.getPiece))
same+=1
if(Utils.column(move.getPiece.getPiecePosition)==Utils.column(@movedPiece.getPiecePosition))
col+=1
elsif(Utils.row(move.getPiece.getPiecePosition)==Utils.row(@movedPiece.getPiecePosition))
row+=1
end
end
end
if(same!=0)
if(col==0)
return Utils.coordinateToString(@movedPiece.getPiecePosition)[0]
elsif(col!=0 && row==0)
return Utils.coordinateToString(@movedPiece.getPiecePosition)[1]
else
return Utils.coordinateToString(@movedPiece.getPiecePosition)
end
end
end
return ""
end