dev: Added QS/KS castle checking; simplified moveList pruning
This commit is contained in:
parent
e42457d3ab
commit
78749a6af2
2 changed files with 18 additions and 7 deletions
|
|
@ -126,10 +126,9 @@ std::vector<Move> King::getLegalMoves(const Square &from, const Board &board) co
|
||||||
// will this actually work?
|
// will this actually work?
|
||||||
moveList.erase(
|
moveList.erase(
|
||||||
std::remove_if(moveList.begin(), moveList.end(),
|
std::remove_if(moveList.begin(), moveList.end(),
|
||||||
[&](const Square &x) {
|
[&](const auto &x) {
|
||||||
return std::find(x.begin(), x.end(), !x.isValid()) != x.end();
|
return !x.to.isValid();
|
||||||
}),
|
}));
|
||||||
moveList.end());
|
|
||||||
return moveList;
|
return moveList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
18
Piece.hpp
18
Piece.hpp
|
|
@ -11,6 +11,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
#include <algorithm>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
@ -34,6 +35,10 @@ enum File {
|
||||||
A = 0, B = 1, C = 2, D = 3, E = 4, F = 5, G = 6, H = 7, INVALID_FILE = 255
|
A = 0, B = 1, C = 2, D = 3, E = 4, F = 5, G = 6, H = 7, INVALID_FILE = 255
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum CastleSide {
|
||||||
|
KINGSIDE = 1, QUEENSIDE = 2
|
||||||
|
};
|
||||||
|
|
||||||
struct Square {
|
struct Square {
|
||||||
Rank rank;
|
Rank rank;
|
||||||
File file;
|
File file;
|
||||||
|
|
@ -101,11 +106,18 @@ class King : public Piece {
|
||||||
return inCheck;
|
return inCheck;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool checkForCastle() const {
|
bool checkForCastle(enum CastleSide side) const {
|
||||||
return canCastle;
|
if(side == KINGSIDE) {
|
||||||
|
return canCastleKS;
|
||||||
|
} else if(side == QUEENSIDE) {
|
||||||
|
return canCastleQS;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
protected:
|
protected:
|
||||||
bool canCastle = true;
|
bool canCastleQS = true;
|
||||||
|
bool canCastleKS = true;
|
||||||
bool inCheck = false;
|
bool inCheck = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue