Example #1
0
        public void EvenlyDistributeTheSelectedMoves_3Options()
        {
            const int executionCount = 100000;

            var rnd = new System.Random();

            var target   = new Engine();
            var expected = new int[] { 0, 1, 2 };
            var s        = new int[] { 0, 0, 0 };

            var situation = new Entities.GameSituation()
            {
                LegalMoves = expected
            };

            for (int i = 0; i < executionCount; i++)
            {
                var actual = target.GetMove(situation);
                s[actual]++;
            }

            int maxExecutions = (int)(executionCount * 0.4);

            for (int i = 0; i < s.Length; i++)
            {
                Assert.IsTrue(s[i] <= maxExecutions);
            }
        }
Example #2
0
        public void LoadBestPathDNA()
        {
            this.DNA = new Chromosome[_dnaStrandLength];
            var shortestPathStrategy = new ChutesAndLadders.Strategy.ShortestPath.Engine();

            var board = new Entities.GameBoard();
            int index = 0;

            for (int startingPoint = 0; startingPoint < 100; startingPoint++)
            {
                for (byte spin = 1; spin <= 6; spin++)
                {
                    var legalEndpoints = board.GetLegalEndpoints(startingPoint, spin);
                    if ((legalEndpoints.Count() > 1) && (!legalEndpoints.Contains(100)))
                    {
                        var situation = new Entities.GameSituation()
                        {
                            BoardLocation = startingPoint, Spin = spin, LegalMoves = legalEndpoints, PlayerLocations = new int[] { }
                        };
                        var selectedEndpoint = shortestPathStrategy.GetMove(situation);

                        this.DNA[index] = new Chromosome(startingPoint, spin, legalEndpoints, selectedEndpoint);
                        index++;
                    }
                }
            }

            LoadRulesFromDNA();
        }
Example #3
0
        public void ReturnOneOfTheValidMoves()
        {
            var rnd = new System.Random();

            var target   = new Engine();
            var expected = new int[] { rnd.Next(99), rnd.Next(99), rnd.Next(99) };

            var situation = new Entities.GameSituation()
            {
                LegalMoves = expected
            };
            var actual = target.GetMove(situation);

            Assert.IsTrue(expected.Contains(actual));
        }
Example #4
0
        public void SelectAllOfTheValidMovesIfExecutedEnoughTimes()
        {
            var rnd = new System.Random();

            var target   = new Engine();
            var expected = new int[] { 0, 1, 2 };
            var s        = new bool[] { false, false, false };

            var situation = new Entities.GameSituation()
            {
                LegalMoves = expected
            };

            while (!s[0] || !s[1] || !s[2])
            {
                var actual = target.GetMove(situation);
                s[actual] = true;
            }
        }