Ejemplo n.º 1
0
        public void TestProvided_ADLreturned()
        {
            var expected  = "adl";
            var evaluator = new TestCase1.Evaluator();
            var generator = new TestCase1.Generator();
            var applier   = new TestCase1.Applier();
            var algorithm = new MinimaxAverageAlgorithm <TestCase1.State, TestCase1.Move>(evaluator, generator, applier)
            {
                MaxDepth             = int.MaxValue,
                MinLevelAverageDepth = 2,
                MaxLevelAverageDepth = 2
            };
            var sb = new StringBuilder();

            var state = new TestCase1.State(1, 0);
            var move  = algorithm.Calculate(state);

            sb.Append(move.Label);

            state = applier.Apply(state, move);
            move  = algorithm.Calculate(state);
            sb.Append(move.Label);

            state = applier.Apply(state, move);
            move  = algorithm.Calculate(state);
            sb.Append(move.Label);

            var actual = sb.ToString();

            Assert.Equal(expected, actual);
        }
Ejemplo n.º 2
0
        public void TestProvided_BENreturned()
        {
            var expected  = "ben";
            var evaluator = new TestCase1.Evaluator();
            var generator = new TestCase1.Generator();
            var applier   = new TestCase1.Applier();
            var algorithm = new AlphaBetaAlgorithm <TestCase1.State, TestCase1.Move>(evaluator, generator, applier);

            algorithm.MaxDepth = int.MaxValue;
            var sb = new StringBuilder();

            var state = new TestCase1.State(1, 0);
            var move  = algorithm.Calculate(state);

            sb.Append(move.Label);

            state = applier.Apply(state, move);
            move  = algorithm.Calculate(state);
            sb.Append(move.Label);

            state = applier.Apply(state, move);
            move  = algorithm.Calculate(state);
            sb.Append(move.Label);

            var actual = sb.ToString();

            Assert.Equal(expected, actual);
        }
Ejemplo n.º 3
0
        public void MaxLevel1(int depth)
        {
            var evaluator = new TestCase1.Evaluator();
            var generator = new TestCase1.Generator();
            var applier   = new TestCase1.Applier();

            var algorithm1 = new MinimaxAlgorithm <TestCase1.State, TestCase1.Move>(evaluator, generator, applier)
            {
                MaxDepth = depth
            };
            var algorithm2 = new MinimaxAverageAlgorithm <TestCase1.State, TestCase1.Move>(evaluator, generator, applier)
            {
                MaxDepth             = depth,
                MaxLevelAverageDepth = 1,
                MinLevelAverageDepth = 1
            };
            var algorithm3 = new AlphaBetaAlgorithm <TestCase1.State, TestCase1.Move>(evaluator, generator, applier)
            {
                MaxDepth = 1
            };

            var state = new TestCase1.State(0, 0);

            var move1 = algorithm1.Calculate(state);
            var move2 = algorithm2.Calculate(state);
            var move3 = algorithm3.Calculate(state);

            Assert.Equal(move1, move2);
            Assert.Equal(move2, move3);
            Assert.Equal(move3, move1);
        }
Ejemplo n.º 4
0
        public void RandomAlgorithm_ReturnsMove()
        {
            var generator = new TestCase1.Generator();
            var applier   = new TestCase1.Applier();
            var algorithm = new RandomAlgorithm <TestCase1.State, TestCase1.Move>(generator);

            var initState = new TestCase1.State(1, 0);
            var move1     = algorithm.Calculate(initState);

            var state2 = applier.Apply(initState, move1);
            var move2  = algorithm.Calculate(state2);

            Assert.NotNull(move1);
            Assert.NotNull(move2);
        }
Ejemplo n.º 5
0
        public void Test1()
        {
            var evaluator = new TestCase1.Evaluator();
            var generator = new TestCase1.Generator();
            var applier   = new TestCase1.Applier();
            var algorithm = new GreedyAlgorithm <TestCase1.State, TestCase1.Move>(evaluator, generator, applier);

            var initState = new TestCase1.State(1, int.MinValue);

            var move1  = algorithm.Calculate(initState);
            var state2 = applier.Apply(initState, move1);
            var move2  = algorithm.Calculate(state2);

            Assert.Equal('a', move1.Label);
            Assert.Equal('c', move2.Label);
        }