private Solution(Solution original, Cloner cloner) : base(original, cloner) { Tree = cloner.Clone(original.Tree); Path = (string)original.Path.Clone(); NrOfRounds = original.NrOfRounds; Enemies = cloner.Clone(original.Enemies); }
public Solution(ISymbolicExpressionTree tree, string path, int nrOfRounds, EnemyCollection enemies) : base() { this.Tree = tree; this.Path = path; this.NrOfRounds = nrOfRounds; this.Enemies = enemies; }
public BattleRunnerDialog(Solution solution) { InitializeComponent(); errorProvider.SetIconAlignment(robocodePathTextBox, ErrorIconAlignment.MiddleLeft); errorProvider.SetIconPadding(robocodePathTextBox, 2); nrOfRoundsNumericUpDown.Maximum = int.MaxValue; NrOfRounds = solution.NrOfRounds; Enemies = (EnemyCollection)solution.Enemies.Clone(new Cloner()); robocodePathTextBox.Text = Enemies.RobocodePath; }
public Profile() { Name = ""; Description = ""; NormalWayPoints = new WayPointCollection(); GhostWayPoints = new WayPointCollection(); VendorWayPoints = new WayPointCollection(); RepairWayPoints = new WayPointCollection(); BranchWayPoints = new WayPointCollection(); Enemies = new EnemyCollection(); }
private void AssignThreeOrbs() { var wingsBossId = BossOrbTierList.TieredBossIds[0][Agent.Rng.Next(0, BossOrbTierList.TieredBossIds[0].Count)]; WingsArea = BossOrbTierList.IdToAreaName[wingsBossId]; var armsBossId = BossOrbTierList.TieredBossIds[1][Agent.Rng.Next(0, BossOrbTierList.TieredBossIds[1].Count)]; ArmsArea = BossOrbTierList.IdToAreaName[armsBossId]; var fakeEyeBossId = BossOrbTierList.TieredBossIds[2][Agent.Rng.Next(0, BossOrbTierList.TieredBossIds[2].Count)]; FakeEyeArea = BossOrbTierList.IdToAreaName[fakeEyeBossId]; RealEyeArea = FakeEyeArea; var realEyeBossId = 0; while (RealEyeArea.Equals(FakeEyeArea)) { realEyeBossId = BossOrbTierList.TieredBossIds[2][Agent.Rng.Next(0, BossOrbTierList.TieredBossIds[2].Count)]; RealEyeArea = BossOrbTierList.IdToAreaName[realEyeBossId]; } var wingsBoss = EnemyCollection.GetMappedObject(wingsBossId); wingsBoss.DropId = Wings; wingsBoss.DropRate = 100; var armsBoss = EnemyCollection.GetMappedObject(armsBossId); armsBoss.DropId = Arms; armsBoss.DropRate = 100; var fakeEyeBoss = EnemyCollection.GetMappedObject(fakeEyeBossId); fakeEyeBoss.DropId = FakeEye; fakeEyeBoss.DropRate = 100; var realEyeBoss = EnemyCollection.GetMappedObject(realEyeBossId); realEyeBoss.DropId = RealEye; realEyeBoss.DropRate = 100; }
private void ScaleEnemies(int oldTier, int newTier, int oldBossId, int newBossId) { if (newTier == oldTier) { return; } var oldBoss = EnemyCollection.GetMappedObject(oldBossId); var newBoss = EnemyCollection.GetMappedObject(newBossId); if (oldTier > newTier) { ScaleDownEnemy(oldBoss, newTier, oldTier); ScaleUpEnemy(newBoss, newTier, oldTier); } else { ScaleUpEnemy(oldBoss, oldTier, newTier); ScaleDownEnemy(newBoss, oldTier, newTier); } EnemyTierList.SwapTiers(oldBossId, newBossId); }
public void ApplySparsityMode() { //Modify Shopping Lists to have no healing items RemoveHealingItemsFromShoppingLists(); //Repopulate Found Items with more healing items PopulateEventsWithNewItems(); //Increase rate of berry drops for enemies IncreaseEnemiesHealDropRate(); //sets ambrosia and nectar to fully heal MP as well as HP var nectar = ItemCollection.GetMappedObject(NectarId); nectar.Vitality = 999; var ambrosia = ItemCollection.GetMappedObject(AmbrosiaId); ambrosia.Vitality = 999; //commit all changes ItemCollection.WriteObjects(Agent.GeneralConfiguration.TempFile); AreaCollection.WriteObjects(Agent.GeneralConfiguration.TempFile); EnemyCollection.WriteObjects(Agent.GeneralConfiguration.TempFile); }
public void ItIteratesThroughtCollection() { var collection = new EnemyCollection { [0] = new EasyEnemy(), [1] = new MediumEnemy(), [2] = new HardEnemy() }; var iterator = collection.CreateIterator(); var total = 0; for (var enemy = iterator.First(); !iterator.Done(); enemy = iterator.Next()) { total++; } Assert.IsType<EnemyCollection>(collection); Assert.Equal(3, total); }
// TODO performance: it would probably be useful to implement the BattleRunner in such a way that we don't have to restart the java process each time, e.g. using console IO to load & run robots public static double EvaluateTankProgram(ISymbolicExpressionTree tree, string path, EnemyCollection enemies, string robotName = null, bool showUI = false, int nrOfRounds = 3) { if (robotName == null) robotName = GenerateRobotName(); string interpretedProgram = InterpretProgramTree(tree.Root, robotName); string battleRunnerPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "robocode"); string roboCodeLibPath = Path.Combine(path, "libs"); string robocodeJar = Path.Combine(roboCodeLibPath, "robocode.jar"); string robocodeCoreJar = GetFileName(roboCodeLibPath, "robocode.core*"); string picocontainerJar = GetFileName(roboCodeLibPath, "picocontainer*"); string robotsPath = Path.Combine(path, "robots", "Evaluation"); string srcRobotPath = Path.Combine(robotsPath, robotName + ".java"); File.WriteAllText(srcRobotPath, interpretedProgram, System.Text.Encoding.Default); // compile java source to class file ProcessStartInfo javaCompileInfo = new ProcessStartInfo(); javaCompileInfo.FileName = "cmd.exe"; javaCompileInfo.Arguments = "/C javac -cp " + robocodeJar + "; " + srcRobotPath; javaCompileInfo.RedirectStandardOutput = true; javaCompileInfo.RedirectStandardError = true; javaCompileInfo.UseShellExecute = false; javaCompileInfo.CreateNoWindow = true; // it's ok to compile multiple robocode programs concurrently using (Process javaCompile = new Process()) { javaCompile.StartInfo = javaCompileInfo; javaCompile.Start(); string cmdOutput = javaCompile.StandardOutput.ReadToEnd(); cmdOutput += javaCompile.StandardError.ReadToEnd(); javaCompile.WaitForExit(); if (javaCompile.ExitCode != 0) { DeleteRobotFiles(path, robotName); throw new Exception("Compile Error: " + cmdOutput); } } ProcessStartInfo evaluateCodeInfo = new ProcessStartInfo(); // execute a battle with numberOfRounds against a number of enemies // TODO: seems there is a bug when selecting multiple enemies evaluateCodeInfo.FileName = "cmd.exe"; var classpath = string.Join(";", new[] { battleRunnerPath, robocodeCoreJar, robocodeJar, picocontainerJar }); var enemyRobotNames = string.Join(" ", enemies.CheckedItems.Select(i => i.Value)); evaluateCodeInfo.Arguments = string.Format("/C java -cp {0} BattleRunner Evaluation.{1} {2} {3} {4} {5}", classpath, robotName, path, showUI, nrOfRounds, enemyRobotNames); evaluateCodeInfo.RedirectStandardOutput = true; evaluateCodeInfo.RedirectStandardError = true; evaluateCodeInfo.UseShellExecute = false; evaluateCodeInfo.CreateNoWindow = true; // the robocode framework writes state to a file therefore parallel evaluation of multiple robocode programs is not possible yet. double evaluation; lock (syncRoot) { using (Process evaluateCode = new Process()) { evaluateCode.StartInfo = evaluateCodeInfo; evaluateCode.Start(); evaluateCode.WaitForExit(); if (evaluateCode.ExitCode != 0) { DeleteRobotFiles(path, robotName); throw new Exception("Error running Robocode: " + evaluateCode.StandardError.ReadToEnd() + Environment.NewLine + evaluateCode.StandardOutput.ReadToEnd()); } try { string scoreString = evaluateCode.StandardOutput.ReadToEnd() .Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries) .Last(); evaluation = Double.Parse(scoreString, CultureInfo.InvariantCulture); } catch (Exception ex) { throw new Exception("Error parsing score string: " + ex); } finally { DeleteRobotFiles(path, robotName); } } } return evaluation; }
private void AssignItemDrops() { foreach (var id in BossOrbTierList.TieredBossIds[0]) { var boss = EnemyCollection.GetMappedObject(id); if (boss.DropId == Wings) { continue; } var potentialItemIds = new List <int>(); potentialItemIds.AddRange(ItemTierList.TieredItemList[5]); potentialItemIds.AddRange(ItemTierList.TieredItemList[6]); potentialItemIds.AddRange(ItemTierList.TieredItemList[7]); var item = ItemCollection.GetMappedObject(0); while (item.EquipSlot == ItemMasks.EquipSlot.None) { item = ItemCollection.GetMappedObject(potentialItemIds[Agent.Rng.Next(0, potentialItemIds.Count)]); } boss.DropId = (byte)item.Id; boss.DropRate = 100; } foreach (var id in BossOrbTierList.TieredBossIds[1]) { var boss = EnemyCollection.GetMappedObject(id); if (boss.DropId == Arms) { continue; } var potentialItemIds = new List <int>(); potentialItemIds.AddRange(ItemTierList.TieredItemList[8]); potentialItemIds.AddRange(ItemTierList.TieredItemList[9]); potentialItemIds.AddRange(ItemTierList.TieredItemList[10]); var item = ItemCollection.GetMappedObject(0); while (item.EquipSlot == ItemMasks.EquipSlot.None) { item = ItemCollection.GetMappedObject(potentialItemIds[Agent.Rng.Next(0, potentialItemIds.Count)]); } boss.DropId = (byte)item.Id; boss.DropRate = 100; } foreach (var id in BossOrbTierList.TieredBossIds[2]) { var boss = EnemyCollection.GetMappedObject(id); if (boss.DropId == RealEye || boss.DropId == FakeEye) { continue; } var potentialItemIds = new List <int>(); potentialItemIds.AddRange(ItemTierList.TieredItemList[11]); potentialItemIds.AddRange(ItemTierList.TieredItemList[12]); potentialItemIds.AddRange(ItemTierList.TieredItemList[13]); potentialItemIds.AddRange(ItemTierList.TieredItemList[14]); var item = ItemCollection.GetMappedObject(0); while (item.EquipSlot == ItemMasks.EquipSlot.None) { item = ItemCollection.GetMappedObject(potentialItemIds[Agent.Rng.Next(0, potentialItemIds.Count)]); } boss.DropId = (byte)item.Id; boss.DropRate = 100; } }
public void ShuffleBossOrder() { var toSwap = new List <Tuple <int, int> >(); var swapped = new HashSet <int>(); foreach (var bossId in EnemyTierList.BossIds) { //determine new tier rank var swapBossId = bossId; byte newTier = 0; byte originalTier = 0; while (swapBossId == bossId) { originalTier = EnemyTierList.GetBossTier(bossId); newTier = RandomFunctions.GenerateGaussianByte(Agent.Rng, originalTier, Agent.Probabilities.BossShuffleStandardDeviation, (byte)(EnemyTierList.TieredBossIds.Count - 1)); if (newTier < 0) { newTier = 0; } //determine what boss to swap with based on new rank var randNum = Agent.Rng.Next(0, EnemyTierList.TieredBossIds[newTier].Count); swapBossId = EnemyTierList.TieredBossIds[newTier][randNum]; } swapped.Add(bossId); swapped.Add(swapBossId); ScaleEnemies(originalTier, newTier, bossId, swapBossId); toSwap.Add(new Tuple <int, int>(bossId, swapBossId)); } EnemyCollection.WriteObjects(Agent.GeneralConfiguration.TempFile); foreach (var t in toSwap) { EnemyCollection.SwapMappedObjects(Agent.GeneralConfiguration.TempFile, EnemyCollection.GetMappedObject(t.Item1), EnemyCollection.GetMappedObject(t.Item2)); } /* * foreach (var t in toSwap) * { * var bossA = EnemyCollection.GetMappedObject(t.Item1); * var bossB = EnemyCollection.GetMappedObject(t.Item2); * bossA.WriteByte((byte)t.Item2, EnemyOffsets.Id); * bossB.WriteByte((byte)t.Item1, EnemyOffsets.Id); * }*/ }