i'm trying to find the winner of a 3x3 TicTacToe game. I user input N which is number of moves, and then N moves like (1,0), (0,2), etc. (X strats the game). At the end of the game the program should return who wins the game (X or 0) or "draw" if there is no winner. I have the following code:
namespace ConsoleApp20;
public class Program
{
public static string Tictactoe(int[][] moves)
{
int[] row = new int[3];
int[] col = new int[3];
int diag1 = 0;
int diag2 = 0;
const int c1 = 2;
const int c2 = 3;
int n = Convert.ToInt32(Console.ReadLine());
for (int i = 0; i < n; i++)
{
int x = moves[i][0];
int y = moves[i][1];
var inc = i % 2 == 0 ? 1 : -1;
row[x] += inc;
col[y] += inc;
if (x == y)
{
diag1 += inc;
}
if (x + y == c1)
{
diag2 += inc;
}
if (Math.Abs(row[x]) == c2 || Math.Abs(col[y]) == c2 || Math.Abs(diag1) == c2 || Math.Abs(diag2) == c2)
{
return i % c1 == 0 ? "X" : "0";
}
}
return moves.Length == 9 ? "Draw" : "Pending";
}
}
I need a suggestion about how to reduce the cyclomatic complexity of this method from 11 to 10.