Ejemplo n.º 1
0
        private void calcKillPoints(Robot who)
        {
            if (who.alive)
                who.kills = (short)(
                    (who.killTime[0] != -1 ? 1 : 0) +
                    (who.killTime[1] != -1 ? 1 : 0) +
                    (who.killTime[2] != -1 ? 1 : 0) +
                    (who.killTime[3] != -1 ? 1 : 0) +
                    (who.killTime[4] != -1 ? 1 : 0) +
                    (who.killTime[5] != -1 ? 1 : 0));
            else
                who.kills = (short)(
                    (who.killTime[0] != -1 && who.deathTime - who.killTime[0] >= 20 ? 1 : 0) +
                    (who.killTime[1] != -1 && who.deathTime - who.killTime[1] >= 20 ? 1 : 0) +
                    (who.killTime[2] != -1 && who.deathTime - who.killTime[2] >= 20 ? 1 : 0) +
                    (who.killTime[3] != -1 && who.deathTime - who.killTime[3] >= 20 ? 1 : 0) +
                    (who.killTime[4] != -1 && who.deathTime - who.killTime[4] >= 20 ? 1 : 0) +
                    (who.killTime[5] != -1 && who.deathTime - who.killTime[5] >= 20 ? 1 : 0));

            // Give every robot alive, if there's less than 4 and more than 1, a survival point.
            // If there's only one robot, wait 5 chronons before awarding a survival point.
            if (robots.Count > 2 && teamBattle)
            {
                if (numAlive == 3)
                {
                    foreach (Robot robot in robots)
                        if (robot.alive)
                            robot.survival = 1;
                }
                else if (numAlive == 2)
                {
                    foreach (Robot robot in robots)
                        if (robot.alive)
                            robot.survival = 2;
                }
            }
        }
Ejemplo n.º 2
0
        // Check whether a robot is colliding with another or the wall.
        // Also sets some critical attributes used by registers, like friend and wall.
        // Pretty much an exact translation of the original routine.
        private void checkCollisions(Robot who)
        {
            long deltaX, deltaY;

            foreach (Robot robot in robots)
            {
                if (robot == who || !robot.alive)
                    continue;

                deltaX = (long)(who.x - robot.x);
                deltaY = (long)(who.y - robot.y);
                if (Math.Abs(deltaX) >= Constants.ROBOT_RADIUS << 1 ||
                    Math.Abs(deltaY) >= Constants.ROBOT_RADIUS << 1 ||
                    deltaX * deltaX + deltaY * deltaY >= (Constants.ROBOT_RADIUS * Constants.ROBOT_RADIUS << 2))
                    continue;

                if (who.energy > 0 && who.stunned == 0)
                {
                    who.x -= who.speedx;
                    who.y -= who.speedy;
                }
                who.collision = true;
                robot.collision = true;
                if (who.team > 0 && who.team == robot.team)
                {
                    who.friend = true;
                    robot.friend = true;
                }
            }

            if (who.x < Constants.ROBOT_RADIUS || who.x > Constants.ARENA_SIZE - Constants.ROBOT_RADIUS)
            {
                who.wall = true;

                who.x = (short)Math.Max((ushort)0, who.x);
                who.x = (short)Math.Min((ushort)Constants.ARENA_SIZE, who.x);
            }
            if (who.y < Constants.ROBOT_RADIUS || who.y > Constants.ARENA_SIZE - Constants.ROBOT_RADIUS)
            {
                who.wall = true;

                who.y = (short)Math.Max((ushort)0, who.y);
                who.y = (short)Math.Min((ushort)Constants.ARENA_SIZE, who.y);
            }
        }
Ejemplo n.º 3
0
 protected RobotEvent(Arena.Robot robot)
 {
     this.robot = robot;
 }
Ejemplo n.º 4
0
        // Instantiate a Robot based on the loaded RobotFile
        public Robot loadRobot(RobotFile f)
        {
            // FIXME: Can this be done during a match?

            // Arena full?
            if (robots.Count == Constants.MAX_ROBOTS)
                return null;

            // Try to find a starting position not too close to the other robots.
            // FIXME: construct a list of starting positions in the constructor
            // so the outcome of prng.Next() is consistent.
            int x, y;
            double dist;
            do
            {
                x = prng.Next(Constants.ARENA_SIZE - 30) + 15;
                y = prng.Next(Constants.ARENA_SIZE - 30) + 15;
                dist = 1000;
                foreach (Robot other in robots)
                {
                    double test = Math.Pow(x - other.x, 2) + Math.Pow(y - other.y, 2);
                    if (test < dist)
                        dist = test;
                }
            } while (dist < 625);

            // Instantiate
            Robot robot = new Robot(this, x, y, robots.Count, f);

            // Update state
            robots_.Add(robot);
            numAlive++;

            return robot;
        }
