private RobotModel(
      String name,
      double heig,
      double widt,
      double ener,
      double g_co,
      double g_hd,
      double g_ht,
      double r_he, // radar heading
      double head,
      double velo,
      double x,
      double y) {

    // Some unchanging features of the robot
    this.name = name;
    height = heig;
    width = widt;
    gun_cooling_rate = g_co;
    parent = null;

    // Initialize TimeCapsule and start tracking state
    this.tc = new TimeCapsule(this);
    tc.update(0, ener, g_hd, g_ht, head, velo, x, y);

    // Set up auxilary features
    this.mm = new MotionModel(this, new CircularMotion(current_history()));
    this.tm = new TargettingModel(this);

    // Generate random color for paint purposes
    Random r = new Random();
    c = new Color((name.hashCode() + r.nextInt(16777215)) % (16777215));
  }
 public Object get(O obj, K key) {
   lock.readLock().lock();
   try {
     // Checking if we have this object hashed
     HashMap<K, TimeCapsule> tMap = map.get(obj);
     if (tMap == null) {
       return null;
     }
     // Checking if that object has the given key
     TimeCapsule tc = tMap.get(key);
     if (tc == null) {
       return null;
     }
     // Checking if the entry has aged beyond its time
     if (timeout > 0 && tc.agedPast(timeout)) {
       return null;
     }
     return tc.obj;
   } finally {
     lock.readLock().unlock();
   }
 }
 /**
  * This method will remove all entries that aged beyond the assigned timeout. As this method has a
  * linear complexity, don't call it <i>too</i> often.
  *
  * <p>This method is a O(1) no-op if no timeout is defined for this method.
  */
 public void cull() {
   // Only do something if we actually have a timeout
   if (timeout <= 0) {
     return;
   }
   lock.writeLock().lock();
   for (HashMap<K, TimeCapsule> tMap : map.values()) {
     if (tMap == null) {
       continue;
     }
     Iterator<TimeCapsule> iter = tMap.values().iterator();
     while (iter.hasNext()) {
       TimeCapsule tc = iter.next();
       if (tc == null) {
         continue;
       }
       if (tc.agedPast(timeout)) {
         iter.remove();
       }
     }
   }
   lock.writeLock().unlock();
 }
 public void update(AdvancedRobot self) {
   if (self.getName().equals(name)) {
     tc.update(
         self.getTime(),
         self.getEnergy(),
         tm.predict_gun_heading(self, tc),
         tm.predict_gun_heat(self, tc),
         correct_angle(self.getHeadingRadians()),
         self.getVelocity(),
         self.getX(),
         self.getY());
     mm.update(self);
   }
 }
 public void update(ScannedRobotEvent sre, double self_h, double self_x, double self_y) {
   if (sre.getName().equals(name)) {
     tc.update(
         sre.getTime(),
         sre.getEnergy(),
         tm.predict_gun_heading(sre, tc),
         tm.predict_gun_heat(sre, tc),
         correct_angle(sre.getHeadingRadians()),
         sre.getVelocity(),
         getX(sre, self_h, self_x),
         getY(sre, self_h, self_y));
     mm.update(sre);
   }
 }
 public void update() {
   tc.update();
   mm.update();
   tm.update();
 }