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

Additions to determine the winner. #1

Merged

Conversation

cambiaresearch
Copy link
Contributor

My approach for determining the winner might be a bit brute force, but I think it's intuitive. Thanks for the code and article.

@conficient
Copy link

I'd suggest a simpler approach than trying to brute-force checking every cell - just check the last move to see if that's a winning move.

By definition the winning move must be the last one (or we've missed a winning move!) - so rather than checking every cell in the board, just check for a row of four from the last one. Further to this you can skip the win check if the total number of moves made is less than 7.

I'd also suggest there are only three 'directions' to check: horizontal, vertical, diagonal. You would need to scan in each direction since a counter may have been dropped in the middle of a row.

@conficient
Copy link

Correction: having tried to write it myself there are indeed four directions, the diagonals are two separate "directions", I stand corrected

@exceptionnotfound exceptionnotfound merged commit 29152d4 into exceptionnotfound:master Nov 6, 2019
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

Successfully merging this pull request may close these issues.

3 participants