-
Notifications
You must be signed in to change notification settings - Fork 0
/
rook.cpp
executable file
·51 lines (45 loc) · 1.49 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
#include "rook.h"
#include "ChessBoard.hpp"
using namespace std;
void Rook::calculateValidMoves(std::string currentPos)
{
int fileChange, rankChange;
// get rid of any moves left over from last turn
validMoves.clear();
string endPos = currentPos;
for (int i = 0; i < 4; i++){
// coordinate change depends on which loop
switch (i){
case 0:// E
fileChange = 1;
rankChange = 0;
break;
case 1:// W
fileChange = -1;
rankChange = 0;
break;
case 2:// N
fileChange = 0;
rankChange = 1;
break;
case 3:// S
fileChange = 0;
rankChange = -1;
break;
}
endPos[0] = currentPos[0] + fileChange;
endPos[1] = currentPos[1] + rankChange;
// loop through moves in this direction, cant go through enemy piece or off board
while (board->onBoard(endPos) && board->checkForPiece(endPos) != colour){
validMoves.push_back(endPos);
// if we have got to an enemy piece cannot pass it
if (board->checkForPiece(endPos) == ChessBoard::otherPlayer(colour)){
break;
}
endPos[0] = endPos[0] + fileChange;
endPos[1] = endPos[1] + rankChange;
}
}
}
Rook::Rook(Colour _colour, ChessBoard* _board) : Piece(_colour, "Rook", _board)
{ }