public static bool DoesGameHaveWinner(TicTacToeState state) { var board = state.board; var winningLines = new List<List<MovePosition>> { new List<MovePosition> { MovePosition.TopLeft, MovePosition.TopCenter, MovePosition.TopRight }, new List<MovePosition> { MovePosition.MiddleLeft, MovePosition.MiddleCenter, MovePosition.MiddleRight }, new List<MovePosition> { MovePosition.BottomLeft, MovePosition.BottomCenter, MovePosition.BottomRight }, new List<MovePosition> { MovePosition.TopLeft, MovePosition.MiddleLeft, MovePosition.BottomLeft }, new List<MovePosition> { MovePosition.TopCenter, MovePosition.MiddleCenter, MovePosition.BottomCenter }, new List<MovePosition> { MovePosition.TopRight, MovePosition.MiddleRight, MovePosition.BottomRight }, new List<MovePosition> { MovePosition.TopLeft, MovePosition.MiddleCenter, MovePosition.BottomRight }, new List<MovePosition> { MovePosition.BottomLeft, MovePosition.MiddleCenter, MovePosition.TopRight }, }; bool hasWinner = winningLines.Any( x => IsLineAllEqual(board, x[0], x[1], x[2])); return hasWinner; }
public void IsBoardFull_IsTrue() { var state = new TicTacToeState { board = new List<PlayerMark> { PlayerMark.X, PlayerMark.O, PlayerMark.X, PlayerMark.X, PlayerMark.O, PlayerMark.X, PlayerMark.O, PlayerMark.X, PlayerMark.O, } }; var isFull = TicTacToeLogic.IsBoardFull(state); Assert.True(isFull); }
public void IsBoardFull_IsFalse() { var state = new TicTacToeState { board = new List<PlayerMark> { PlayerMark.Empty, PlayerMark.Empty, PlayerMark.Empty, PlayerMark.Empty, PlayerMark.Empty, PlayerMark.Empty, PlayerMark.Empty, PlayerMark.Empty, PlayerMark.Empty, } }; var isFull = TicTacToeLogic.IsBoardFull(state); Assert.False(isFull); }
public void DoesGameHaveWinner_IsTrue() { var state = new TicTacToeState { firstPlayer = Guid.Empty, secondPlayer = Guid.Empty, board = new List<PlayerMark> { PlayerMark.Empty, PlayerMark.Empty, PlayerMark.Empty, PlayerMark.X, PlayerMark.X, PlayerMark.X, PlayerMark.Empty, PlayerMark.Empty, PlayerMark.Empty, } }; var hasWinner = TicTacToeLogic.IsGameOver(state); Assert.True(hasWinner); }
public static bool IsGameTie(TicTacToeState state) { var isTie = IsBoardFull(state) && !DoesGameHaveWinner(state); return isTie; }
public static bool IsGameOver(TicTacToeState state) { bool gameOver = DoesGameHaveWinner(state) || IsBoardFull(state); return gameOver; }
public static bool IsBoardFull(TicTacToeState state) { var isFull = state.board.All(x => x != PlayerMark.Empty); return isFull; }