diff options
| author | Adam <adammegarules1@gmail.com> | 2026-07-28 10:28:36 +0200 |
|---|---|---|
| committer | Adam <adammegarules1@gmail.com> | 2026-07-28 10:28:36 +0200 |
| commit | bc20789325250b1ca6b5b06a8021a99d91a5dc20 (patch) | |
| tree | b0e1b129a3cb33728e58c8b4075493a029ece942 /src/moves.cpp | |
| parent | ca5e947269608757a1af5295f5c77958de341fc3 (diff) | |
fixing memory bug
Diffstat (limited to 'src/moves.cpp')
| -rw-r--r-- | src/moves.cpp | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/src/moves.cpp b/src/moves.cpp index d7df595..00cd437 100644 --- a/src/moves.cpp +++ b/src/moves.cpp @@ -1,6 +1,7 @@ #include <array> #include <cassert> #include <cstdint> +#include <iostream> #include <sys/types.h> #include <vector> @@ -61,20 +62,22 @@ void GeneratePawnMoves(Game *b, int from, std::vector<Move> &moves) { moves.push_back({position, IndexToPosition(twoSteps)}); } } - - // check for (int fileOffset : {-1, 1}) { int targetFile = position.file + fileOffset; - if (targetFile < 0 || targetFile >= 8) { + int targetRank = position.rank + (pawn.color ? -1 : 1); + + if (targetFile < 0 || targetFile >= 8) continue; - } - int target = (position.rank + (pawn.color ? -1 : 1)) * 8 + targetFile; + if (targetRank < 0 || targetRank >= 8) + continue; + + int target = targetRank * 8 + targetFile; if (IndexToPosition(target) == b->enPassant && b->canEnpassant) { - // enpasstant!!!!!!! moves.push_back({position, IndexToPosition(target)}); } + if (b->pieces[target].type != NONE && b->pieces[target].color != pawn.color) { moves.push_back({position, IndexToPosition(target)}); |
