Scoring system

I made a simple tic tac toe game out of a 3x3 grid of squares. The squares have a script that changes the texture on mouse down depending on whos turn it is. Each successful turn it changes to the other player.

I currently have two scripts one attached to an empty which basicly chooses a random player to start the game and manages some events. The other attached to the grid squares to change the texture.

What I’m having trouble with is a way to detrimine if a player has won or if its a tie. I was thinking of assigning a vaule to a naught of -1 or cross +1 and adding the values of each row, column and diagonally but im having a hard time putting it into code.

Im probably overthinking it but some input would be appreciated.

I recently did a tic tac toe and to check if there was a victory, I did like this :

  • First, store the nine positions in an array (top left, top center, etc)
  • Second, there is 8 ways to win (3 rows, 3 columns, 2 diag). You can either create a class that hold 3 ints and then create an array of 8 of those, or an array of 8 * 3 int. Fill it with the correct indices.
  • Each time someone has played, check all those 8 possibilities to see if they contains 3 times the same thing.

I suggest you use an enum to know the status of each squares (Circle, Cross, Empty for instance).

I’d like to know how to ask questions? On this website, thank you