Esempio n. 1
0
    public void StrangeWeakCase()
    {
        List <Point> playerMoves = new List <Point> {
            Point.Make(0, 2), Point.Make(2, 0), Point.Make(2, 2), Point.Make(1, 2)
        };
        var gameState = new Gameplay.GameState(Gameplay.Player.X);

        foreach (var point in playerMoves)
        {
            var move = new Gameplay.Move(point);

            if (gameState.PossibleMoves.Contains(move))
            {
                gameState = gameState.PickAMove(move);
            }
            else
            {
                gameState = gameState.PickAMove(gameState.PossibleMoves[0]);
            }

            if (gameState.IsEndState)
            {
                break;
            }

            var aiMove = m_ai.NextMove(gameState);
            gameState = gameState.PickAMove(aiMove);
        }

        Assert.AreEqual(Gameplay.Player.O, gameState.VictoryState.Winner);
    }
Esempio n. 2
0
        public void CantPickAnUnavailableMove()
        {
            var gameState = new GameState(Player.X);
            var move      = new Move(Point.Make(0, 0));

            gameState = gameState.PickAMove(move);

            Assert.Throws <Exception> (() => {
                gameState.PickAMove(move);
            });
        }
Esempio n. 3
0
        public void EmptyBoardMustHave8AfterFirstMove()
        {
            var gameState = new GameState(Player.X);

            gameState = gameState.PickAMove(gameState.PossibleMoves[0]);

            Assert.AreEqual(8, gameState.PossibleMoves.Count);
        }
Esempio n. 4
0
        public void PickMoveChangesTurn()
        {
            var gameState = new GameState(Player.X);

            var move = gameState.PossibleMoves [1];

            gameState = gameState.PickAMove(move);

            Assert.AreEqual(Player.O, gameState.CurrentPlayer);
        }
Esempio n. 5
0
        public void OtherVictoriousX()
        {
            var gameState = new GameState(Player.O);

            foreach (var target in m_secondWins)
            {
                gameState = gameState.PickAMove(new Move(target));
            }

            Assert.AreEqual(Player.X, gameState.VictoryState.Winner);
        }
Esempio n. 6
0
        public void OIsVictorious()
        {
            var gameState = new GameState(Player.O);

            foreach (var target in m_starterWins)
            {
                gameState = gameState.PickAMove(new Move(target));
            }

            Assert.AreEqual(Player.O, gameState.VictoryState.Winner);
        }
Esempio n. 7
0
        public void PickMoveChangesCellOwner()
        {
            var gameState = new GameState(Player.X);

            var move = gameState.PossibleMoves [0];

            gameState = gameState.PickAMove(move);

            var cell = gameState [Point.Make(0, 0)];

            Assert.AreEqual(Player.X, cell.Owner);
        }
Esempio n. 8
0
        public void NoneVictoriousAfterSingleMove()
        {
            var gameState = new GameState(Player.X);

            foreach (var target in m_secondWins)
            {
                gameState = gameState.PickAMove(new Move(target));
                break;
            }

            Assert.AreEqual(Player.None, gameState.VictoryState.Winner);
        }
Esempio n. 9
0
        public void CellOwnerEqualsCurrentPlayer()
        {
            var gameState = new GameState(Player.O);

            var move = gameState.PossibleMoves [0];

            gameState = gameState.PickAMove(move);

            var cell = gameState [Point.Make(0, 0)];

            Assert.AreEqual(Player.O, cell.Owner);
        }
Esempio n. 10
0
    public void AiVsAiDraw()
    {
        var gameState = new Gameplay.GameState(Gameplay.Player.X);

        while (!gameState.IsEndState)
        {
            var move = m_ai.NextMove(gameState);
            gameState = gameState.PickAMove(move);
        }

        bool draw = gameState.PossibleMoves.Count == 0 && gameState.VictoryState.Winner.Equals(Gameplay.Player.None);

        Assert.That(draw, "Move Count: " + gameState.PossibleMoves.Count + " Winner: " + gameState.VictoryState.Winner);
    }
Esempio n. 11
0
        public void PickAMoveRemovesItFromPossibleMoves()
        {
            var gameState = new GameState(Player.X);

            var move = gameState.PossibleMoves [0];

            gameState = gameState.PickAMove(move);

            var notContains = gameState.PossibleMoves.Count((m) => {
                return(m.Target.Equals(move.Target));
            }) == 0;

            Assert.That(notContains);
        }
Esempio n. 12
0
        public void ShouldContainTheWinningMove()
        {
            var gameState = new GameState(Player.X);


            foreach (var target in m_starterAlmosVicotirous)
            {
                gameState = gameState.PickAMove(new Move(target));
            }

            bool contains = gameState.PossibleMoves.Contains(new Move(Point.Make(2, 0)));

            Assert.That(contains, "should contain the winning move");
        }
Esempio n. 13
0
        public AiCase(IList <Point> moves, IEnumerable <Point> nextMoves, Gameplay.Player player)
        {
            State = new Gameplay.GameState(player);

            foreach (var point in moves)
            {
                State = State.PickAMove(new Gameplay.Move(point));
            }

            NextMoves = new List <Gameplay.Move>();

            foreach (var point in nextMoves)
            {
                NextMoves.Add(new Gameplay.Move(point));
            }
        }
Esempio n. 14
0
        public void PossiblePlayDontContainAnAlreadyPlayedMove()
        {
            var gameState = new GameState(Player.X);

            foreach (var target in m_draw)
            {
                var move = new Move(target);
                gameState = gameState.PickAMove(move);

                bool contains = gameState.PossibleMoves.Contains(move);

                if (contains)
                {
                    Assert.Fail("should not contain move " + target);
                    break;
                }
            }
        }
Esempio n. 15
0
        public void Draw()
        {
            var  gameState  = new GameState(Player.X);
            bool alwaysNone = true;

            foreach (var target in m_draw)
            {
                gameState = gameState.PickAMove(new Move(target));

                alwaysNone = alwaysNone && gameState.VictoryState.Winner.Equals(Player.None);

                if (!alwaysNone)
                {
                    Assert.Fail(gameState.VictoryState.Winner + " should not have won");
                    break;
                }
            }
            Assert.AreEqual(0, gameState.PossibleMoves.Count, "The end game must have no possible moves");
        }
Esempio n. 16
0
 public AI.IState <Move> Pick(Move move)
 {
     return(new AiStateAdapter(m_gameState.PickAMove(move), m_bot));
 }