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

New winning square algorithm #8

Open
dmorawetz opened this issue Nov 21, 2020 · 2 comments
Open

New winning square algorithm #8

dmorawetz opened this issue Nov 21, 2020 · 2 comments
Labels
discussion Open to discussion

Comments

@dmorawetz
Copy link

@slovnicki asked for a cleaner algorithm to detect game termination.

Instead of comparing all the fields, we could track the state incrementally as described in this stackoverflow answer.

Basically, we keep an array of scores for every row, column and diagonal and update them after a valid move. Increment for X, decrement for O. When the score reaches 3 or -3 the corresponding player has won. We need such an array for every InnerGrid and one for the outer Grid.

@grayson-harrington
Copy link
Contributor

It sounds like solving this issue will also solve the issue I created.

#36

@slovnicki
Copy link
Collaborator

It sounds like solving this issue will also solve the issue I created.

Not quite solve it, but definitely make it cleaner. Because we still need some higher canWin function.

@slovnicki slovnicki added the discussion Open to discussion label Jun 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion Open to discussion
Projects
None yet
Development

No branches or pull requests

3 participants