Skip to content

Commit

Permalink
Validate max one king per side
Browse files Browse the repository at this point in the history
  • Loading branch information
ianfab committed Mar 1, 2024
1 parent def2560 commit fb8cf35
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/apiutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -821,6 +821,16 @@ inline Validation check_number_of_kings(const std::string& fenBoard, const std::
int nbWhiteKingsStart = piece_count(startFenBoard, WHITE, KING, v);
int nbBlackKingsStart = piece_count(startFenBoard, BLACK, KING, v);

if (nbWhiteKings > 1)
{
std::cerr << "Invalid number of white kings. Maximum: 1. Given: " << nbWhiteKings << std::endl;
return NOK;
}
if (nbBlackKings > 1)
{
std::cerr << "Invalid number of black kings. Maximum: 1. Given: " << nbBlackKings << std::endl;
return NOK;
}
if (nbWhiteKings != nbWhiteKingsStart)
{
std::cerr << "Invalid number of white kings. Expected: " << nbWhiteKingsStart << ". Given: " << nbWhiteKings << std::endl;
Expand Down

0 comments on commit fb8cf35

Please sign in to comment.