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

3 fold repetition #67

Closed
nicholasmello opened this issue Apr 20, 2024 · 2 comments · Fixed by #82
Closed

3 fold repetition #67

nicholasmello opened this issue Apr 20, 2024 · 2 comments · Fixed by #82
Labels
bug Something isn't working

Comments

@nicholasmello
Copy link
Contributor

Description

3 fold repetition only checks moves in a row, it should check if the position repeats regardless of order

To Reproduce

Play a game and repeat the position, outside of the same order

Expected behavior

Draw in all repetition scenarios

Environment

OS: Linux (NixOS)
Terminal Emulator: Alacritty

Additional context

This function just needs to be rewritten

    pub fn draw_by_repetition(&self) -> bool {
        if self.move_history.len() >= 9 {
            let last_ten: Vec<PieceMove> =
                self.move_history.iter().rev().take(9).cloned().collect();

            if (last_ten[0].clone(), last_ten[1].clone())
                == (last_ten[4].clone(), last_ten[5].clone())
                && last_ten[4].clone() == last_ten[8].clone()
                && (last_ten[2].clone(), last_ten[3].clone())
                    == (last_ten[6].clone(), last_ten[7].clone())
            {
                return true;
            }
        }
        false
    }
@nicholasmello nicholasmello added the bug Something isn't working label Apr 20, 2024
@thomas-mauran
Copy link
Owner

Oh yes you are right ! I always thought 3 fold rep needed to be consecutive, do you want to take the pr ? else I might fix it this week, nice catch @nicholasmello

@nicholasmello
Copy link
Contributor Author

I'll take a look at it if I have time, my focus is on getting #65 flushed out. If someone takes a look at this before me, one thing to remember is "Two positions are by definition "the same" if the same types of pieces occupy the same squares, the same player has the move, the remaining castling rights are the same and the possibility to capture en passant is the same". Castling rights and the possibility of en passant are the obscure rules that often get left out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Done
2 participants