/// <summary> /// Check if winner exists /// </summary> /// <param name="board">current state of the board</param> /// <returns>if winner exists</returns> public bool CheckForWinner(Board board) { int[][] winners = new int[][] { new[] { 1, 2, 3 }, new[] { 4, 5, 6 }, new[] { 7, 8, 9 }, new[] { 1, 4, 7 }, new[] { 2, 5, 8 }, new[] { 3, 6, 9 }, new[] { 1, 5, 9 }, new[] { 3, 5, 7 } }; // Given all the winning conditions, Determine the winning logic. for (int i = 0; i < winners.Length; i++) { Position p1 = Player.PositionForNumber(winners[i][0]); Position p2 = Player.PositionForNumber(winners[i][1]); Position p3 = Player.PositionForNumber(winners[i][2]); string a = Board.GameBoard[p1.Row, p1.Column]; string b = Board.GameBoard[p2.Row, p2.Column]; string c = Board.GameBoard[p3.Row, p3.Column]; if ($"{a}{b}{c}" == "XXX" || $"{a}{b}{c}" == "OOO") { return(true); } } return(false); }
/// <summary> /// Check if winner exists /// </summary> /// <param name="board">current state of the board</param> /// <returns>if winner exists</returns> public bool CheckForWinner(Board board) { int[][] winners = new int[][] { new[] { 1, 2, 3 }, new[] { 4, 5, 6 }, new[] { 7, 8, 9 }, new[] { 1, 4, 7 }, new[] { 2, 5, 8 }, new[] { 3, 6, 9 }, new[] { 1, 5, 9 }, new[] { 3, 5, 7 } }; // Given all the winning conditions, Determine the winning logic. for (int i = 0; i < winners.Length; i++) { Position pos1 = Player.PositionForNumber(winners[i][0]); Position pos2 = Player.PositionForNumber(winners[i][1]); Position pos3 = Player.PositionForNumber(winners[i][2]); string a = Board.GameBoard[pos1.Row, pos1.Column]; string b = Board.GameBoard[pos2.Row, pos2.Column]; string c = Board.GameBoard[pos3.Row, pos3.Column]; if (a == "X" && b == "X" && c == "X") { Winner = PlayerOne; return(true); } else if (a == "O" && b == "O" && c == "O") { Winner = PlayerTwo; return(true); } // TODO: Determine a winner has been reached. // return true if a winner has been reached. } return(false); }
/// <summary> /// Check if winner exists /// </summary> /// <param name="board">current state of the board</param> /// <returns>if winner exists</returns> public bool LookForAWinner(Board board) { int[][] winners = new int[][] { //Row Wins new[] { 1, 2, 3 }, new[] { 4, 5, 6 }, new[] { 7, 8, 9 }, //Col Wins new[] { 1, 4, 7 }, new[] { 2, 5, 8 }, new[] { 3, 6, 9 }, //Diag Wins new[] { 1, 5, 9 }, new[] { 3, 5, 7 } }; // Given all the winning conditions, Determine the winning logic. for (int i = 0; i < winners.Length; i++) { Position p1 = Player.PositionForNumber(winners[i][0]); Position p2 = Player.PositionForNumber(winners[i][1]); Position p3 = Player.PositionForNumber(winners[i][2]); string a = Board.GameBoard[p1.Row, p1.Column]; string b = Board.GameBoard[p2.Row, p2.Column]; string c = Board.GameBoard[p3.Row, p3.Column]; // TODO: Determine a winner has been reached. // return true if a winner has been reached. if ($"{a}{b}{c}" == "XXX" || $"{a}{b}{c}" == "OOO") { return(true); } } return(false); }