public static int[,] positionsGame = new int[3, 3];
public static bool finishGame = false;
public static void Main()
Console.WriteLine("¡Bienvenidos al mundo de tres en linea!");
Console.WriteLine(":::3 en linea:::");
Console.WriteLine("::Menu::");
Console.WriteLine("1. P v P");
Console.WriteLine("2. P v CPU");
Console.WriteLine("0. Cerrar");
Console.WriteLine("Ingrese una opcion");
option = Int32.Parse(Console.ReadLine());
Console.WriteLine(":P v P:");
Console.WriteLine("El jugador 1 es X, Jugador 2 es O");
Console.WriteLine("Jugador 1: [x, y]");
Console.WriteLine("Ingrese X:");
x = Int32.Parse(Console.ReadLine());
Console.WriteLine("Ingrese Y:");
y = Int32.Parse(Console.ReadLine());
Console.WriteLine("[" + x + ", " + y + "]");
} while (positionsGame[x, y] != 0);
Console.WriteLine("Jugador 2: [x, y]");
Console.WriteLine("Ingrese X:");
x = Int32.Parse(Console.ReadLine());
Console.WriteLine("Ingrese Y:");
y = Int32.Parse(Console.ReadLine());
Console.WriteLine("[" + x + ", " + y + "]");
} while (positionsGame[x, y] != 0);
Console.WriteLine("¿Quiere volver a jugar? Y/N");
temp = Console.ReadLine();
if(temp == "Y" || temp == "y" )
Console.WriteLine("1. P v P");
Console.WriteLine("El jugador 1 es X, Jugador 2 es O");
Console.WriteLine("Saliendo de P v P");
Console.WriteLine(":P v CPU:");
Console.WriteLine("El jugador 1 es X, CPU es O");
Console.WriteLine("Jugador 1: [x, y]");
Console.WriteLine("Ingrese X:");
x = Int32.Parse(Console.ReadLine());
Console.WriteLine("Ingrese Y:");
y = Int32.Parse(Console.ReadLine());
Console.WriteLine("[" + x + ", " + y + "]");
}while (positionsGame[x, y] != 0);
Console.WriteLine("CPU : ");
Console.WriteLine("¿Quiere volver a jugar? Y/N");
temp = Console.ReadLine();
if(temp == "Y" || temp == "y" )
Console.WriteLine("1. P v P");
Console.WriteLine("El jugador 1 es X, Jugador 2 es O");
Console.WriteLine("Saliendo de P v P");
Console.WriteLine("Hasta luego");
Console.WriteLine("Opcion no disponible");
public static void ShowTable()
for (int i = 0; i < 3; i++)
for (int j = 0; j < 3; j++)
if (positionsGame[i, j] == 0)
Console.Write("_" + " ");
else if (positionsGame[i, j] == 1)
Console.Write("X" + " ");
else if (positionsGame[i, j] == 2)
Console.Write("O" + " ");
public static void ValidateGame()
for(int k = 1; k <= 2; k++)
for(int i = 0; i < 3; i++)
for (int j = 0; j < 3; j++)
if (positionsGame[i, j] == k)
countNext = countNext + 1;
Console.WriteLine("Gana jugador 1");
Console.WriteLine("Gana jugador 2");
for(int k = 1; k <= 2; k++)
for(int i = 0; i < 3; i++)
for (int j = 0; j < 3; j++)
if (positionsGame[j, i] == k)
countNext = countNext + 1;
Console.WriteLine("Gana jugador 1");
Console.WriteLine("Gana jugador 2");
if (!finishGame && positionsGame[0,0] == 1 &&positionsGame[1,1] == 1 && positionsGame[2,2] == 1)
Console.WriteLine("Gana jugador 1");
if (!finishGame && positionsGame[0,0] == 2 &&positionsGame[1,1] == 2 && positionsGame[2,2] == 2)
Console.WriteLine("Gana jugador 2");
if (!finishGame && positionsGame[0,2] == 1 &&positionsGame[1,1] == 1 && positionsGame[2,0] == 1)
Console.WriteLine("Gana jugador 1");
if (!finishGame && positionsGame[0,2] == 2 &&positionsGame[1,1] == 2 && positionsGame[2,0] == 2)
Console.WriteLine("Gana jugador 2");
for (int i = 0; i < 3; i++)
for (int j = 0; j < 3; j++)
if (positionsGame[i,j] != 0)
tempCount = tempCount + 1;
if (tempCount == 9 && !finishGame)
Console.WriteLine("Empate");
public static void cleartable()
for (int i = 0; i < 3; i++)
for (int j = 0; j < 3; j++)
public static void MachineTurn()
for (int i = 0; i < 3; i++)
for (int j = 0; j < 3; j++)
if (positionsGame[i,j] != 0)
tempCount = tempCount + 1;
if (positionsGame[i,j] == 1)
tempConse = tempConse + 1;
if (positionsGame[i,j] == 0)
if (tempConse == 2 && movMachine && positionsGame[i, tempConseJ] == 0)
positionsGame[i, tempConseJ] = 2;
for (int i = 0; i < 3; i++)
for (int j = 0; j < 3; j++)
if (positionsGame[j,i] == 1)
tempConse = tempConse + 1;
if (positionsGame[j,i] == 0)
if (tempConse == 2 && movMachine && positionsGame[tempConseJ, i] == 0)
positionsGame[tempConseJ, i] = 2;
if (positionsGame[0, 0] == 1)
tempDiagonal = tempDiagonal + 1;
if (positionsGame[1, 1] == 1)
tempDiagonal = tempDiagonal + 1;
if (positionsGame[2, 2] == 1)
tempDiagonal = tempDiagonal + 1;
if(tempDiagonal == 2 && movMachine)
if (positionsGame[0, 0] == 0)
else if (positionsGame[1, 1] == 0)
else if (positionsGame[2, 2] == 0)
if (positionsGame[0, 2] == 1)
tempDiagonal = tempDiagonal + 1;
if (positionsGame[1, 1] == 1)
tempDiagonal = tempDiagonal + 1;
if (positionsGame[2, 0] == 1)
tempDiagonal = tempDiagonal + 1;
if(tempDiagonal == 2 && movMachine)
if (positionsGame[0, 2] == 0)
else if (positionsGame[1, 1] == 0)
else if (positionsGame[2, 0] == 0)
Random ran = new Random();
} while (positionsGame[x, y] != 0);
Random ran = new Random();
} while (positionsGame[x, y] != 0);