Ejemplo n.º 5
0
 public void onSpawn(Robot owner_, Robot target_, int damage_)
 {
     base.baseOnSpawn(owner_, target_);
     damage = damage_;
 }
Ejemplo n.º 6
0
 public RobotWrapper(Robot robot)
 {
     this.robot_ = robot;
 }
Ejemplo n.º 7
0
 internal RobotException(Robot robot, String reason)
     : base(robot.interp, reason)
 {
     this.robot = robot;
 }
Ejemplo n.º 8
0
 public void onSpawn(Robot owner_, Robot target_)
 {
     base.baseOnSpawn(owner_, target_);
 }
Ejemplo n.º 9
0
 internal HardwareException(Robot robot, String msg)
     : base(robot, msg)
 {
 }
Ejemplo n.º 10
0
 internal RobotException(Robot robot, String reason, Exception innerException)
     : base(robot.interp, reason, innerException)
 {
 }
Ejemplo n.º 11
0
 internal StepEvent(Arena.Robot robot) : base(robot)
 {
 }
Ejemplo n.º 12
0
 internal InterruptEvent(Arena.Robot robot, Int16 code) : base(robot)
 {
     this.code = code;
 }
Ejemplo n.º 13
0
 internal RobotFaultEvent(Arena.Robot robot, Exception exception) : base(robot)
 {
     this.exception = exception;
 }
Ejemplo n.º 14
0
        private void checkDeath(Robot who)
        {
            if (who.damage > 0 || who.deathTime >= 0)
                return;

            numAlive--;

            who.explode();

            // Check if the game has ended
            if (numAlive > 1)
            {
                int loop;
                for (loop = 0; loop < robots.Count; loop++)
                    if (robots[loop].alive)
                        break;

                int firstTeam = robots[loop].team;
                if (firstTeam == 0)
                    return;
                else
                    foreach (Robot robot in robots)
                        if (robot.team != firstTeam && robot.alive)
                            return;
            }

            // End it after 20 chronons
            onlyTrackingShots = 20;
        }
Ejemplo n.º 15
0
 internal RobotException(Robot robot, VMachineException e)
     : this(robot, e.Message)
 {
 }
Ejemplo n.º 16
0
 // Subtract points for intimacy. This is war, gentlemen!
 private void doCollisionDamage(Robot who)
 {
     if (who.collision)
         who.doDamage(1);
     if (who.wall)
         who.doDamage(5);
 }
Ejemplo n.º 17
0
 public void onSpawn(Robot owner__, double anglex_, double angley_)
 {
     owner = owner__;
     anglex = anglex_;
     angley = angley_;
 }
Ejemplo n.º 18
0
 public RobotControl()
 {
     InitializeComponent();
     robot_ = null;
     update_info();
 }
Ejemplo n.º 19
0
 public void onSpawn(Robot owner_, int energy_)
 {
     owner = owner_;
     energy = energy_;
     frame = 0;
 }
Ejemplo n.º 20
0
 // We got hit by someone
 public bool doShotDamage(int amount, Robot from)
 {
     // Attribute kills to proper owner
     int oldDamage = damage;
     doDamage(amount);
     if (damage <= 0 && oldDamage > 0 && this != from
         && (from.energy > -200) && !(team != 0 && (team == from.team)))
     {
         deathReason = DeathReason.Killed;
         from.kills++;
         from.killTime[number] = parent.chronon;
         killer = from;
     }
     return damage < oldDamage; // return true if robot took damage
 }
Ejemplo n.º 21
0
 public RobotWidget()
 {
     this.Build();
     robot_ = null;
     update_info();
 }
Ejemplo n.º 22
0
 public void baseOnSpawn(Robot owner_, Robot target_)
 {
     owner = owner_;
     target = target_;
 }
Ejemplo n.º 23
0
 public void onSpawn(Robot owner_, Robot target_, int energy_)
 {
     base.baseOnSpawn(owner_, target_);
     energy = energy_;
 }