aboutsummaryrefslogtreecommitdiff
path: root/src/moves.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/moves.cpp')
-rw-r--r--src/moves.cpp16
1 files changed, 9 insertions, 7 deletions
diff --git a/src/moves.cpp b/src/moves.cpp
index 5c8c07e..0059039 100644
--- a/src/moves.cpp
+++ b/src/moves.cpp
@@ -5,7 +5,7 @@
#include "board.hpp"
#include "moves.hpp"
-void GeneratePawnMoves(board *b, int from, std::vector<Move> &moves) {
+void GeneratePawnMoves(Board *b, int from, std::vector<Move> &moves) {
Piece pawn = b->pieces[from];
if (pawn.type != PAWN) {
assert(false && "Calling generate pawn moves on non pawn");
@@ -49,7 +49,7 @@ void GeneratePawnMoves(board *b, int from, std::vector<Move> &moves) {
// the end
}
-std::vector<Move> GetLegalMoves(board *b) {
+std::vector<Move> GetLegalMoves(Board *b) {
std::vector<Move> moves;
moves.reserve(50); // almost all position dont have that many moves
@@ -93,7 +93,7 @@ Position IndexToPosition(int i) {
return {rank, file};
}
-void GenerateSlidingMoves(board *b, int from,
+void GenerateSlidingMoves(Board *b, int from,
const std::array<int, 4> &directions,
std::vector<Move> &moves) {
for (uint i = 0; i < directions.size(); i++) {
@@ -128,7 +128,7 @@ void GenerateSlidingMoves(board *b, int from,
};
};
-void GenerateKingMoves(board *b, int from, std::vector<Move> &moves) {
+void GenerateKingMoves(Board *b, int from, std::vector<Move> &moves) {
if (b->pieces[from].type != KING) {
assert(false && "calling generate king moves on non king");
return;
@@ -146,9 +146,11 @@ void GenerateKingMoves(board *b, int from, std::vector<Move> &moves) {
if (std::abs((next % 8) - (from % 8)) > 1) {
continue;
};
- if (b->pieces[next].color == b->turn) {
- continue;
- };
+ if (b->pieces[next].type != NONE) {
+ if (b->pieces[next].color == b->turn) {
+ continue;
+ };
+ }
moves.push_back({IndexToPosition(from), IndexToPosition(next)});
}