Exemplo n.º 1
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();
        }
Exemplo n.º 2
0
        public void LoadLinearDNA()
        {
            this.DNA = new Chromosome[_dnaStrandLength];

            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)))
                    {
                        int selectedEndpoint = startingPoint + spin;
                        if (!legalEndpoints.Contains(selectedEndpoint))
                        {
                            selectedEndpoint = legalEndpoints.ClosestTo(selectedEndpoint);
                        }

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

            LoadRulesFromDNA();
        }
Exemplo n.º 3
0
        private void Load()
        {
            var board = new Entities.GameBoard();

            for (int startingPoint = 0; startingPoint < 100; startingPoint++)
            {
                for (byte spin = 1; spin <= 6; spin++)
                {
                    var legalEndpoints = board.GetLegalEndpoints(startingPoint, spin);
                    if (legalEndpoints.Count() > 1)
                    {
                        // Capture variables for lambda
                        int    sPoint       = startingPoint;
                        int    sValue       = spin;
                        int    bestEndpoint = legalEndpoints.Max();
                        string name         = $"Start:{sPoint} Spin:{sValue} End:{bestEndpoint}";
                        Func <int, byte, bool> conditionsFunction = (st, sp) => { return(st == sPoint && sp == sValue); };
                        Func <int, byte, int>  resultsFunction    = (st, sp) => { return(bestEndpoint); };
                        base.AddRule(name, conditionsFunction, resultsFunction);
                    }
                }
            }
        }
Exemplo n.º 4
0
        public void LoadRandomDNA()
        {
            this.DNA = new Chromosome[_dnaStrandLength];

            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)))
                    {
                        int selectedEndpoint = legalEndpoints.GetRandom();
                        System.Diagnostics.Debug.Assert(legalEndpoints.Contains(selectedEndpoint));
                        this.DNA[index] = new Chromosome(startingPoint, spin, legalEndpoints, selectedEndpoint);
                        index++;
                    }
                }
            }

            LoadRulesFromDNA();
        }