/// <summary> /// Initializes Form and bots /// </summary> public GameplayForm() { world = new World(new Bot(new PointF(50, 300), 0.0f, new Renderable(new List <PointF>(), true)), new Bot(new PointF(350, 200), (float)Math.PI, new Renderable(new List <PointF>(), true))); GameUpdater = new GameplayUpdater(world); InitializeComponent(); ResizePanels(); }
public string[] SimulateFights(int generations) { World fakeWorld = new World(new Bot(new PointF(50, 300), 0.0f, new Renderable(new List <PointF>(), true)), new Bot(new PointF(350, 200), (float)Math.PI, new Renderable(new List <PointF>(), true))); GameplayUpdater updater = new GameplayUpdater(fakeWorld); fakeWorld.setPlayerCode(PlayerInputTexBox.Lines); // init population List <BotScript> population = new List <BotScript>(); for (int i = 0; i < 10; i++) { population.Add(new BotScript(Bot.allVariables, Bot.outputVariables, Bot.operators, 25)); } while (generations-- > 0) { List <Result> result = new List <Result>(); foreach (BotScript script in population) { updater.Reset(); Random random = new Random(); if (random.NextDouble() < 0.5) { fakeWorld.setComputerCode(new String[0]); } else { fakeWorld.setComputerCode(new String[] { "control.forward = true" }); } //fakeWorld.setComputerCode(script.getLines()); for (int i = 0; i < 600; i++) { updater.Update(); if (updater.winner != "") { break; } } result.Add(new Result(updater.score.enemyScore, script)); } result.Sort((left, right) => left.score > right.score ? 1 : -1); PlayerInputTexBox.Text = (result[0].score.ToString() + " to " + result[result.Count - 1].score.ToString()); } return(new String[0]); }