added the check for insufficient material
This commit is contained in:
parent
fced9757c2
commit
6e567f2f11
@ -5,6 +5,7 @@
|
|||||||
#include "../utils/move.hpp"
|
#include "../utils/move.hpp"
|
||||||
#include "../utils/utils.hpp"
|
#include "../utils/utils.hpp"
|
||||||
|
|
||||||
|
#include <SFML/Graphics/BlendMode.hpp>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cctype>
|
#include <cctype>
|
||||||
#include <map>
|
#include <map>
|
||||||
@ -269,6 +270,28 @@ Board Board::make_move(Move move) const {
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Board::insufficient_material_for(Colour current_colour) const {
|
||||||
|
int n_bishop = 0, n_knight = 0;
|
||||||
|
|
||||||
|
for (int i = 0; i < 64; i++) {
|
||||||
|
Colour colour = colour_at(i);
|
||||||
|
if (colour != current_colour)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
Piece piece = piece_at(i);
|
||||||
|
if (piece == Piece::Pawn || piece == Piece::Queen
|
||||||
|
|| piece == Piece::Rook)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (piece == Piece::Bishop)
|
||||||
|
n_bishop++;
|
||||||
|
if (piece == Piece::Knigt && colour == Colour::White)
|
||||||
|
n_knight++;
|
||||||
|
}
|
||||||
|
return (n_bishop == 0 && n_knight == 0) || (n_bishop == 1 && n_knight == 0)
|
||||||
|
|| (n_bishop == 0 && n_knight == 1);
|
||||||
|
}
|
||||||
|
|
||||||
int8_t Board::get_king_of(int8_t colour) const {
|
int8_t Board::get_king_of(int8_t colour) const {
|
||||||
for (int i = 0; i < 64; i++)
|
for (int i = 0; i < 64; i++)
|
||||||
if (squares[i] == (colour | Piece::King))
|
if (squares[i] == (colour | Piece::King))
|
||||||
|
@ -25,7 +25,12 @@ struct Board {
|
|||||||
Board make_move(Move) const;
|
Board make_move(Move) const;
|
||||||
std::string to_fen() const;
|
std::string to_fen() const;
|
||||||
bool is_check_for(int8_t) const;
|
bool is_check_for(int8_t) const;
|
||||||
bool insufficient_material() const;
|
bool insufficient_material_for(Colour) const;
|
||||||
|
|
||||||
|
bool insufficient_material() const {
|
||||||
|
return insufficient_material_for(White)
|
||||||
|
&& insufficient_material_for(Black);
|
||||||
|
};
|
||||||
|
|
||||||
std::vector<Move> all_legal_moves() const;
|
std::vector<Move> all_legal_moves() const;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user