public void ThreeStepsAwayFromMaxWinning_MaxTurn_MaxWin(int degreeOfParallelism, ParallelismMode parallelismMode)
        {
            TicTacToeState startState = new TicTacToeState(new[, ]
            {
                { Player.Max, Player.Min, Player.Max },
                { Player.Empty, Player.Empty, Player.Empty },
                { Player.Min, Player.Empty, Player.Empty },
            }, Player.Max);

            var engine     = GetSearchEngine(degreeOfParallelism, parallelismMode);
            var evaluation = engine.Search(startState, 3);

            Assert.AreEqual(Player.Max, ((TicTacToeState)evaluation.NextMove).Board[2, 2]);
            var lastMove = (IDeterministicState)evaluation.StateSequence.Last();

            Assert.AreEqual(TicTacToeState.MaxValue, lastMove.Evaluate(0, new List <IState>()), "Should have found a wining state");
        }
Ejemplo n.º 2
0
        private void TestCase(char[] states, int dimension, bool endExpected, TicTacToeState resultExpected)
        {
            var board = new Cell[dimension, dimension];
            var count = 0;

            for (int i = 0; i < dimension; i++)
            {
                for (int j = 0; j < dimension; j++)
                {
                    board[j, i] = new Cell(ParseState(states[count++]));
                }
            }

            (var isWinner, var winner) = _checker.IsGameOver(board);
            Assert.AreEqual(endExpected, isWinner);
            Assert.AreEqual(resultExpected, winner);
        }
        public void FiveStepsAwayFromMinWinning_MinTurn_MinWin(int degreeOfParallelism, ParallelismMode parallelismMode, CacheMode cacheMode)
        {
            TicTacToeState startState = new TicTacToeState(new[, ]
            {
                { Player.Empty, Player.Empty, Player.Empty },
                { Player.Empty, Player.Min, Player.Max },
                { Player.Empty, Player.Empty, Player.Empty },
            }, Player.Min);

            var engine     = GetSearchEngine(degreeOfParallelism, parallelismMode, cacheMode);
            var evaluation = engine.Search(startState, 5);

            Assert.AreEqual(TicTacToeState.MinValue, evaluation.Evaluation);
            if (cacheMode == CacheMode.NoCache)
            {
                // If we're using a cache, last moves read from the cache may not be win positions (but they will lead to one)
                var lastMove = (IDeterministicState)evaluation.StateSequence.Last();
                Assert.AreEqual(TicTacToeState.MinValue, lastMove.Evaluate(0, new List <IState>()), "Should have found a wining state");
            }
        }
Ejemplo n.º 4
0
 public Cell(TicTacToeState state)
 {
     State = state;
 }