-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathKnight.cpp
37 lines (34 loc) · 1.88 KB
/
Knight.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
#include "Knight.h"
Knight::Knight(bool color) {
if (color) {
pieceType.setTexture(TextureManager::GetTexture("white_knight"));
}
else {
pieceType.setTexture(TextureManager::GetTexture("black_knight"));
}
ChessPiece::color = color;
dragging = false;
moveCount = 0;
canEnPassant = false;
canCastle = false;
canCastleLeft = false;
canCastleRight = false;
inCheck = false;
attackingKing = false;
protectingKing = false;
alreadyModified = false;
name = "Nnig"; //For "Nnight"
}
void Knight::CalculateLegalMoves(vector<vector<ChessPiece*>>& gridPieces, int activeRowIndex, int activeColIndex, int activePieceOriginalPositionX, int activePieceOriginalPositionY, vector<Log>& logs, vector<ChessPiece*>& whitePieces, vector<ChessPiece*>& blackPieces) {
legalMoves.clear();
legalMovesIncludingFriendlyFire.clear();
AddMove(gridPieces, activeRowIndex, -2, activeColIndex, 1, activePieceOriginalPositionX, activePieceOriginalPositionY); //Up-Right
AddMove(gridPieces, activeRowIndex, -2, activeColIndex, -1, activePieceOriginalPositionX, activePieceOriginalPositionY); //Up-Left
AddMove(gridPieces, activeRowIndex, 1, activeColIndex, -2, activePieceOriginalPositionX, activePieceOriginalPositionY); //Left-Down
AddMove(gridPieces, activeRowIndex, -1, activeColIndex, -2, activePieceOriginalPositionX, activePieceOriginalPositionY); //Left-Up
AddMove(gridPieces, activeRowIndex, 2, activeColIndex, 1, activePieceOriginalPositionX, activePieceOriginalPositionY); //Down-Right
AddMove(gridPieces, activeRowIndex, 2, activeColIndex, -1, activePieceOriginalPositionX, activePieceOriginalPositionY); //Down-Left
AddMove(gridPieces, activeRowIndex, 1, activeColIndex, 2, activePieceOriginalPositionX, activePieceOriginalPositionY); //Right-Down
AddMove(gridPieces, activeRowIndex, -1, activeColIndex, 2, activePieceOriginalPositionX, activePieceOriginalPositionY); //Right-Up
totalMoves = legalMoves;
}