Exemple #1
0
        private void CompareAlgorithms(String[] input, Int32 index, Int32 depth)
        {
            IGameFactory gameFactory = new FourInARowFactory();

            FourInARowMove moveA = Common(
                input,
                new MiniMaxAlgorithmImproved(depth, gameFactory, false),
                gameFactory);

            FourInARowMove moveB = Common(
                input,
                new MiniMaxWithAlfaBetaPrunningDynamic(depth, gameFactory),
                gameFactory);

            FourInARowMove moveC = Common(
                input,
                new MiniMaxWithAlfaBetaPrunningB(depth, gameFactory),
                gameFactory);

            if (moveA.Column != moveC.Column)
            {
            }

            Assert.AreEqual(moveA.Column, moveB.Column, "Scenario failed [A] " + index + " " + depth);

            Assert.AreEqual(moveA.Column, moveC.Column, "Scenario failed [B] " + index + " " + depth);
        }
Exemple #2
0
        private static void PlayFourInARowTest()
        {
            //String[] input = new[]
            //	{
            //		"oo.o...",
            //		"x......",
            //		"x......",
            //		".......",
            //		".......",
            //		".......",
            //	};

            //String[] input = new[]
            //	{
            //		"oooxooo",
            //		"xxxoxxx",
            //		"oooxooo",
            //		"xxxoxxx",
            //		"xoxoxox",
            //		"oo.o...",
            //	};

            String[] input = new[]
            {
                "oooxooo",
                "xxxoxxx",
                "oooxooo",
                "xxxoxxx",
                "xoxoxox",
                "oo.o...",
            };

            FourInARowState state = FourInARowTests.PrepareState(input);

            FourInARowFactory factory = new FourInARowFactory();

            IGameLogic logic = factory.CreateLogic();

            MiniMaxAlgorithmImproved alg = new MiniMaxAlgorithmImproved(3, factory, true);

            PrintState((FourInARowState)state);

            Int32 res = factory.CreateStateEvaluator().Evaluate(state, GamePlayer.PlayerMax);

            IGameMove move = alg.FindBestMove(state, GamePlayer.PlayerMax);

            IGameState newState = logic.MakeMove(move, state);

            PrintState((FourInARowState)newState);
        }
Exemple #3
0
        private static void PlayFourInARow()
        {
            Console.BufferHeight = 8000;

            FourInARowFactory factory = new FourInARowFactory();

            IGameLogic logic = factory.CreateLogic();

            IGameAlgorithm alg = new MiniMaxWithAlfaBetaPrunningDynamic(3, factory); /// new MiniMaxWithAlfaBetaPrunningB(8, factory); // new MiniMaxAlgorithmImproved(6, factory, true);

            IGameState state = new FourInARowState();

            while (true)
            {
                IGameMove move = alg.FindBestMove(state, GamePlayer.PlayerMax);

                if (null != move)
                {
                    state = logic.MakeMove(move, state);
                }
                else
                {
                    break;
                }

                PrintState((FourInARowState)state);

                if (logic.IsFinished(state))
                {
                    break;
                }

                Int32 x = Int32.Parse(Console.ReadLine());

                state = logic.MakeMove(new FourInARowMove
                {
                    Column = x,
                    State  = FourInARowFieldState.Circle
                }, state);

                if (logic.IsFinished(state))
                {
                    break;
                }
            }

            PrintState((FourInARowState)state);
        }
Exemple #4
0
        public void TestMoveEvaluation()
        {
            String[] inputA = new[]
            {
                ".x.o...",
                ".x.....",
                ".......",
                ".......",
                ".......",
                "......."
            };

            String[] inputB = new[]
            {
                "...o.x.",
                ".....x.",
                ".......",
                ".......",
                ".......",
                "......."
            };

            FourInARowState stateA = PrepareState(inputA);

            FourInARowState stateB = PrepareState(inputB);

            FourInARowFactory factory = new FourInARowFactory();

            IGameStateEvaluator evaluator = factory.CreateStateEvaluator();

            Int32 rateA = evaluator.Evaluate(stateA, GamePlayer.PlayerMax);

            Int32 rateB = evaluator.Evaluate(stateB, GamePlayer.PlayerMax);

            Assert.AreEqual(rateA, rateB);

            rateA = evaluator.Evaluate(stateA, GamePlayer.PlayerMin);

            rateB = evaluator.Evaluate(stateB, GamePlayer.PlayerMin);

            Assert.AreEqual(rateA, rateB);
        }
Exemple #5
0
        public void TestWin06()
        {
            String[] input = new[]
            {
                "x.xx...",
                "..oo...",
                "...o...",
                ".......",
                ".......",
                "......."
            };

            IGameFactory gameFactory = new FourInARowFactory();

            FourInARowMove move = Common(
                input,
                new MiniMaxWithAlfaBetaPrunningDynamic(3, gameFactory),
                gameFactory);

            Assert.AreEqual(1, move.Column);
        }
Exemple #6
0
        public void TestAnotherWin()
        {
            String[] input = new[]
            {
                "oooxooo",
                "xxxoxxx",
                "oooxooo",
                "xxxoxxx",
                "xoxoxox",
                "oooooo.",
            };

            FourInARowState state = PrepareState(input);

            FourInARowFactory factory = new FourInARowFactory();

            IGameLogic logic = factory.CreateLogic();

            Boolean result = logic.IsFinished(state);

            Assert.IsTrue(result);
        }