-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRook.cpp
70 lines (60 loc) · 2.75 KB
/
Rook.cpp
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
#include "Rook.h"
Rook::Rook(bool color) {
if (color) {
pieceType.setTexture(TextureManager::GetTexture("white_rook"));
}
else {
pieceType.setTexture(TextureManager::GetTexture("black_rook"));
}
ChessPiece::color = color;
dragging = false;
moveCount = 0;
canEnPassant = false;
canCastle = false;
canCastleLeft = false;
canCastleRight = false;
inCheck = false;
attackingKing = false;
protectingKing = false;
alreadyModified = false;
name = "Rook";
}
void Rook::CalculateLegalMoves(vector<vector<ChessPiece*>>& gridPieces, int activeRowIndex, int activeColIndex, int activePieceOriginalPositionX, int activePieceOriginalPositionY, vector<Log>& logs, vector<ChessPiece*>& whitePieces, vector<ChessPiece*>& blackPieces) {
//Moves used for playing the game
legalMoves.clear();
legalMovesIncludingFriendlyFire.clear();
lineOfSight = true; //Send an LoS check all the way in one direction, false if hits friendly or wall
for (int pivot = 1; lineOfSight; pivot++) {
AddMove(gridPieces, activeRowIndex, -pivot, activeColIndex, 0, activePieceOriginalPositionX, activePieceOriginalPositionY); //Up
}
lineOfSight = true; //Reset the LoS check for the other straights
for (int pivot = 1; lineOfSight; pivot++) {
AddMove(gridPieces, activeRowIndex, pivot, activeColIndex, 0, activePieceOriginalPositionX, activePieceOriginalPositionY); //Down
}
lineOfSight = true; //So on
for (int pivot = 1; lineOfSight; pivot++) {
AddMove(gridPieces, activeRowIndex, 0, activeColIndex, -pivot, activePieceOriginalPositionX, activePieceOriginalPositionY); //Left
}
lineOfSight = true; //And so forth
for (int pivot = 1; lineOfSight; pivot++) {
AddMove(gridPieces, activeRowIndex, 0, activeColIndex, pivot, activePieceOriginalPositionX, activePieceOriginalPositionY); //Right
}
//Moves used for monitoring state
totalMoves.clear();
lineOfSight = true; //Send an LoS check all the way in one direction, false if hits wall
for (int pivot = 1; lineOfSight; pivot++) {
AddTotalMove(gridPieces, activeRowIndex, -pivot, activeColIndex, 0, activePieceOriginalPositionX, activePieceOriginalPositionY); //Up
}
lineOfSight = true; //Reset the LoS check for the other straights
for (int pivot = 1; lineOfSight; pivot++) {
AddTotalMove(gridPieces, activeRowIndex, pivot, activeColIndex, 0, activePieceOriginalPositionX, activePieceOriginalPositionY); //Down
}
lineOfSight = true; //So on
for (int pivot = 1; lineOfSight; pivot++) {
AddTotalMove(gridPieces, activeRowIndex, 0, activeColIndex, -pivot, activePieceOriginalPositionX, activePieceOriginalPositionY); //Left
}
lineOfSight = true; //And so forth
for (int pivot = 1; lineOfSight; pivot++) {
AddTotalMove(gridPieces, activeRowIndex, 0, activeColIndex, pivot, activePieceOriginalPositionX, activePieceOriginalPositionY); //Right
}
}