question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Board reports legal moves after drawn position

See original GitHub issue

To reproduce, use the code snippet below for MyBot and play g1 to g3, then shuffle the rook back and forth. The computer should do the same in the opposite corner, and a repetition draw will (correctly) occur after a few moves back and forth.

public class MyBot : IChessBot
{
    public Move Think(Board board, Timer timer)
    {
        Move[] moves = board.GetLegalMoves();
        Move moveToPlay = moves[0];

        board.MakeMove(moveToPlay);
        if (board.IsDraw())
        {
            System.Console.WriteLine(
                "Number of legal positions from drawn position: {0}",
                board.GetLegalMoves().Length
            );
        }
        board.UndoMove(moveToPlay);

        return moveToPlay;
    }
}

Doing so produces the following output:

Launching Chess-Challenge version 1.13
Number of legal positions from drawn position: 19
Number of legal positions from drawn position: 20
Number of legal positions from drawn position: 19
Game Over: Repetition

There should be no legal moves following a draw, as the game has ended. Further, the bot misreports that its next move will be a draw twice too early, but I think https://github.com/SebLague/Chess-Challenge/issues/170 deals with this already.

Issue Analytics

  • State:open
  • Created 2 months ago
  • Reactions:2
  • Comments:6

github_iconTop GitHub Comments

1reaction
WorstWizardcommented, Jul 24, 2023

A simple tree search (the way I’ve implemented it for instance) will usually only evaluate the state of the board at the leaf nodes. The easiest way to do this is to get a list of legal moves, and then recursively evaluate on the board state following those moves.

With the current behaviour, you would have to check whether the board is a draw at each internal node if you don’t want to search an invalid state space, rather than just the leaves. Since we’re constrained on token space in this challenge, this absolutely matters. Whether or not it is intended behaviour is up to @SebLague of course, but the current behaviour seems unintuitive, it’s certainly not documented.

Move generators don’t concern themselves with the 50 move rule or repetitions, that’s not what they’re made for.

The Board class includes a check for whether the current state is a draw, because it knows whether or not it is (or at least it should). So it should already know that the moves it’s generating are bogus. It’s not just a move generator, it already tracks this information, just a matter of including that in its knowledge of move legality.

0reactions
WorstWizardcommented, Jul 29, 2023

That’s a perfectly valid point! Wasn’t aware that it was optional per actual rules. Within this version of the game, it is an instant draw, so I’ll leave the issue open for now as it could still be a convenience feature.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Repeat Moves In Drawn Position
The game is not automatically drawn if a position occurs for the third time – one of the players, on their turn to...
Read more >
Does 'dead position' consider the 75 moves rule?
The game is drawn when a position has arisen in which neither player can checkmate the opponent's king with any series of legal...
Read more >
(Rant) This was the position on move 47. My opponent kept ...
Under FIDE rules: When no legal sequence of moves can lead to checkmate, the game is already drawn. Does not matter whether time...
Read more >
Draw (chess)
Under the standard FIDE rules, a draw also occurs in a dead position (when no sequence of legal moves can lead to checkmate),...
Read more >
Summary of differences between the FIDE Laws of ...
US. Chess rules allow a player to claim a draw by triple occurrence or the 50-move rule after moving (determining the move) but...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found