AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |
Back to Blog
Stockfish chess move generator1/30/2024 ![]() This is very strange, because isolated, the make_move() method works just fine. The app also includes free access to a growing list of engines running. When printing the game state after calling game_state.make_move() in perft(), it seems to have had no effect on the position bitboards (the other properties change like they are supposed to). NCM is a powerful chess calculator that runs Stockfish 15.1 directly on your device. To sort the vector of legal moves causes the found number of total nodes for the initial position (for depth 3) to change from the wrong 7070 to the (also wrong) 7331. I discovered some interesting new facts that might help to solve the problem, but I don't know what to do with them:įor some reason, using std::sort() like this in perft(): std::sort(legal_moves.begin(), legal_moves.end(), (auto first, auto second)) If you have any idea what the problem could be here, please help me out. When calling perft() on the position you get after making the move a2a3 in the initial position in my engine, it calculates the correct number of total nodes at depth 2, 380:.When calling perft() on the initial position in my engine, it calculates 280 subnodes for a2a3 at depth 3.When calling perft() on the initial position in stockfish, it calculates 380 subnodes for a2a3 at depth 3.But for all moves I tried this with, the engine suddenly starts to output the correct results I expected to get earlier! Nobody would use an engine to verify a moves legality. Anything could happen if you give a move as illegal. If you give it an illegal move, the behavior is undefined - from a crash to jumping king. I figured that my move generator was just buggy, and tried to track down the bugs by making a move the engine gives incorrect values for on the board and then calling perft() with depth = 2 on it to find out which moves are missing. Stockfish is a chess engine it always and always assume a move given is legal. The results stop matching at depth 3, though: It's results for the initial chess position (FEN: rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1) for depths 1 and 2 match the results of stockfish's perft command, so I assume they are correct: h2h3: 1 Nodes += perft_no_print(game_state, depth - 1) Std::cout legal_moves = generator.generate_legal_moves(game_state) ![]() Last_move_nodes = perft_no_print(game_state, depth - 1) Std::vector legal_moves = generator.generate_legal_moves(game_state) For this purpose, I wrote a simple perft() function: int32_t Engine::perft(GameState game_state, int32_t depth) ![]() If there are no moves in the position, an empty list is returned.I am currently developing a chess engine in C++, and I am in the process of debugging my move generator. The score is either `cp` or `mate` a higher `cp` is better, positive `mate` To which side is playing instead of absolute like `get_top_moves`. Unlike `get_top_moves` - which returns a list of dict, this will yieldĪ list of `Stockfish.TopMove` instead, and the score (cp/mate) is relative ![]() This however will take some time for stockfish to stop. The evaluation could be stopped early by calling Generator.close() The number of moves to return info on, assuming there are at leastĪ generator that yields top moves in the position at each depth. """Returns a generator that yields top moves in the position at each depth # equal move, by "move", not by score/evaluationĭef _eq_(self, other: Stockfish.TopMove) -> bool: # both winning move, which takes less move is better # both losing move, which takes more moves is better # compare if this move is better than the other moveĭef _gt_(self, other: Stockfish.TopMove) -> bool: Here's the idea, you can read more about this in the PR: I have created a pull request that adds generate_top_moves method which returns a generator that yields top moves in the position at each depth. As it is not possible to create such a large array in-memory, Stockfish will instead use a hashmap to store the candidate moves. Since the blockers board is a 64-bits variable, the array containing the candidate moves will have 2 elements, which is about one Exabyte in size. While evaluating, stockfish will output top moves at each depth, but the package will wait until the evaluation is done. With this method, a practical problem is raised. In the stockfish package, The get_evaluation function works by evaluating the top moves in the current position, the score is either the centipawn or mate.
0 Comments
Read More
Leave a Reply. |