Ejemplo n.º 1
0
        //per default we use the goal point of the environment as our target point.
        public void update(Engine.Environment env, List <Robot> robots, CollisionManager cm)
        {
            // Schrum: Provides an easy way to clear sensors for domains
            // where way points should not be sensed
            if (env == null)
            {
                for (int i = 0; i < radarAngles1.Count; i++)
                {
                    signalsSensors[i].setSignal(0.0);
                }
                return;
            }

            Point2D temp = new Point2D((int)env.goal_point.x, (int)env.goal_point.y);

            temp.rotate((float)-(owner.heading), owner.circle.p);  //((float)-(owner.heading * 180.0 / 3.14), owner.circle.p);

            //translate with respect to location of navigator
            temp.x -= (float)owner.circle.p.x;
            temp.y -= (float)owner.circle.p.y;

            //what angle is the vector between target & navigator
            float angle = angleValue((float)temp.x, (float)temp.y); // (float)temp.angle();

            //!    angle *= 57.297f;//convert to degrees

            //fire the appropriate radar sensor
            for (int i = 0; i < radarAngles1.Count; i++)
            {
                signalsSensors[i].setSignal(0.0);
                //radar[i] = 0.0f;

                if (angle >= radarAngles1[i] && angle < radarAngles2[i])
                {
                    signalsSensors[i].setSignal(1.0);
                    //   Console.WriteLine(i);
                }
                //radar[i] = 1.0f;

                if (angle + 360.0 >= radarAngles1[i] && angle + 360.0 < radarAngles2[i])
                {
                    signalsSensors[i].setSignal(1.0);
                    // Console.WriteLine(i);
                }
//                    radar[i] = 1.0f;


                // inputs[sim_engine.robots[0].rangefinders.Count + i] = sim_engine.radar[i];
            }
        }
        //Different from PieSliceSensorArray in that EnemyRobots are used as targets instead
        // of goal points.
        public void update(Engine.Environment env, List <Robot> robots, CollisionManager cm)
        {
            List <float> translatedEnemyAngles = new List <float>();

            // Start at 1: Assume all robots after first are enemies
            for (int i = 1; i < robots.Count; i++)
            {
                EnemyRobot er = (EnemyRobot)robots[i];
                if (!er.stopped) // Only sense prey robots that are active
                {
                    Point2D temp = new Point2D((int)er.location.x, (int)er.location.y);

                    temp.rotate((float)-(owner.heading), owner.circle.p);  //((float)-(owner.heading * 180.0 / 3.14), owner.circle.p);

                    //translate with respect to location of navigator
                    temp.x -= (float)owner.circle.p.x;
                    temp.y -= (float)owner.circle.p.y;

                    //what angle is the vector between target & navigator
                    float angle = angleValue((float)temp.x, (float)temp.y);// (float)temp.angle();

                    translatedEnemyAngles.Add(angle);
                }
            }

            //fire the appropriate radar sensor
            for (int i = 0; i < radarAngles1.Count; i++)
            {
                signalsSensors[i].setSignal(0.0);

                for (int a = 0; a < translatedEnemyAngles.Count; a++)
                {
                    float angle = translatedEnemyAngles[a];

                    if (angle >= radarAngles1[i] && angle < radarAngles2[i])
                    {
                        signalsSensors[i].setSignal(1.0);
                    }

                    if (angle + 360.0 >= radarAngles1[i] && angle + 360.0 < radarAngles2[i])
                    {
                        signalsSensors[i].setSignal(1.0);
                    }
                }
            }
        }
Ejemplo n.º 3
0
        void IFitnessFunction.update(SimulatorExperiment Experiment, Environment environment, instance_pack ip)
        {
            // Schrum: brain-switching policy
            // Schrum: Restricting numBrains == 2 assures that this switch won't occur in the FourTasks experiments with 5 brains
            if (Experiment.multibrain && !Experiment.preferenceNeurons && Experiment.numBrains == 2)
            {
                // Schrum: These magic numbers directly correspond to the Two Rooms environment.
                //         This range of y values is the portion of the environment that is taken
                //         up by the hallway.
                if (ip.agentBrain.getBrainCounter() == 1 && // Don't "switch" if already using right brain
                    ip.robots[0].location.y < 716 && ip.robots[0].location.y > 465) //hallway
                {
                    //Console.WriteLine("Switch to 0");
                    ip.agentBrain.switchBrains(0); // use brain 0 for hallway
                }
                else if (ip.agentBrain.getBrainCounter() == 0)   //room
                {
                    //Console.WriteLine("Switch to 1");
                    ip.agentBrain.switchBrains(1); // use brain 1 when in the open
                }
            }

            // Schrum: Debug: For comparing non-visual eval with visual
            // Prints out locations visited by all robots
            /*
            for (int i = 0; i < ip.robots.Count; i++)
            {
                Console.Write(ip.robots[i].location.x + "\t" + ip.robots[i].location.y + "\t");
                if (ip.robots[i] is EnemyRobot)
                {
                    Console.Write(((EnemyRobot)ip.robots[i]).wallResponse + "\t" + ((EnemyRobot)ip.robots[i]).chaseResponse + "\t" + ip.robots[i].heading + "\t" + ((EnemyRobot)ip.robots[i]).angle + "\t");
                }
            }
            Console.WriteLine();
            */
            // End debug

            //For food gathering
            if (ip.timeSteps == 1)
            {
                environment.goal_point.x = environment.POIPosition[0].X;
                environment.goal_point.y = environment.POIPosition[0].Y;

                collectedFood = 0;
                POINr = 0;
                collided = false;
				finished = false;
                portionAlive = 0;
            }

			Point2D goalPoint = new Point2D (environment.POIPosition [POINr].X, environment.POIPosition [POINr].Y);
	
			float d = (float)ip.robots[0].location.distance(goalPoint);
			bool guidance = true;
			if (d < 20.0f && !finished)
            {
                collectedFood++;
                POINr++;

				if (POINr >= environment.POIPosition.Count) {
					POINr = 0;
					finished = true;
				}

				if (POINr > 4 && POINr < 11) {
					guidance = false;
				}

				if (guidance) {
					environment.goal_point.x = environment.POIPosition [POINr].X;
					environment.goal_point.y = environment.POIPosition [POINr].Y;
				}

			
            }

            // Schrum2: Added to detect robot collisions and end the evaluation when they happen
			if (ip.robots[0].collisions > 0)
            { // Disabling prevents further action
                collided = true;
                portionAlive = (ip.elapsed * 1.0) / Experiment.evaluationTime;
                //Console.WriteLine("Fitness before:" + ip.elapsed + "/" + Experiment.evaluationTime + ":" + ip.timeSteps);
                ip.elapsed = Experiment.evaluationTime; // force end time: only affects non-visual evaluation
                Experiment.running = false; // Ends visual evaluation
                //Console.WriteLine("Collision");
                //Console.WriteLine("Fitness after:" + ip.elapsed + "/" + Experiment.evaluationTime + ":" + ip.timeSteps);
            }
        }