aboutsummaryrefslogtreecommitdiff
path: root/src/moves.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/moves.cpp')
-rw-r--r--src/moves.cpp20
1 files changed, 17 insertions, 3 deletions
diff --git a/src/moves.cpp b/src/moves.cpp
index 3463fe8..bba85e7 100644
--- a/src/moves.cpp
+++ b/src/moves.cpp
@@ -52,9 +52,16 @@ void GeneratePawnMoves(Game *b, int from, std::vector<Move> &moves) {
// if piece it want to move to is none and it as legal move
if (b->pieces[next].type == NONE) {
- moves.push_back({position, IndexToPosition(next)}); // adding legal move
+ if (position.rank + (pawn.color ? -1 : 1) == 0 ||
+ position.rank + (pawn.color ? -1 : 1) == 7) {
+ moves.push_back({position, IndexToPosition(next), QUEEN});
+ moves.push_back({position, IndexToPosition(next), ROOK});
+ moves.push_back({position, IndexToPosition(next), BISHOP});
+ moves.push_back({position, IndexToPosition(next), KNIGHT});
+ } else {
+ moves.push_back({position, IndexToPosition(next)});
+ }
- // todo find why this code is here and what it does
int startingRank = pawn.color ? 6 : 1;
int twoSteps = from + step * 2;
if (position.rank == startingRank && b->pieces[twoSteps].type == NONE) {
@@ -79,7 +86,14 @@ void GeneratePawnMoves(Game *b, int from, std::vector<Move> &moves) {
if (b->pieces[target].type != NONE &&
b->pieces[target].color != pawn.color) {
- moves.push_back({position, IndexToPosition(target)});
+ if (targetRank == 0 || targetRank == 7) {
+ moves.push_back({position, IndexToPosition(target), QUEEN});
+ moves.push_back({position, IndexToPosition(target), ROOK});
+ moves.push_back({position, IndexToPosition(target), BISHOP});
+ moves.push_back({position, IndexToPosition(target), KNIGHT});
+ } else {
+ moves.push_back({position, IndexToPosition(target)});
+ }
}
}
// the end