-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPawn.cc
More file actions
43 lines (38 loc) · 1.43 KB
/
Pawn.cc
File metadata and controls
43 lines (38 loc) · 1.43 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
34
35
36
37
38
39
40
41
42
43
#include <vector>
#include <utility>
#include "Pawn.h"
#include "Move.h"
#include "Piece.h"
using namespace std;
Pawn::Pawn(bool white, pair<int, int> position) : Piece{white, 10, position, 'P'} {}
vector<Move> Pawn::generateMoves(){
vector<Move> rawList = {};
int row = position.first;
int col = position.second;
if (white) {
if(row == 1 && !hasMoved()) rawList.push_back(Move{this, position, make_pair(row + 2, col)});
rawList.push_back(Move{this, position, make_pair(row + 1, col)});
rawList.push_back(Move{this, position, make_pair(row + 1, col + 1)});
rawList.push_back(Move{this, position, make_pair(row + 1, col - 1)});
} else{
if(row == 6 && !hasMoved()) rawList.push_back(Move{this, position, make_pair(row - 2, col)});
rawList.push_back(Move{this, position, make_pair(row - 1, col)});
rawList.push_back(Move{this, position, make_pair(row - 1, col + 1)});
rawList.push_back(Move{this, position, make_pair(row - 1, col - 1)});
}
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;
}
void Pawn::setEnPassant(bool enPassant){
this->enPassant = enPassant;
}
bool Pawn::getEnPassant(){
return this->enPassant;
}