예제 #1
0
 /// <summary>
 /// The Cannon() function fires a missile heading a specified range and direction.
 /// Cannon() returns 1 (true) if a missile was fired, or 0 (false) if the cannon is reloading.
 /// Degree is forced into the range 0-359 as in Scan() and Drive().
 /// Range can be 0-700, with greater ranges truncated to 700.
 /// 
 /// Examples:
 ///    degree = 45;                              // set a direction to test
 ///    if ((range=Scan(robot, degree, 2)) > 0)   // see if a target is there
 ///      Cannon(robot, degree, range);           // fire a missile
 /// </summary>
 /// <param name="robot"></param>
 /// <param name="degree"></param>
 /// <param name="range"></param>
 /// <returns></returns>
 public static bool Cannon(Robot robot, int degree, int range)
 {
     return EngineInstance.FireCannon(robot, degree, range);
 }
예제 #2
0
 /// <summary>
 /// The Scan() function invokes the robot's scanner, at a specified degree and resolution.
 /// Scan() returns 0 if no robots are within the scan range or a positive integer representing
 /// the  range to the closest robot.  Degree should be within the range 0-359, otherwise degree
 /// is forced into 0-359 by a modulo 360 operation, and made positive if necessary.
 /// Resolution controls the scanner's sensing resolution, up to +/- 10 degrees.
 /// 
 /// Examples:
 ///   range = Scan(robot, 45, 0);   // scan 45, with no variance
 ///   range = Scan(robot, 365, 10); // scans the range from 355 to 15
 /// </summary>
 /// <param name="robot"></param>
 /// <param name="degree"></param>
 /// <param name="resolution"></param>
 /// <returns></returns>
 public static int Scan(Robot robot, int degree, int resolution)
 {
     return EngineInstance.Scan(robot, degree, resolution);
 }
예제 #3
0
 /// <summary>
 /// The Speed() function returns the current speed of the robot.
 /// Speed() takes no arguments, and returns the percent of speed, 0-100.
 /// Note that Speed() may not always be the same as the last drive(), because of acceleration and de-acceleration.
 /// 
 /// Examples:
 ///   Drive(robot, 270, 100);   // start drive, due south
 ///   ; ; ;                     // other instructions
 ///   if (Speed(robot) == 0)    // check current speed
 ///   {
 ///     Drive(robot, 90, 20);   // ran into the south wall, or another robot
 ///   }
 /// </summary>
 /// <param name="robot"></param>
 /// <returns></returns>
 public static int Speed(Robot robot)
 {
     return EngineInstance.Bots.Find(botAssembly => botAssembly.Id == robot.Id).Speed;
 }
예제 #4
0
 /// <summary>
 /// The LocationY() function returns the robot's current y axis location in range 0-999.
 /// 
 /// Examples:
 ///    Drive(robot, 0, 50);             // start heading for east wall
 ///    while (LocationY(robot)) > 20)
 ///      ;                              // do nothing until we are close
 ///    Drive(robot, 180, 0);            // stop drive
 /// </summary>
 /// <param name="robot"></param>
 /// <returns></returns>
 public static int LocationY(Robot robot)
 {
     return (int)EngineInstance.Bots.Find(botAssembly => botAssembly.Id == robot.Id).Location.Y;
 }
예제 #5
0
        /// <summary>
        /// The Drive() function activates the robot's drive mechanism, on a specified heading and speed.
        /// Degree is forced into the range 0-359 as in Scan().
        /// Speed is expressed as a percent, with 100 as maximum.
        /// A speed of 0 disengages the drive.
        /// Changes in direction can be negotiated at speeds of less than 50 percent.
        /// 
        /// Examples:
        ///    Drive(robot, 0, 100);  // head due east, at maximum speed
        ///    Drive(robot, 90, 0);   // stop motion
        /// </summary>
        /// <param name="robot"></param>
        /// <param name="degree"></param>
        /// <param name="speed"></param>
        public static void Drive(Robot robot, int degree, int speed)
        {
            if (speed < 0) speed = 0;
            if (speed > 100) speed = 100;
            if (degree < 0) degree = 0;
            if (degree > 359) degree = 359;

            EngineInstance.Bots.Find(botAssembly => botAssembly.Id == robot.Id).Speed = speed;

            if (speed <= 50)
                EngineInstance.Bots.Find(botAssembly => botAssembly.Id == robot.Id).Direction = degree;
        }
