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 void AddToken_TokenIsRetrievable()
        {
            var tokenA = new Token(0, 'x');
            var tokenB = new Token(1, 'y');
            var board = GetBoard(6, 6, tokenA, tokenB);

            Assert.IsNull(board.GetToken(0, 0));
            Assert.IsNull(board.GetToken(3, 3));

            board.TryAddToken(0, 0, tokenA);

            Assert.AreEqual(tokenA, board.GetToken(0, 0));
            Assert.IsNull(board.GetToken(5, 5));

            board.TryAddToken(5, 5, tokenB);
            Assert.AreEqual(tokenA, board.GetToken(0, 0));
            Assert.AreEqual(tokenB, board.GetToken(5, 5));
        }
        public void DetectNull()
        {
            var tokenA = new Token(0, 'x');
            var tokenB = new Token(1, 'y');

            var state = new Connect4State(2, 2, tokenA, tokenB);

            state.PlayMove(new Connect4Move()
                {
                    Token = tokenA,
                    X = 0
                }
            );

            Assert.IsFalse(state.IsGameOver());

            state.PlayMove(new Connect4Move()
                {
                    Token = tokenA,
                    X = 0
                }
            );

            Assert.IsFalse(state.IsGameOver());

            state.PlayMove(new Connect4Move()
                {
                    Token = tokenA,
                    X = 1
                }
            );

            Assert.IsFalse(state.IsGameOver());

            state.PlayMove(new Connect4Move()
                {
                    Token = tokenA,
                    X = 1
                }
            );

            Assert.IsTrue(state.IsGameOver());
        }
        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 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);
        }
        public void Detect_Diagonale1()
        {
            var tokenA = new Token(0, 'x');
            var tokenB = new Token(1, 'y');

            var state = new Connect4State(7, 6, tokenA, tokenB);

            state.PlayMove(new Connect4Move()
            {
                Token = tokenA,
                X = 0
            }
            );

            Assert.IsFalse(state.IsGameOver());

            state.PlayMove(new Connect4Move()
            {
                Token = tokenB,
                X = 1
            }
            );

            Assert.IsFalse(state.IsGameOver());

            state.PlayMove(new Connect4Move()
            {
                Token = tokenA,
                X = 1
            }
            );

            Assert.IsFalse(state.IsGameOver());

            state.PlayMove(new Connect4Move()
            {
                Token = tokenB,
                X = 2
            }
            );

            Assert.IsFalse(state.IsGameOver());

            state.PlayMove(new Connect4Move()
            {
                Token = tokenA,
                X = 2
            }
            );

            Assert.IsFalse(state.IsGameOver());

            state.PlayMove(new Connect4Move()
            {
                Token = tokenA,
                X = 2
            }
            );

            Assert.IsFalse(state.IsGameOver());

            state.PlayMove(new Connect4Move()
            {
                Token = tokenB,
                X = 3
            }
            );

            Assert.IsFalse(state.IsGameOver());

            state.PlayMove(new Connect4Move()
            {
                Token = tokenA,
                X = 3
            }
            );

            Assert.IsFalse(state.IsGameOver());

            state.PlayMove(new Connect4Move()
            {
                Token = tokenA,
                X = 3
            }
            );

            Assert.IsFalse(state.IsGameOver());

            state.PlayMove(new Connect4Move()
            {
                Token = tokenA,
                X = 3
            }
            );

            Assert.IsTrue(state.IsGameOver());
        }
        public void DoesNotCountTheOpponent()
        {
            var tokenA = new Token(0, 'x');
            var tokenB = new Token(1, 'y');

            var state = new Connect4State(7, 6, tokenA, tokenB);

            state.PlayMove(new Connect4Move()
            {
                Token = tokenA,
                X = 0
            }
            );

            Assert.IsFalse(state.IsGameOver());

            state.PlayMove(new Connect4Move()
            {
                Token = tokenA,
                X = 0
            }
            );

            Assert.IsFalse(state.IsGameOver());

            state.PlayMove(new Connect4Move()
            {
                Token = tokenA,
                X = 0
            }
            );

            Assert.IsFalse(state.IsGameOver());

            state.PlayMove(new Connect4Move()
            {
                Token = tokenB,
                X = 0
            }
            );

            Assert.IsFalse(state.IsGameOver());
        }