-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathKnight.cc
More file actions
33 lines (29 loc) · 1.16 KB
/
Knight.cc
File metadata and controls
33 lines (29 loc) · 1.16 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
#include <vector>
#include <utility>
#include "Knight.h"
#include "Move.h"
#include "Piece.h"
using namespace std;
Knight::Knight(bool white, pair<int, int> position) : Piece{white, 30, position, 'N'} {}
vector<Move> Knight::generateMoves(){
vector<Move> rawList = {};
int row = position.first;
int col = position.second;
rawList.push_back(Move{this, position, make_pair(row+2, col+1)});
rawList.push_back(Move{this, position, make_pair(row+2, col-1)});
rawList.push_back(Move{this, position, make_pair(row-2, col+1)});
rawList.push_back(Move{this, position, make_pair(row-2, col-1)});
rawList.push_back(Move{this, position, make_pair(row+1, col+2)});
rawList.push_back(Move{this, position, make_pair(row+1, col-2)});
rawList.push_back(Move{this, position, make_pair(row-1, col+2)});
rawList.push_back(Move{this, position, make_pair(row-1, col-2)});
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;
}