예제 #6
0
 /// <summary>
 /// The Damage() function returns the current amount of damage incurred.
 /// Damage() takes no arguments, and returns the percent of damage, 0-99.
 /// (100 percent damage means the robot is completely disabled, thus no longer running!) 
 /// 
 /// Examples:
 ///   d = Damage(robot);        // save current state
 ///   ; ; ;                     // other instructions
 ///   if (d != Damage(robot))   // compare current state to prior state
 ///   {
 ///     Drive(robot, 90, 100);  // robot has been hit, start moving
 ///     d = Damage(robot);      // get current damage again
 ///   } 
 /// </summary>
 /// <param name="robot"></param>
 /// <returns></returns>
 public static int Damage(Robot robot)
 {
     return EngineInstance.Bots.Find(botAssembly => botAssembly.Id == robot.Id).Damage;
 }
예제 #7
0
        /// <summary>
        /// Called from the Arena, when a bot calls the Arena.Scan() method
        /// 
        /// The Scan() function invokes the robot's scanner, at a specified degree and resolution.
        /// Scan() returns 0 if no robots are within the scan range or a positive integer representing
        /// the  range to the closest robot.  Degree should be within the range 0-359, otherwise degree
        /// is forced into 0-359 by a modulo 360 operation, and made positive if necessary.
        /// Resolution controls the scanner's sensing resolution, up to +/- 10 degrees.
        /// 
        /// Examples:
        ///   range = Scan(robot, 45, 0);   // scan 45, with no variance
        ///   range = Scan(robot, 365, 10); // scans the range from 355 to 15
        /// </summary>
        /// <param name="robot"></param>
        /// <param name="degree"></param>
        /// <param name="resolution"></param>
        /// <returns></returns>
        public int Scan(Robot robot, int degree, int resolution)
        {
            degree = Arena.DegreeTo360(degree);
            if (resolution < 0) resolution = 0;
            if (resolution > MaxScanResolution) resolution = MaxScanResolution;

            // Get the BotAssembly of the given robot from our list of robots
            BotAssembly botAssembly = Bots.Find(ba => ba.Id == robot.Id);

            // Update these for display
            botAssembly.ScanDirection = degree;
            botAssembly.ScanResolution = resolution;

            // Iterate all bots (Max of 4 bots in the game)
            foreach (var bot in Bots)
            {
                // As long as it is not the given robot
                if (bot != botAssembly)
                {
                    // Plot a course from this bot to the given methods bot
                    int course = Arena.PlotCourse((int)bot.Location.X,
                                                  (int)bot.Location.Y,
                                                  (int)botAssembly.Location.X,
                                                  (int)botAssembly.Location.Y);

                    // Given the Scan resolution ( +/- 10 degrees maximum ) is there a bot out there?
                    int degStart = Arena.DegreeTo360(degree - resolution);
                    int degEnd = Arena.DegreeTo360(degree + resolution);
                    for (int scanResolution = degStart; scanResolution <= degEnd; ++scanResolution)
                    {
                        if (course == scanResolution)
                        {
                            // Return the range to the discovered target
                            int range = Math.Abs(Arena.Distance((int)bot.Location.X,
                                                                (int)bot.Location.Y,
                                                                (int)botAssembly.Location.X,
                                                                (int)botAssembly.Location.Y));

                            // Return the range to the discovered robot if distance is MaxScanRange or less
                            return range;//range >= MaxScanRange ? range : 0;
                        }
                    }
                }
            }

            // No robot found
            return 0;
        }
예제 #8
0
        /// <summary>
        /// Called from the Arena, when a bot calls the Arena.Cannon() method
        /// 
        /// The Cannon() function fires a missile heading a specified range and direction.
        /// Cannon() returns 1 (true) if a missile was fired, or 0 (false) if the cannon is reloading.
        /// Degree is forced into the range 0-359 as in Scan() and Drive().
        /// Range can be 0-700, with greater ranges truncated to 700.
        /// 
        /// Examples:
        ///    degree = 45;                              // set a direction to test
        ///    if ((range=Scan(robot, degree, 2)) > 0)   // see if a target is there
        ///      Cannon(robot, degree, range);           // fire a missile
        /// </summary>
        /// <param name="robot"></param>
        /// <param name="degree"></param>
        /// <param name="range"></param>
        /// <returns></returns>
        public bool FireCannon(Robot robot, int degree, int range)
        {
            degree = Arena.DegreeTo360(degree);
            if (range < 0) range = 0;
            if (range > 700) range = 700;

            BotAssembly bot = Bots.Find(botAssembly => botAssembly.Id == robot.Id);

            if (bot.MissilesInFlight < MaxMissles)
            {
                bot.MissilesInFlight++;
                Missiles.Add(new Missile
                                      {
                                          Id = robot.Id,
                                          Speed = 100,
                                          Location = new PointF {X = bot.Location.X, Y = bot.Location.Y},
                                          Direction = degree,
                                          Range = range
                                      });

                return true;
            }

            return false;
        }