コード例 #1
0
ファイル: TicTacToeLogic.cs プロジェクト: emactaggart/CS476
        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;
        }
コード例 #2
0
ファイル: TicTacToeTests.cs プロジェクト: emactaggart/CS476
 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);
 }
コード例 #3
0
ファイル: TicTacToeTests.cs プロジェクト: emactaggart/CS476
 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);
 }
コード例 #4
0
ファイル: TicTacToeTests.cs プロジェクト: emactaggart/CS476
 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);
 }
コード例 #5
0
ファイル: TicTacToeLogic.cs プロジェクト: emactaggart/CS476
 public static bool IsGameTie(TicTacToeState state)
 {
     var isTie = IsBoardFull(state) && !DoesGameHaveWinner(state);
     return isTie;
 }
コード例 #6
0
ファイル: TicTacToeLogic.cs プロジェクト: emactaggart/CS476
 public static bool IsGameOver(TicTacToeState state)
 {
     bool gameOver = DoesGameHaveWinner(state) || IsBoardFull(state);
     return gameOver;
 }
コード例 #7
0
ファイル: TicTacToeLogic.cs プロジェクト: emactaggart/CS476
 public static bool IsBoardFull(TicTacToeState state)
 {
     var isFull = state.board.All(x => x != PlayerMark.Empty);
     return isFull;
 }