public final Fleet fleet;
public Context(Fleet fleet) { this.fleet = fleet; }
+ // FIXME: ability for a group of Contexts to share an "allocation
+ // pool" because they will run concurrently.
+ public HashSet<Ship> allocatedShips = new HashSet<Ship>();
+
+ public Ship allocateShip(String name) {
+ for(int i=0; ; i++) {
+ Ship ship = fleet.getShip(name, i);
+ if (ship==null)
+ throw new RuntimeException("no more ships of type " + name);
+ if (allocatedShips.contains(ship)) continue;
+ allocatedShips.add(ship);
+ return ship;
+ }
+ }
+
+ // FIXME: is it legitimate to send a torpedo to a count==1 loop?
+ // FIXME: is it legitimate to send a torpedo to a count>1 loop?
/**
*
* A helper class for building loops of instructions.