Hey, I am making a sort of tic-tac-toe game, with a board of 5x5 and added features. But I am really struggling to check when a player has won. On a normal 3x3 board this is really easy, but when you expand the board it becomes much more difficult. I have a sort of solution but it involves tons and tons of if statements.
First check if the cell you are standing on is on the edge, in that case, only check on the other side.
Then check if you are one cell from the edge, in that case, only check one cell on that side and two on the other side.
And if you are in the middle, check two cells to the left and two cells to the right.
I had decided that I would only check for vertical and horizontal but that still would have been a lot of if statements and unreadable code.
So is there another way?
I was thinking of having 5 int arrays for each row and column and then whenever you place something the int in the array corresponding to the row or column you placed something on will be set to 1 if you are team 1 and 2 if you are team 2. Then after something has been placed you check the row and column in which you have placed something for if there are is a series of three 1âs or 2âs. You would end up with a grid that looks something like this.
Row1{ 1, 1, 1, 2, 0}
Row2{ 2, 1, 2, 0, 1}
Row3{ 0, 2, 1, 0, 0}
Row4{ 1, 0, 0, 2, 0}
Row5{ 2, 0, 1, 2, 0}
Indicating that on row 1 player 1 has a series on three and then won the game.
But how do you make this? And how do you adapt this to diagonals?
Thanks in advance,
Pepijn
