So I got the game mostly done, except for the win conditions. I haven’t looked at how others have solved this, but the way my tic tac toe game works is the following…
You’ve got an array called board. board = [0,1,2,3,4,5,6,7,8]; The array is visually set up like this.
0 | 1 | 2
3 | 4 | 5
6 | 7 | 8
When an X or O is placed on the board, it replaces one of those ints with a
string for “X” or “O”.
So when, for example…board[0,1,2] =[“X”,“X”,“X”] or also with O…it’s a winning turn. And the same for these.
I could have a bunch of if statements but that seems really redundant. Then I thought about making the array a string and checking for regex patterns but the pattern here seems like it would be really complex. Any way around a bunch of if statements or a regex string longer than a Tolstoy novel?