Example #1
0
 public AgentHandler(World world, bool carnivorPercentageEnabled, bool keepTrackOfTree, int restartAtTurn, bool strictK)
 {
     this.StrictK = strictK;
     RestartAtTurn = restartAtTurn;
     random = new Random();
     this.world = world;
     this.CarnivorPercentageEnabled = carnivorPercentageEnabled;
     this.KeepTrackOfTree = keepTrackOfTree;
 }
Example #2
0
        // abort the mainloop thread and reset al parameters
        private void btn_ClearRun_Click(object sender, EventArgs e)
        {
            // abort the current mainloop thread
            threadEvent.WaitOne(5000);
            mainLoopThread.Abort();

            // reset parameter
            SimulationActive = false;
            SimulationLoaded = false;
            world = null;
            agentHandler = null;
            btn_StartSimulation.Text = "Start Simulation";
            num_WorldHeight.Enabled = true;
            num_WorldWidth.Enabled = true;
            numUD_AgentsPerKValue.Enabled = true;
            num_NValue.Enabled = true;
            lbox_KValues.Enabled = true;
            btn_ClearRun.Enabled = false;
            chbox_CarnivorPercentage.Enabled = true;
            num_RestartAfter.Enabled = true;
            chbox_strictK.Enabled = true;
        }
Example #3
0
        private void btn_StartSimulation_Click(object sender, EventArgs e)
        {
            if(!SimulationLoaded) // if the simulation hasn't been loaded yet
            {
                world = new World((int)num_WorldWidth.Value, (int)num_WorldHeight.Value); // create world instance
                agentHandler = new AgentHandler(world, chbox_CarnivorPercentage.Checked, false, (int)num_RestartAfter.Value, chbox_strictK.Checked); // create agenthandler instance

                // pass all of the initial parameters to the agenthandler
                List<int> KValues = new List<int>();
                foreach (int i in lbox_KValues.SelectedIndices)
                {
                    KValues.Add(i);
                }
                agentHandler.SetKValues(KValues);
                agentHandler.SetAgentsPerKValue((int)numUD_AgentsPerKValue.Value);
                agentHandler.setNValue((int)num_NValue.Value);

                // calculate the widht of the agents/food to be drawn
                blockWidth = (float)(glControl1.Width / num_WorldWidth.Value);
                blockHeight = (float)(glControl1.Height / num_WorldHeight.Value);

                // add an initial amount of food to the world
                world.AddFoodToWorld(6000);

                // deactive initial simulation parameter controls
                SimulationLoaded = true;
                num_WorldHeight.Enabled = false;
                num_WorldWidth.Enabled = false;
                numUD_AgentsPerKValue.Enabled = false;
                num_NValue.Enabled = false;
                lbox_KValues.Enabled = false;
                threadEvent = new AutoResetEvent(true);
                mainLoopThread = new Thread(new ThreadStart(this.MainLoop));
                mainLoopThread.IsBackground = true;
                mainLoopThread.Start();
                btn_ClearRun.Enabled = true;
                chbox_CarnivorPercentage.Enabled = false;
                num_RestartAfter.Enabled = false;
                chbox_strictK.Enabled = false;
            }
            if(SimulationActive) // pause the simulation if it was loaded and started
            {
                SimulationActive = false;
                btn_StartSimulation.Text = "Start Simulation";
            }
            else // resume the simulation if it was already loaded and paused
            {
                SimulationActive = true;
                btn_StartSimulation.Text = "Pause Simulation";
            }
        }