public void TestCompeteWorksWithProbabilisticStates()
        {
            var engine     = Connect4TestUtils.GetSearchEngine(1, ParallelismMode.FirstLevelOnly);
            var startState = new StartState(new Connect4State(Connect4TestUtils.GetEmptyBoard(), Player.Max));

            var results = engine.Compete(startState, 3, (s, d, l) => 0);

            var finalState = (ProbabilisticConnect4State)results.FinalState;

            Assert.IsTrue(BoardEvaluator.IsWin(finalState.Board, Player.Min), "Min should have won; Final state is " + Environment.NewLine + finalState);
        }
        private void BenchmarkWithDegreeOfParallelism(int degreeOfParallelism, ParallelismMode parallelismMode)
        {
            Console.WriteLine("Running with degreeOfParallelism: " + degreeOfParallelism + ", Mode: " + parallelismMode);
            var engine     = Connect4TestUtils.GetSearchEngine(degreeOfParallelism, parallelismMode);
            var startState = new StartState(new Connect4State(Connect4TestUtils.GetEmptyBoard(), Player.Max));

            var results = engine.Search(startState, 7);

            Console.WriteLine("Time: " + results.SearchTime);
            Console.WriteLine("Leaves: " + results.Leaves);
            Console.WriteLine("InternalNodes: " + results.InternalNodes);
        }
        public void MaxTwoTurnsAwayFromTwoWins_MaxGoesForTheMoreLikilyWin(int degreeOfParallelism, ParallelismMode parallelismMode)
        {
            var startState = new StartState(new Connect4State(new[, ]
            {
                { Player.Empty, Player.Empty, Player.Max, Player.Max, Player.Empty, Player.Empty },
                { Player.Empty, Player.Empty, Player.Empty, Player.Empty, Player.Empty, Player.Empty },
                { Player.Empty, Player.Empty, Player.Empty, Player.Empty, Player.Empty, Player.Empty },
                { Player.Empty, Player.Empty, Player.Empty, Player.Empty, Player.Empty, Player.Empty },
                { Player.Empty, Player.Empty, Player.Empty, Player.Empty, Player.Empty, Player.Empty },
                { Player.Empty, Player.Empty, Player.Empty, Player.Empty, Player.Empty, Player.Empty },
            }, Player.Max));

            var engine   = Connect4TestUtils.GetSearchEngine(degreeOfParallelism, parallelismMode);
            var newState = (ProbabilisticConnect4State)engine.Search(startState, 3).NextMove;

            Assert.AreEqual(Player.Max, newState.Board[0, 4], "Min didn't block the more likely win");
        }
        public void MaxHasTwoWinsNextTurn_MinBlocksTheMoreLikelyOne(int degreeOfParallelism, ParallelismMode parallelismMode)
        {
            var startState = new StartState(new Connect4State(new[, ]
            {
                { Player.Empty, Player.Max, Player.Empty, Player.Empty, Player.Max, Player.Empty },
                { Player.Empty, Player.Max, Player.Empty, Player.Empty, Player.Max, Player.Empty },
                { Player.Empty, Player.Max, Player.Empty, Player.Empty, Player.Max, Player.Empty },
                { Player.Empty, Player.Empty, Player.Empty, Player.Empty, Player.Empty, Player.Empty },
                { Player.Empty, Player.Empty, Player.Empty, Player.Empty, Player.Empty, Player.Empty },
                { Player.Empty, Player.Empty, Player.Empty, Player.Empty, Player.Empty, Player.Empty },
            }, Player.Min));

            var engine   = Connect4TestUtils.GetSearchEngine(degreeOfParallelism, parallelismMode);
            var newState = (ProbabilisticConnect4State)engine.Search(startState, 2).NextMove;

            Assert.AreEqual(Player.Min, newState.Board[3, 4], "Min didn't block the more likely win");
        }