implemented the last details to make everything
work (hopefully)
This commit is contained in:
parent
fa57dcfc30
commit
21136a26f0
@ -292,3 +292,30 @@ bool Board::is_check_for(int8_t colour) const {
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Board::no_legal_moves_for(int8_t colour) const {
|
||||||
|
for (int i = 0; i < 64; i++) {
|
||||||
|
if ((colour_at(i) == White && white_to_play)
|
||||||
|
|| (colour_at(i) == Black && !white_to_play)) {
|
||||||
|
if (legal_moves(squares[i] & 0b111, *this, Coords::from_index(i))
|
||||||
|
.size()
|
||||||
|
> 0)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<Move> Board::all_legal_moves() const {
|
||||||
|
std::vector<Move> ret;
|
||||||
|
for (int i = 0; i < 64; i++) {
|
||||||
|
if ((colour_at(i) == White && white_to_play)
|
||||||
|
|| (colour_at(i) == Black && !white_to_play)) {
|
||||||
|
std::vector<Move> moves =
|
||||||
|
legal_moves(squares[i] & 0b111, *this, Coords::from_index(i));
|
||||||
|
if (moves.size() > 0)
|
||||||
|
ret.insert(ret.end(), moves.begin(), moves.end());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
@ -8,7 +8,8 @@
|
|||||||
|
|
||||||
struct Board {
|
struct Board {
|
||||||
private:
|
private:
|
||||||
int8_t get_king_of(int8_t colour) const;
|
int8_t get_king_of(int8_t) const;
|
||||||
|
bool no_legal_moves_for(int8_t) const;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
int8_t squares[64] = {Piece::None};
|
int8_t squares[64] = {Piece::None};
|
||||||
@ -25,6 +26,21 @@ struct Board {
|
|||||||
std::string to_fen() const;
|
std::string to_fen() const;
|
||||||
bool is_check_for(int8_t) const;
|
bool is_check_for(int8_t) const;
|
||||||
|
|
||||||
|
std::vector<Move> all_legal_moves() const;
|
||||||
|
|
||||||
|
bool is_checkmate_for(int8_t colour) const {
|
||||||
|
return is_checkmate_for(colour) && no_legal_moves_for(colour);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool is_stalemate_for(int8_t colour) const {
|
||||||
|
return !is_checkmate_for(colour) && no_legal_moves_for(colour);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool is_terminal() const {
|
||||||
|
return is_checkmate_for(White) || is_checkmate_for(Black)
|
||||||
|
|| is_stalemate_for(White) || is_stalemate_for(Black);
|
||||||
|
}
|
||||||
|
|
||||||
int8_t colour_at(int8_t idx) const {
|
int8_t colour_at(int8_t idx) const {
|
||||||
return squares[idx] & 0b11000;
|
return squares[idx] & 0b11000;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user