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]); }
/// <summary> /// Gets calles when a paint event triggers, and renders all of the on screen elements using /// the graphics objects passed in. /// </summary> /// /// <param name="sender"></param> /// <param name="e"></param> private void GameForm_Paint(object sender, PaintEventArgs e) { world.Update(); world.Render(e.Graphics); GameUpdater.Update(); showWinnerIfWinner(); startButton.Update(); IntroButton.Update(); AcceptedInputsButton.Update(); SimpleScriptExampleButton.Update(); PlayerInputTexBox.Update(); WinnerTextBox.Update(); System.Threading.Thread.Sleep(16); gamePanel.Invalidate(); }