public static bool LoadDna(string path, Robot rob) { var hold = new StringBuilder(); rob.Dna.Clear(); if (path == "") { return(false); } var lines = File.ReadAllLines(path); foreach (var a in lines) { var processedLine = a; // eliminate comments at the end of a line // but preserves comments-only lines if (a.IndexOf('\'') > 0) { processedLine = processedLine.Split("'")[0]; } processedLine = processedLine.Replace('\t', ' ').Trim(); if (processedLine.StartsWith("'") || processedLine.StartsWith("/") || string.IsNullOrEmpty(processedLine)) { if (processedLine.StartsWith("'#") || processedLine.StartsWith("/#")) { GetVals(rob, a, hold.ToString()); } } else { if (processedLine.StartsWith("def")) { DnaManipulations.InsertVar(rob, a); } else { var parts = processedLine.Split(" ", StringSplitOptions.RemoveEmptyEntries); foreach (var b in parts) { rob.Dna.Add(Parse(b, rob)); } } } hold.AppendLine(a); } rob.Dna.Add(new DnaBlock { Type = 10, Value = 1 }); return(true); }
private const double OverTime = 30; // Time correction across all mutations public static void DeleteGene(Robot rob, int g) { if (g <= 0 || g > rob.NumberOfGenes) { return; } DeleteSpecificGene(rob.Dna, g); rob.NumberOfGenes = DnaManipulations.CountGenes(rob.Dna); rob.Memory[MemoryAddresses.DnaLenSys] = rob.Dna.Count; rob.Memory[MemoryAddresses.GenesSys] = rob.NumberOfGenes; Senses.MakeOccurrList(rob); }
private void LoadRobots() { foreach (var species in SimOpt.SimOpts.Specie) { for (var t = 0; t < species.Quantity; t++) { var rob = DnaManipulations.RobScriptLoad(_robotsManager, _bucketManager, Path.Join(species.Path, species.Name)); if (rob == null) { species.Native = false; break; } species.Native = true; rob.IsVegetable = species.Veg; rob.ChloroplastsDisabled = species.NoChlr; rob.IsFixed = species.Fixed; if (rob.IsFixed) { rob.Memory[216] = 1; } rob.Position = new DoubleVector(ThreadSafeRandom.Local.Next(Robot.RobSize / 2, SimOpt.SimOpts.FieldWidth - Robot.RobSize / 2), ThreadSafeRandom.Local.Next(Robot.RobSize / 2, SimOpt.SimOpts.FieldHeight - Robot.RobSize / 2)); rob.Energy = species.Stnrg; rob.Body = 1000; rob.Memory[MemoryAddresses.SetAim] = Physics.RadiansToInt(rob.Aim * 200); if (rob.IsVegetable) { rob.Chloroplasts = SimOptions.StartChlr; } rob.IsDead = false; rob.MutationProbabilities = species.Mutables; for (var i = 0; i < 7; i++) { rob.Skin[i] = species.Skin[i]; } rob.Color = species.Color; rob.Memory[MemoryAddresses.timersys] = ThreadSafeRandom.Local.Next(-32000, 32000); rob.CantSee = species.CantSee; rob.DnaDisabled = species.DisableDna; rob.MovementSysvarsDisabled = species.DisableMovementSysvars; rob.CantReproduce = species.CantReproduce; rob.IsVirusImmune = species.VirusImmune; rob.VirusShot = null; rob.VirusTimer = 0; rob.NumberOfGenes = DnaManipulations.CountGenes(rob.Dna); rob.GenMut = (double)rob.Dna.Count / RobotsManager.GeneticSensitivity; //Botsareus 4/9/2013 automatically apply genetic to inserted robots rob.Memory[MemoryAddresses.DnaLenSys] = rob.Dna.Count; rob.Memory[MemoryAddresses.GenesSys] = rob.NumberOfGenes; } } }
private static void aggiungirob(IRobotManager robotManager, IBucketManager bucketManager) { if (!SimOpt.SimOpts.Specie.Any(s => CheckVegStatus(robotManager, s))) { return; } int r; do { r = ThreadSafeRandom.Local.Next(0, SimOpt.SimOpts.Specie.Count); // start randomly in the list of species } while (!CheckVegStatus(robotManager, SimOpt.SimOpts.Specie[r])); var x = ThreadSafeRandom.Local.Next(Robot.RobSize / 2, SimOpt.SimOpts.FieldWidth - Robot.RobSize / 2); var y = ThreadSafeRandom.Local.Next(Robot.RobSize / 2, SimOpt.SimOpts.FieldHeight - Robot.RobSize / 2); if (SimOpt.SimOpts.Specie[r].Name == "" || SimOpt.SimOpts.Specie[r].Path == "Invalid Path") { return; } var a = DnaManipulations.RobScriptLoad(robotManager, bucketManager, System.IO.Path.Join(SimOpt.SimOpts.Specie[r].Path, SimOpt.SimOpts.Specie[r].Name)); if (a == null) { SimOpt.SimOpts.Specie[r].Native = false; return; } //Check to see if we were able to load the bot. If we can't, the path may be wrong, the sim may have //come from another machine with a different install path. Set the species path to an empty string to //prevent endless looping of error dialogs. if (!a.Exists) { SimOpt.SimOpts.Specie[r].Path = "Invalid Path"; return; } a.IsVegetable = SimOpt.SimOpts.Specie[r].Veg; if (a.IsVegetable) { a.Chloroplasts = SimOptions.StartChlr; } a.IsFixed = SimOpt.SimOpts.Specie[r].Fixed; a.CantSee = SimOpt.SimOpts.Specie[r].CantSee; a.DnaDisabled = SimOpt.SimOpts.Specie[r].DisableDna; a.MovementSysvarsDisabled = SimOpt.SimOpts.Specie[r].DisableMovementSysvars; a.CantReproduce = SimOpt.SimOpts.Specie[r].CantReproduce; a.IsVirusImmune = SimOpt.SimOpts.Specie[r].VirusImmune; a.IsCorpse = false; a.IsDead = false; a.Body = 1000; a.Mutations = 0; a.OldMutations = 0; a.LastMutation = 0; a.SonNumber = 0; a.Parent = null; Array.Clear(a.Memory, 0, a.Memory.Length); if (a.IsFixed) { a.Memory[216] = 1; } a.Position = new DoubleVector(x, y); a.Aim = ThreadSafeRandom.Local.NextDouble() * Math.PI * 2; a.Memory[MemoryAddresses.SetAim] = (int)a.Aim * 200; //Bot is already in a bucket due to the prepare routine bucketManager.UpdateBotBucket(a); a.Energy = SimOpt.SimOpts.Specie[r].Stnrg; a.MutationProbabilities = SimOpt.SimOpts.Specie[r].Mutables; a.VirusTimer = 0; a.VirusShot = null; a.NumberOfGenes = DnaManipulations.CountGenes(a.Dna); a.GenMut = (double)a.Dna.Count / RobotsManager.GeneticSensitivity; a.Memory[MemoryAddresses.DnaLenSys] = a.Dna.Count; a.Memory[MemoryAddresses.GenesSys] = a.NumberOfGenes; a.ChloroplastsDisabled = SimOpt.SimOpts.Specie[r].NoChlr; for (var i = 0; i < 7; i++) { a.Skin[i] = SimOpt.SimOpts.Specie[r].Skin[i]; } a.Color = SimOpt.SimOpts.Specie[r].Color; Senses.MakeOccurrList(a); }