public TicTacToeGame() : base() { table = new TicTacToeTable(); rules = new List <IRule <TicTacToe> >() { new ValidPlayTicTacToeRule() }; }
public TicTacToeGame(Player <TicTacToe> player1, Player <TicTacToe> player2) : base(new List <Team <TicTacToe> >() { new Team <TicTacToe>(player1.Id, new List <Player <TicTacToe> >(){ player1 }), new Team <TicTacToe>(player2.Id, new List <Player <TicTacToe> >(){ player2 }) }) { table = new TicTacToeTable(); rules = new List <IRule <TicTacToe> >() { new ValidPlayTicTacToeRule() }; }
/// <summary> /// Método que verifica si ya hay un ganador, chequeando si existe una fila, columna o diagonal llenas por un juagador /// </summary> /// <param name="x"></param> /// <param name="y"></param> /// <param name="my_table"></param> /// <returns></returns> public bool AreInLine(int x, int y, TicTacToeTable my_table) { bool inLine = true; for (int i = 0; i < my_table.CountColumns; i++) { if (my_table.Board[x, y] != my_table.Board[x, i]) { inLine = false; } } if (inLine) { return(true); } else { inLine = true; for (int i = 0; i < my_table.CountRows; i++) { if (my_table.Board[x, y] != my_table.Board[i, y]) { inLine = false; } } if (inLine) { return(true); } } if (x == 0 && y == 0) { inLine = true; int i = 0; int j = 0; while (i < my_table.CountRows && j < my_table.CountColumns) { if (my_table.Board[0, 0] != my_table.Board[i, j]) { inLine = false; } i++; j++; } if (inLine) { return(true); } } if (x == 0 && y == my_table.CountColumns) { inLine = true; int i = 0; int j = 0; while (i < my_table.Board.GetLength(0) && j >= 0) { if (my_table.Board[0, 0] == my_table.Board[i, j]) { inLine = false; } i++; j--; } if (inLine) { return(true); } } return(false); }