//handles key press event...e.g. normal keys (alphabetical etc.)
        private void KeyPressHandler(object sender, System.Windows.Forms.KeyPressEventArgs e)
		{
			if (e.KeyChar == 'p' || e.KeyChar == 'P')
			{
				       if (selected_wall != null) {
             				Console.WriteLine(selected_wall.line.p1.x+" "+selected_wall.line.p1.y);
							Console.WriteLine("to");
		          			Console.WriteLine(selected_wall.line.p2.x+" "+selected_wall.line.p2.y);
					}
			}
            if (e.KeyChar == 'W' || e.KeyChar == 'w')
            {
                wallAdder adder = new wallAdder();
                adder.Show(this);
            }

            if (e.KeyChar == 'R' || e.KeyChar == 'r')
            {
                experiment.running = !experiment.running;
                setRunningState();
            }
            if (e.KeyChar == 'L' || e.KeyChar == 'l')
                this.bDrawLabel = !this.bDrawLabel;

            if (e.KeyChar == 'N' || e.KeyChar == 'n')
            {
                if (drawMode == drawModes.selectMode && selected_robot != null)
                {
                    NetworkVisualizerForm netForm=null;
                    if (experiment is MultiAgentExperiment) //if this is a multiagentexperiment use agentBrain class
                    {
                        // Schrum: With preference neurons, all brains need to be displayed
                        if (experiment.preferenceNeurons)
                        {
                            for (int i = 0; i < experiment.agentBrain.numBrains; i++)
                            {
                                experiment.agentBrain.switchBrains(i); // Schrum: Select the right brain
                                INetwork brain = experiment.agentBrain.getBrain(selected_robot.id);
                                int brainCounter = experiment.agentBrain.getBrainCounter(); // Schrum: Added to know which brain is being used
                                bool checkZ = experiment.robots.Count > 1;
                                if (brain == null) return; //TODO maybe show dialog
                                netForm = new NetworkVisualizerForm(selected_robot, (ModularNetwork)brain, brainCounter, checkZ); // Schrum: Know which brain is being used
                                netForm.genomeVisualizerForm = genomeVisualizerForm;                               
                                netForm.Show();

                                // Schrum: Make layout/organization of multiple brains better
                                // These are custom layouts for different numbers of brains.
                                int hspacing;
                                int vspacing;

                                if (experiment.mmdRate > 0 || experiment.mmpRate > 0 || experiment.mmrRate > 0)
                                {
                                    if (experiment.agentBrain.numBrains > 10)
                                    {
                                        netForm.Width = 130;
                                        netForm.Height = 130;
                                        hspacing = -20;
                                        vspacing = +170;
                                    }
                                    else
                                    {
                                        netForm.Width = 170;
                                        netForm.Height = 170;
                                        hspacing = -20;
                                        vspacing = +40;
                                    }
                                }
                                else
                                { // Schrum: these settings work well for up to about 5 brains
                                    netForm.Width = 200;
                                    netForm.Height = 200;
                                    hspacing = -25;
                                    vspacing = +40;
                                }
                                netForm.SetDesktopLocation((i%10) * (netForm.Width + hspacing), selected_robot.id * (netForm.Height + vspacing) + (i >= 10 ? 120 : 0));
                            }
                            return; // Schrum: need to break normal execution flow to avoid netForm being shown again
                        }
                        else // Schrum: Original code
                        {
                            INetwork brain = experiment.agentBrain.getBrain(selected_robot.id);
                            int brainCounter = experiment.agentBrain.getBrainCounter(); // Schrum: Added to know which brain is being used
                            bool checkZ = experiment.robots.Count > 1;
                            if (brain == null)
                            {
                                Console.WriteLine("NULL Brain!");
                                return; //TODO maybe show dialog
                            }
                            netForm = new NetworkVisualizerForm(selected_robot, (ModularNetwork)brain, brainCounter,checkZ); // Schrum: Know which brain is being used
                        }
                    }
                    else 
                    {
                      //  TODO test with non MultiAgentExperiment
                        if (experiment.agentBrain.brain == null) return;
                        int brainCounter = experiment.agentBrain.getBrainCounter(); // Schrum: Added to know which brain is being used
                        bool checkZ = experiment.robots.Count > 1;
                        netForm = new NetworkVisualizerForm(selected_robot, (ModularNetwork)experiment.agentBrain.brain, brainCounter, checkZ); // Schrum: Know which brain is being used
                    }

                    netForm.genomeVisualizerForm = genomeVisualizerForm;
                    netForm.Show();
                  
                   // this.selected_robot.displayPath = !this.selected_robot.displayPath;
                }
            }

            // Schrum: Track mode/brain usage
            if (e.KeyChar == 'U' || e.KeyChar == 'u')
            {
                if (drawMode == drawModes.selectMode && selected_robot != null && selected_robot.brainHistory != null)
                {
                    INetwork brain = experiment.agentBrain.getBrain(selected_robot.id);
                    ModuleUsageVisualizerForm usageForm = new ModuleUsageVisualizerForm(selected_robot, (ModularNetwork)brain, experiment.evaluationTime);
                    usageForm.Show();

                    // Schrum: Custom displays for certain number of brains
                    usageForm.Width = experiment.agentBrain.numBrains * (200 - 25);
                }
            }

            if (e.KeyChar == '+' || e.KeyChar == '=')
            {
                animation.Interval += 5;
            }
            if (e.KeyChar == '-')
            {
                if (animation.Interval - 5 <= 0) {
                    animation.Interval = 1;
					frameskip++;
				}
                else
                    animation.Interval -= 5;
                //if (experiment.timestep <= 0.0f)
                //if(animation.Interval<=0)
				// animation.Interval = 3;
            }
            Invalidate();
        }
        //handles key press event...e.g. normal keys (alphabetical etc.)
        private void KeyPressHandler(object sender, System.Windows.Forms.KeyPressEventArgs e)
		{
			if (e.KeyChar == 'p' || e.KeyChar == 'P')
			{
				       if (selected_wall != null) {
             				Console.WriteLine(selected_wall.line.p1.x+" "+selected_wall.line.p1.y);
							Console.WriteLine("to");
		          			Console.WriteLine(selected_wall.line.p2.x+" "+selected_wall.line.p2.y);
					}
			}
            if (e.KeyChar == 'W' || e.KeyChar == 'w')
            {
                wallAdder adder = new wallAdder();
                adder.Show(this);
            }

            if (e.KeyChar == 'R' || e.KeyChar == 'r')
            {
                experiment.running = !experiment.running;
                setRunningState();
            }
            if (e.KeyChar == 'L' || e.KeyChar == 'l')
                this.bDrawLabel = !this.bDrawLabel;

            if (e.KeyChar == 'N' || e.KeyChar == 'n')
            {
                if (drawMode == drawModes.selectMode && selected_robot != null)
                {
                    NetworkVisualizerForm netForm=null;
                    if (experiment is MultiAgentExperiment) //if this is a multiagentexperiment use agentBrain class
                    {
                        // Schrum: With preference neurons, all brains need to be displayed
                        if (experiment.preferenceNeurons)
                        {
                            for (int i = 0; i < experiment.agentBrain.numBrains; i++)
                            {
                                experiment.agentBrain.switchBrains(i); // Schrum: Select the right brain
                                INetwork brain = experiment.agentBrain.getBrain(selected_robot.id);
                                int brainCounter = experiment.agentBrain.getBrainCounter(); // Schrum: Added to know which brain is being used
                                bool checkZ = experiment.robots.Count > 1;
                                if (brain == null) return; //TODO maybe show dialog
                                netForm = new NetworkVisualizerForm(selected_robot, (ModularNetwork)brain, brainCounter, checkZ); // Schrum: Know which brain is being used
                                netForm.genomeVisualizerForm = genomeVisualizerForm; 
                                netForm.Show();
                            }
                            return; // Schrum: need to break normal execution flow to avoid netForm being shown again
                        }
                        else // Schrum: Original code
                        {
                            INetwork brain = experiment.agentBrain.getBrain(selected_robot.id);
                            int brainCounter = experiment.agentBrain.getBrainCounter(); // Schrum: Added to know which brain is being used
                            bool checkZ = experiment.robots.Count > 1;
                            if (brain == null)
                            {
                                Console.WriteLine("NULL Brain!");
                                return; //TODO maybe show dialog
                            }
                            netForm = new NetworkVisualizerForm(selected_robot, (ModularNetwork)brain, brainCounter,checkZ); // Schrum: Know which brain is being used
                        }
                    }
                    else 
                    {
                      //  TODO test with non MultiAgentExperiment
                        if (experiment.agentBrain.brain == null) return;
                        int brainCounter = experiment.agentBrain.getBrainCounter(); // Schrum: Added to know which brain is being used
                        bool checkZ = experiment.robots.Count > 1;
                        netForm = new NetworkVisualizerForm(selected_robot, (ModularNetwork)experiment.agentBrain.brain, brainCounter, checkZ); // Schrum: Know which brain is being used
                    }

                    netForm.genomeVisualizerForm = genomeVisualizerForm;
                    netForm.Show();
                  
                   // this.selected_robot.displayPath = !this.selected_robot.displayPath;
                }
            }

            // Schrum: Track mode/brain usage
            if (e.KeyChar == 'U' || e.KeyChar == 'u')
            {
                if (drawMode == drawModes.selectMode && selected_robot != null && selected_robot.brainHistory != null)
                {
                    INetwork brain = experiment.agentBrain.getBrain(selected_robot.id);
                    ModuleUsageVisualizerForm usageForm = new ModuleUsageVisualizerForm(selected_robot, (ModularNetwork)brain, experiment.evaluationTime);
                    usageForm.Show();
                }
            }

            if (e.KeyChar == '+' || e.KeyChar == '=')
            {
                animation.Interval += 5;
            }
            if (e.KeyChar == '-')
            {
                if (animation.Interval - 5 <= 0) {
                    animation.Interval = 1;
					frameskip++;
				}
                else
                    animation.Interval -= 5;
                //if (experiment.timestep <= 0.0f)
                //if(animation.Interval<=0)
				// animation.Interval = 3;
            }
            Invalidate();
        }