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(); }
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(); }
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); } } } }
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(); }