Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calling Position::set on existing object leads to wrong results #16

Open
osvitashev opened this issue Sep 1, 2021 · 2 comments
Open

Comments

@osvitashev
Copy link

As far as i can say Position::set assumes the object is blank and does not clear the existing values in it, which leads to wrong move generation if the object is reused:

  int main() {
   initialise_all_databases();
   zobrist::initialise_zobrist_keys();

   Position p;
   Position::set("8/2p5/3p4/KP5r/1R3p1k/8/4P1P1/8 w - - ", p);
   auto n = perft<WHITE>(p, 4);
   std::cout<<n<<std::endl;
   Position::set("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1", p);
   Position::set("8/2p5/3p4/KP5r/1R3p1k/8/4P1P1/8 w - - ", p); //same as first position
   n = perft<WHITE>(p, 4); //same as the first perft call
   std::cout << n << std::endl; //this gives wrong perft count

   return 0;
  }
@Dark42ed
Copy link

Dark42ed commented Oct 26, 2021

For anyone wondering, the solution is to create a new board and copy over the position.

Position newBoard;
Position::set(brokenBoard.fen(), newBoard);
// Use newBoard from here

@nkarve
Copy link
Owner

nkarve commented Jun 24, 2022

@Dark42ed nice temporary fix, but I'll be reworking Position::set soon, it's the most poorly implemented function in the whole library. The idea of having this function was originally pinched from Stockfish, but I think it would probably go better in the default/copy constructors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants