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

Not working if the game is completed in more than 3 steps #1

Open
connect-dips opened this issue Sep 5, 2017 · 3 comments
Open

Not working if the game is completed in more than 3 steps #1

connect-dips opened this issue Sep 5, 2017 · 3 comments

Comments

@connect-dips
Copy link

connect-dips commented Sep 5, 2017

This quick and easy approach for the Tic Tac Toe game algorithm. One issue I have noticed is that the game works perfectly well if I win on the 3rd click. But, if I win on the 4th step it is not being counted and always return 'Game tied'.

This is because the below condition fails on the 4th click game win,

if(winningPosition && currentPlayerPositions === winningPosition){
     game.announceWinner();
}

tictactoe-bug

Any fix identified?

Thanks.

@ayushgp
Copy link
Owner

ayushgp commented Sep 6, 2017

@connect-dips Thanks for reporting the issue! The condition for checking win should be the following:

if((winningPosition & currentPlayerPositions) === winningPosition){
	game.announceWinner();
}

Note that its an & and not && as we need bitwise and not logical one.

@connect-dips
Copy link
Author

@ayushgp this issue is reproducible on the demo here, http://tic-tac-toe-realtime.herokuapp.com/. The condition change was part of some workarounds I tried.

@ayushgp
Copy link
Owner

ayushgp commented Sep 6, 2017 via email

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

No branches or pull requests

2 participants