public void TestDiagonale()
        {
            var state = new TicTacTocState(3);
            Assert.IsFalse(state.IsGameOver());

            IToken token = new Token(1, 'X');
            IToken tokenEnnemy = new Token(2, 'O');

            state.PlayMove(new TicTacToeMove()
            {
                X = 0,
                Y = 0,
                Token = token
            });
            Assert.IsFalse(state.IsGameOver());

            state.PlayMove(new TicTacToeMove()
            {
                X = 1,
                Y = 1,
                Token = token
            });
            Assert.IsFalse(state.IsGameOver());

            state.PlayMove(new TicTacToeMove()
            {
                X = 2,
                Y = 2,
                Token = token
            });

            Assert.IsTrue(state.IsGameOver());
        }
        public static IGame GetGame(GameType gameType)
        {
            IGame game = null;

            switch (gameType)
            {
                case GameType.TicTacToe:

                    IPlayer humanPlayer = PlayerFactory.GetHumanPlayer(GameType.TicTacToe, 0);
                    IPlayer iaPlayer = PlayerFactory.GetAiPlayer(GameType.TicTacToe, 1, 4);
                    var gameBoard = new OptimizeGameBoard(4, 4, humanPlayer.Token, iaPlayer.Token);

                    IState initialState = new TicTacTocState(gameBoard);

                    game = new GameManager2P()
                    {
                        GameState = initialState,
                        PlayerA = humanPlayer,
                        PlayerB = iaPlayer
                    };

                    break;

                case GameType.Connect4:
                    humanPlayer = PlayerFactory.GetHumanPlayer(GameType.Connect4, 0);
                    iaPlayer = PlayerFactory.GetAiPlayer(GameType.Connect4, 1, 6);
                    gameBoard = new OptimizeGameBoard(5, 4, humanPlayer.Token, iaPlayer.Token);

                    initialState = new Connect4State(gameBoard);

                    game = new GameManager2P()
                    {
                        GameState = initialState,
                        PlayerA = humanPlayer,
                        PlayerB = iaPlayer
                    };
                    break;
            }

            return game;
        }
        public void AccessibleStateTest()
        {
            var state = new TicTacTocState(2);
            Assert.IsFalse(state.IsGameOver());

            IToken token = new Token(1, 'X');
            ITeamIdentifier player = new HumanPlayer(token, 1);

            var list = state.GetPossibleStates(player);

            Assert.AreEqual(4, list.Count);

            state.PlayMove(new TicTacToeMove()
            {
                X = 0,
                Y = 0,
                Token = token
            });

            list = state.GetPossibleStates(player);
            Assert.AreEqual(3, list.Count);
        }
        public void TestDiagonaleWithOponent()
        {
            var state = new TicTacTocState(3);
            Assert.IsFalse(state.IsGameOver());

            IToken tokenX = new Token(1, 'X');
            ITeamIdentifier opponent = new IAPlayer(tokenX, 1);

            IToken tokenO = new Token(2, 'O');
            ITeamIdentifier player = new IAPlayer(tokenO, 2);

            state.PlayMove(new TicTacToeMove()
            {
                X = 2,
                Y = 0,
                Token = tokenX
            });
            Assert.IsFalse(state.IsGameOver());

            state.PlayMove(new TicTacToeMove()
            {
                X = 0,
                Y = 2,
                Token = tokenX
            });
            Assert.IsFalse(state.IsGameOver());

            state.PlayMove(new TicTacToeMove()
            {
                X = 0,
                Y = 0,
                Token = tokenO
            });
            state.PlayMove(new TicTacToeMove()
            {
                X = 2,
                Y = 2,
                Token = tokenO
            });

            state.PlayMove(new TicTacToeMove()
            {
                X = 1,
                Y = 1,
                Token = tokenX
            });
            Assert.IsTrue(state.IsGameOver());
            Assert.AreEqual(1, state.GetValueFor(opponent));
            Assert.AreEqual(-1, state.GetValueFor(player));
        }
 public void TestClone_NotSameReference()
 {
     var state = new TicTacTocState(5);
     var clone = state.Copy();
     Assert.AreNotEqual(clone, state);
 }
        public void TestVerticallWin()
        {
            var state = new TicTacTocState(3);
            Assert.IsFalse(state.IsGameOver());

            IToken token = new Token(1, 'X');

            state.PlayMove(new TicTacToeMove()
            {
                X = 0,
                Y = 0,
                Token = token
            });
            Assert.IsFalse(state.IsGameOver());

            state.PlayMove(new TicTacToeMove()
            {
                X = 0,
                Y = 1,
                Token = token
            });
            Assert.IsFalse(state.IsGameOver());

            state.PlayMove(new TicTacToeMove()
            {
                X = 0,
                Y = 2,
                Token = token
            });

            Assert.IsTrue(state.IsGameOver());
        }
        public void NotLoosingTest()
        {
            var state = new TicTacTocState(3);

            IToken tokenY = new Token(2, 'Y');
            ITeamIdentifier player = new IAPlayer(tokenY, 2);

            IToken tokenX = new Token(1, 'X');
            ITeamIdentifier opponent = new IAPlayer(tokenX, 1);

            var solver = GetStrateger();

            state.PlayMove(new TicTacToeMove()
            {
                X = 0,
                Y = 0,
                Token = tokenX
            });
            Assert.IsFalse(state.IsGameOver());

            state.PlayMove(new TicTacToeMove()
            {
                X = 1,
                Y = 1,
                Token = tokenX
            });
            Assert.IsFalse(state.IsGameOver());

            state.PlayMove(new TicTacToeMove()
            {
                X = 0,
                Y = 1,
                Token = tokenX
            });
            Assert.IsFalse(state.IsGameOver());

            state.PlayMove(new TicTacToeMove()
            {
                X = 0,
                Y = 2,
                Token = tokenY
            });
            Assert.IsFalse(state.IsGameOver());

            state.PlayMove(new TicTacToeMove()
            {
                X = 2,
                Y = 1,
                Token = tokenY
            });
            Assert.IsFalse(state.IsGameOver());

            state.Display();
            var move = solver.FindBestMove(state, player, opponent) as TicTacToeMove;
            Assert.IsNotNull(move);
            Assert.IsFalse(state.IsGameOver());
            Assert.AreEqual(2, move.X);
            Assert.AreEqual(2, move.Y);
        }