-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRook.cc
More file actions
32 lines (27 loc) · 947 Bytes
/
Rook.cc
File metadata and controls
32 lines (27 loc) · 947 Bytes
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
#include <vector>
#include <utility>
#include "Rook.h"
#include "Move.h"
#include "Piece.h"
using namespace std;
Rook::Rook(bool white, pair<int, int> position) : Piece{white, 50, position, 'R'} {}
vector<Move> Rook::generateMoves(){
vector<Move> rawList = {};
int row = position.first;
int col = position.second;
for(int i = 1; i < 8; i++){
rawList.push_back(Move{this, position, make_pair(row+i, col)});
rawList.push_back(Move{this, position, make_pair(row-i, col)});
rawList.push_back(Move{this, position, make_pair(row, col+i)});
rawList.push_back(Move{this, position, make_pair(row, col-i)});
}
vector<Move> moveList = {};
for(Move move : rawList){
int row = move.getEndPos().first;
int col = move.getEndPos().second;
if(!((row < 0) || (row > 7) || (col < 0) || (col > 7))){
moveList.push_back(move);
}
}
return moveList;
}