public void Debug()
        {
            var stateInput = "...1...|..344..|.44433.|2444443|.41421.|..113..|...0...|5 2|0 3|2 1|3 5|";
            var state      = StateReader.Read(stateInput);
            var action     = new AlphaBetaAi(evaluator, 1).GetAction(state, 100);

            Assert.That(action.ToString(), Is.EqualTo("MOVE&BUILD 0 SE SW"));
        }
Пример #2
0
        public void RunCase(string input)
        {
            var state  = StateReader.Read(input);
            var ai     = new AlphabetaAi(evaluator);
            var action = ai.GetAction(state, 45);

            Console.WriteLine(action);
        }
        public void AssignValueToLastSearchTreeSizeProperty_DuringSearch(int depth, int expectedSize)
        {
            var state = StateReader.Read("002|022|200|0 0|1 0|-1 -1|-1 -1|");
            var ai    = new AlphaBetaAi(evaluator, depth);

            ai.GetAction(state, 1000);
            ai.LastSearchTreeSize.Should().Be(expectedSize);
        }
        public void AssignValueToLastDepthFullySearchedProperty_DuringSearch(int depth)
        {
            var state = StateReader.Read("00000|00000|00000|00000|00000|1 1|2 3|-1 -1|-1 -1|");
            var ai    = new AlphaBetaAi(evaluator, depth);

            ai.GetAction(state, 1000);
            ai.LastDepthFullySearched.Should().Be(depth);
        }
        public void MeasureSearchTreeSize()
        {
            var stateInput = "...2...|..303..|.13033.|0010031|.01412.|..121..|...1...|3 5|5 2|2 2|5 4|";
            var state      = StateReader.Read(stateInput);

            new AlphaBetaAi(evaluator).GetAction(state, 1); // heat up
            var ai = new AlphaBetaAi(evaluator, 3);

            ai.GetAction(state, 3000); // measure
            Console.WriteLine($"SearchTreeSize: {ai.LastSearchTreeSize}");
        }
Пример #6
0
        public void AbWithDepth1_IsSameAsGreedy(string input)
        {
            var state            = StateReader.Read(input);
            var initialStateDump = state.ToString();

            var greedyAction = new GreedyAi(evaluator).GetAction(state, 100);
            var abAction     = new AlphabetaAi(evaluator, 1).GetAction(state, 100);

            Console.WriteLine(state.ToString());
            Console.WriteLine(abAction);

            state.ToString().Should().Be(initialStateDump, "ai.GetAction should not change state");
            abAction.ToString().Should().Be(greedyAction.ToString(), "ab-ai with depth=1 should be exactly gready ai");
        }
        public void BeEquivalentToGreedy_WhenSearchDepthIs1(string input)
        {
            var state            = StateReader.Read(input);
            var initialStateDump = state.ToString();

            var greedyAction = new GreedyAi(evaluator).GetAction(state, 100);
            var abAction     = new AlphaBetaAi(evaluator, 1).GetAction(state, 100);

            Console.WriteLine(state.ToString());
            Console.WriteLine($"[{abAction}]");

            state.ToString().Should().Be(initialStateDump, "ai.GetAction should not change state");
            abAction.ToString().Should().Be(greedyAction.ToString(), "ab-ai with depth=1 should be exactly gready ai");
        }
Пример #8
0
        public void TreeSizeMeasurement()
        {
            var totalSize = new StatValue();

            foreach (var stateInput in GetStatesCollection())
            {
                var localSize = new StatValue();
                var state     = StateReader.Read(stateInput);
                var ai        = new AlphabetaAi(evaluator, 3)
                {
                    Logging = false
                };
                for (var i = 0; i < 1; i++)
                {
                    var action = ai.GetAction(state, 250);
                    localSize.Add(ai.LastSearchTreeSize);
                    action.ApplyTo(state);
                }
                Console.WriteLine(localSize.ToDetailedString());
                totalSize.AddAll(localSize);
            }
            Console.WriteLine("Total:");
            Console.WriteLine(totalSize.ToDetailedString());
        }