You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@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.
The text was updated successfully, but these errors were encountered:
@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.
The text was updated successfully, but these errors were encountered: