RoboSim.RoboAPIImplementor Class Reference
Inheritance diagram for RoboSim.RoboAPIImplementor:
Collaboration diagram for RoboSim.RoboAPIImplementor:

Public Member Functions

Robot.AttackResult meleeAttack (int power, Robot.GridCell adjacent_cell) throws RoboSimExecutionException
 
Robot.AttackResult rangedAttack (int power, Robot.GridCell nonadjacent_cell) throws RoboSimExecutionException
 
Robot.AttackResult capsuleAttack (int power_of_capsule, Robot.GridCell cell) throws RoboSimExecutionException
 
void defend (int power) throws RoboSimExecutionException
 
void move (int steps, Robot.Direction way) throws RoboSimExecutionException
 
void pick_up_capsule (Robot.GridCell adjacent_cell) throws RoboSimExecutionException
 
void drop_capsule (Robot.GridCell adjacent_cell, int power_of_capsule) throws RoboSimExecutionException
 
Robot.BuildStatus getBuildStatus ()
 
Robot.GridCell getBuildTarget ()
 
int getInvestedBuildPower ()
 
void setBuildTarget (Robot.BuildStatus status, Robot.GridCell location) throws RoboSimExecutionException
 
void setBuildTarget (Robot.BuildStatus status, Robot.GridCell location, byte[] message) throws RoboSimExecutionException
 
void build (int power) throws RoboSimExecutionException
 
void repair (int power) throws RoboSimExecutionException
 
void charge (int power, Robot.GridCell ally) throws RoboSimExecutionException
 
void sendMessage (byte[] message, int power) throws RoboSimExecutionException
 
Robot.GridCell[][] getVisibleNeighborhood ()
 
Robot.GridCell[][] getWorld (int power) throws RoboSimExecutionException
 
void scanEnemy (Robot.Robot_Specs enemySpecs, Robot.Robot_Status enemyStatus, Robot.GridCell toScan) throws RoboSimExecutionException
 

Private Member Functions

 RoboAPIImplementor (RobotData actingRobot_)
 
boolean isAdjacent (Robot.GridCell adjacent_cell)
 
boolean calculateHit (int attack, int defense)
 
Robot.AttackResult processAttack (int attack, SimGridCell cell_to_attack, int power) throws RoboSimExecutionException
 
void finalizeBuilding (byte[] creation_message) throws RoboSimExecutionException
 

Private Attributes

RobotData actingRobot
 

Detailed Description

The implementing class for the WorldAPI reference. We can't just use ourselves for this because students could downcast us to our real type and manipulate the simulator in untoward ways (not that any of you would do that, and I would catch it when I reviewed your code anyway, but still).

NOTE: THIS IS A NON-STATIC INNER CLASS!

Definition at line 282 of file RoboSim.java.

Constructor & Destructor Documentation

RoboSim.RoboAPIImplementor.RoboAPIImplementor ( RobotData  actingRobot_)
private

Private constructor

Parameters
actingRobot_data for robot attempting to act in the simulator

Definition at line 290 of file RoboSim.java.

References RoboSim.RoboAPIImplementor.actingRobot.

Referenced by RoboSim.RoboAPIImplementor.processAttack().

290 { actingRobot = actingRobot_; }

Here is the caller graph for this function:

Member Function Documentation

void RoboSim.RoboAPIImplementor.build ( int  power) throws RoboSimExecutionException
Parameters
powerhow much power to apply to building the current target. Must not be more than remaining power needed to finish building target.

Implements WorldAPI.

Definition at line 883 of file RoboSim.java.

References RoboSim.RoboAPIImplementor.actingRobot, RoboSim.RobotData.assoc_cell, RoboSim.RobotData.player, and RoboSim.RobotData.status.

884  {
885  if(power > actingRobot.status.power || power < 0)
886  throw new RoboSimExecutionException("attempted to apply invalid power to build task",actingRobot.player,actingRobot.assoc_cell);
887  actingRobot.status.charge-=power;
888  actingRobot.status.power-=power;
889  actingRobot.investedPower+=power;
890  }
Robot.Robot_Status status
Definition: RoboSim.java:69
SimGridCell assoc_cell
Definition: RoboSim.java:67
boolean RoboSim.RoboAPIImplementor.calculateHit ( int  attack,
int  defense 
)
private

Did the attacker hit the defender?

Parameters
attackattack skill of attacker (including bonuses/penalties)
defensedefense skill of defender (including bonuses)
Returns
whether the attacker hit

Definition at line 311 of file RoboSim.java.

Referenced by RoboSim.RoboAPIImplementor.processAttack().

312  {
313  int luckOfAttacker = generator.nextInt(10);
314  return luckOfAttacker+attack-defense>=5;
315  }

Here is the caller graph for this function:

Robot.AttackResult RoboSim.RoboAPIImplementor.capsuleAttack ( int  power_of_capsule,
Robot.GridCell  cell 
) throws RoboSimExecutionException

Capsule attack: attack with a capsule

Parameters
power_of_capsulepower of the capsule to use in the attack
cellGridCell (may be adjacent or nonadjacent) to attack

Implements WorldAPI.

Definition at line 511 of file RoboSim.java.

References RoboSim.RoboAPIImplementor.actingRobot, RoboSim.RobotData.assoc_cell, RoboSim.RobotData.player, RoboSim.RoboAPIImplementor.processAttack(), RoboSim.RobotData.specs, RoboSim.RobotData.status, RoboSim.worldGrid, Robot.GridCell.x_coord, and Robot.GridCell.y_coord.

512  {
513  //Error checking, *sigh*...
514  if(cell==null)
515  throw new RoboSimExecutionException("passed null to capsuleAttack()",actingRobot.player,actingRobot.assoc_cell);
516 
517  //Does cell exist in grid?
518  if(cell.x_coord > worldGrid.length || cell.y_coord > worldGrid[0].length || cell.x_coord < 0 || cell.y_coord < 0)
519  throw new RoboSimExecutionException("passed invalid cell coordinates to capsuleAttack()",actingRobot.player,actingRobot.assoc_cell,cell);
520 
521  //Cell to attack
522  SimGridCell cell_to_attack = worldGrid[cell.x_coord][cell.y_coord];
523 
524  //Do we have a capsule of this power rating?
525  int capsule_index = ArrayUtility.linearSearch(actingRobot.status.capsules,power_of_capsule);
526 
527  if(capsule_index==-1)
528  throw new RoboSimExecutionException("passed invalid power to capsuleAttack(): doesn't have capsule of power "+power_of_capsule,actingRobot.player,actingRobot.assoc_cell);
529 
530  //Can we use this capsule? (attack + defense >= power)
531  if(actingRobot.specs.attack + actingRobot.specs.defense < power_of_capsule)
532  throw new RoboSimExecutionException("attempted to use capsule of greater power than attack+defense",actingRobot.player,actingRobot.assoc_cell);
533 
534  //Can we hit the target? Range is power of capsule + defense.
535  Robot.GridCell[] shortest_path = Robot.RobotUtility.findShortestPath(actingRobot.assoc_cell,cell_to_attack,worldGrid);
536 
537  if(shortest_path==null)
538  throw new RoboSimExecutionException("no clear shot to target",actingRobot.player,actingRobot.assoc_cell,cell_to_attack);
539 
540  if(shortest_path.length > power_of_capsule + actingRobot.specs.defense)
541  throw new RoboSimExecutionException("target not in range",actingRobot.player,actingRobot.assoc_cell,cell_to_attack);
542 
543  //Is there an enemy, fort, or wall at the cell's location?
544  switch(cell_to_attack.contents)
545  {
546  case EMPTY:
547  throw new RoboSimExecutionException("attempted to attack empty cell",actingRobot.player,actingRobot.assoc_cell,cell_to_attack);
548  case BLOCKED:
549  throw new RoboSimExecutionException("attempted to attack blocked tile",actingRobot.player,actingRobot.assoc_cell,cell_to_attack);
550  case SELF:
551  if(cell_to_attack.occupant_data.player.equals(actingRobot.player))
552  throw new RoboSimExecutionException("attempted to attack ally",actingRobot.player,actingRobot.assoc_cell,cell_to_attack);
553  break;
554  case CAPSULE:
555  throw new RoboSimExecutionException("attempted to attack energy capsule",actingRobot.player,actingRobot.assoc_cell,cell_to_attack);
556  case ALLY:
557  throw new RuntimeException("ERROR in RoboSim.RoboAPIImplementor.capsuleAttack(). This is probably not the student's fault. Contact Patrick Simmons about this message. (Not the Doobie Brother...)");
558  }
559 
560  /*Okay, if we're still here, we can use the capsule.
561  Need to delete capsule from robot status structure.
562  */
563  actingRobot.status.capsules = ArrayUtility.deleteElement(actingRobot.status.capsules,capsule_index);
564 
565  int[] newCapsules = new int[actingRobot.status.capsules.length-1];
566  boolean deleted_capsule = false;
567  for(int i=0,j=0; i<actingRobot.status.capsules.length; i++,j++)
568  {
569  if(!deleted_capsule && actingRobot.status.capsules[i]==power_of_capsule)
570  {
571  deleted_capsule=true;
572  j--;
573  continue;
574  }
575  newCapsules[j]=actingRobot.status.capsules[i];
576  }
577 
578  //Process attack
579  return processAttack(actingRobot.specs.attack + power_of_capsule,cell_to_attack,(int)(Math.ceil(0.1 * power_of_capsule * actingRobot.specs.attack)));
580  }
Robot.AttackResult processAttack(int attack, SimGridCell cell_to_attack, int power)
Definition: RoboSim.java:323
SimGridCell[][] worldGrid
Definition: RoboSim.java:93
Robot.Robot_Status status
Definition: RoboSim.java:69
SimGridCell assoc_cell
Definition: RoboSim.java:67
Robot.Robot_Specs specs
Definition: RoboSim.java:68

Here is the call graph for this function:

void RoboSim.RoboAPIImplementor.charge ( int  power,
Robot.GridCell  ally 
) throws RoboSimExecutionException

Spend power to charge an adjacent ally robot. 1-for-1 efficiency.

Parameters
poweramount of power to use for charging ally
allycell containing ally to charge. Must be adjacent.

Implements WorldAPI.

Definition at line 905 of file RoboSim.java.

References RoboSim.RoboAPIImplementor.actingRobot, RoboSim.RobotData.assoc_cell, Robot.GridCell.contents, RoboSim.RoboAPIImplementor.isAdjacent(), RoboSim.SimGridCell.occupant_data, RoboSim.RobotData.player, RoboSim.RobotData.status, RoboSim.worldGrid, Robot.GridCell.x_coord, and Robot.GridCell.y_coord.

906  {
907  //Lots of error checking here (as everywhere...)
908  if(ally==null)
909  throw new RoboSimExecutionException("passed null as argument to charge()",actingRobot.player);
910 
911  //Check that we're using a valid amount of power
912  if(power > actingRobot.status.power || power < 1)
913  throw new RoboSimExecutionException("attempted charge with illegal power level",actingRobot.player,actingRobot.assoc_cell);
914 
915  //Are cells adjacent?
916  if(!isAdjacent(ally))
917  throw new RoboSimExecutionException("attempted to charge nonadjacent cell",actingRobot.player,actingRobot.assoc_cell);
918 
919  //Does cell exist in grid?
920  //(could put this in isAdjacent() method but want to give students more useful error messages)
921  if(ally.x_coord > worldGrid.length || ally.y_coord > worldGrid[0].length || ally.x_coord < 0 || ally.y_coord < 0)
922  throw new RoboSimExecutionException("passed invalid cell coordinates to charge()",actingRobot.player,actingRobot.assoc_cell,ally);
923 
924  //Safe to use this now, checked for oob condition from student
925  SimGridCell allied_cell = worldGrid[ally.x_coord][ally.y_coord];
926 
927  //Is there an ally in that cell?
928  if(allied_cell.contents!=Robot.GridObject.SELF || !allied_cell.occupant_data.player.equals(actingRobot.player))
929  throw new RoboSimExecutionException("attempted to charge non-ally, or cell with no robot in it",actingRobot.player,actingRobot.assoc_cell,allied_cell);
930 
931  //Perform the charge
932  actingRobot.status.power-=power;
933  actingRobot.status.charge-=power;
934  allied_cell.occupant_data.status.charge+=power;
935  }
SimGridCell[][] worldGrid
Definition: RoboSim.java:93
Definition: Robot.java:11
Robot.Robot_Status status
Definition: RoboSim.java:69
SimGridCell assoc_cell
Definition: RoboSim.java:67
boolean isAdjacent(Robot.GridCell adjacent_cell)
Definition: RoboSim.java:297

Here is the call graph for this function:

void RoboSim.RoboAPIImplementor.defend ( int  power) throws RoboSimExecutionException

Defend: increase defense

Parameters
powerpower to use for defense (may not exceed defense skill)

Implements WorldAPI.

Definition at line 582 of file RoboSim.java.

References RoboSim.RoboAPIImplementor.actingRobot, RoboSim.RobotData.assoc_cell, RoboSim.RobotData.player, RoboSim.RobotData.specs, and RoboSim.RobotData.status.

583  {
584  //Error checking
585  if(power < 0 || power > actingRobot.specs.defense || power > actingRobot.specs.power || power > actingRobot.status.charge)
586  throw new RoboSimExecutionException("attemped to defend with negative power",actingRobot.player, actingRobot.assoc_cell);
587 
588  //This one's easy
589  actingRobot.status.charge-=power;
590  actingRobot.status.defense_boost+=power;
591  }
Robot.Robot_Status status
Definition: RoboSim.java:69
SimGridCell assoc_cell
Definition: RoboSim.java:67
Robot.Robot_Specs specs
Definition: RoboSim.java:68
void RoboSim.RoboAPIImplementor.drop_capsule ( Robot.GridCell  adjacent_cell,
int  power_of_capsule 
) throws RoboSimExecutionException

drop_capsule: drop a capsule (for an ally to pick up, presumably)

Parameters
adjacent_cellwhere to drop capsule (must be adjacent)
power_of_capsulehow powerful a capsule to drop

Implements WorldAPI.

Definition at line 703 of file RoboSim.java.

References RoboSim.RoboAPIImplementor.actingRobot, RoboSim.RobotData.assoc_cell, Robot.GridCell.contents, RoboSim.RoboAPIImplementor.isAdjacent(), RoboSim.RobotData.player, RoboSim.worldGrid, Robot.GridCell.x_coord, and Robot.GridCell.y_coord.

704  {
705  //Error checking, *sigh*...
706  //Can't pass us null
707  if(adjacent_cell==null)
708  throw new RoboSimExecutionException("passed null to pick_up_capsule()",actingRobot.player,actingRobot.assoc_cell);
709 
710  //Does cell exist in grid?
711  if(adjacent_cell.x_coord > worldGrid.length || adjacent_cell.y_coord > worldGrid[0].length || adjacent_cell.x_coord < 0 || adjacent_cell.y_coord < 0)
712  throw new RoboSimExecutionException("passed invalid cell coordinates to pick_up_capsule()",actingRobot.player,actingRobot.assoc_cell,adjacent_cell);
713 
714  //Cell in question
715  SimGridCell gridCell = worldGrid[adjacent_cell.x_coord][adjacent_cell.y_coord];
716 
717  //Cell must be adjacent
718  if(!isAdjacent(adjacent_cell))
719  throw new RoboSimExecutionException("attempted to pick up capsule in nonadjacent cell",actingRobot.player,actingRobot.assoc_cell,gridCell);
720 
721  //Is the cell empty?
722  if(gridCell.contents!=Robot.GridObject.EMPTY)
723  throw new RoboSimExecutionException("attempted to place capsule in nonempty cell",actingRobot.player,actingRobot.assoc_cell,gridCell);
724 
725  //Do we have such a capsule?
726  int index = ArrayUtility.linearSearch(actingRobot.status.capsules,power_of_capsule);
727  if(index==-1)
728  throw new RoboSimExecutionException("attempted to drop capsule with power "+power_of_capsule+", having no such capsule",actingRobot.player,actingRobot.assoc_cell,gridCell);
729 
730  //Okay. We're good. Drop the capsule
731  gridCell.contents = Robot.GridObject.CAPSULE;
732  gridCell.capsule_power = power_of_capsule;
733 
734  //Delete it from our inventory
735  ArrayUtility.deleteElement(actingRobot.status.capsules,index);
736  }
SimGridCell[][] worldGrid
Definition: RoboSim.java:93
Definition: Robot.java:11
SimGridCell assoc_cell
Definition: RoboSim.java:67
boolean isAdjacent(Robot.GridCell adjacent_cell)
Definition: RoboSim.java:297

Here is the call graph for this function:

void RoboSim.RoboAPIImplementor.finalizeBuilding ( byte[]  creation_message) throws RoboSimExecutionException
private

Definition at line 753 of file RoboSim.java.

References RoboSim.RoboAPIImplementor.actingRobot, RoboSim.RobotData.assoc_cell, RoboSim.checkSpecsValid(), Robot.createRobot(), RoboSim.RobotData.invested_assoc_cell, RoboSim.RobotData.investedPower, RoboSim.RobotData.player, RoboSim.RobotData.robot, RoboSim.RobotData.specs, RoboSim.RobotData.status, RoboSim.turnOrder, RoboSim.WALL_HEALTH, and RoboSim.RobotData.whatBuilding.

Referenced by RoboSim.RoboAPIImplementor.setBuildTarget().

754  {
755  //Nothing to finalize if not building anything
756  if(actingRobot.whatBuilding==null)
757  return;
758 
759  //What do we have to finalize?
760  switch(actingRobot.whatBuilding)
761  {
762  case WALL:
763  if(actingRobot.investedPower >= 50)
764  {
765  actingRobot.invested_assoc_cell.contents = Robot.GridObject.WALL;
766  actingRobot.invested_assoc_cell.wallforthealth = WALL_HEALTH;
767  }
768  else
769  actingRobot.invested_assoc_cell.contents = Robot.GridObject.EMPTY;
770  break;
771 
772  case FORT:
773  if(actingRobot.investedPower >= 75)
774  {
775  actingRobot.invested_assoc_cell.contents = Robot.GridObject.FORT;
776  actingRobot.invested_assoc_cell.wallforthealth = WALL_HEALTH;
777  }
778  else
779  actingRobot.invested_assoc_cell.contents = Robot.GridObject.EMPTY;
780  break;
781 
782  case CAPSULE:
783  int capsule_power = actingRobot.investedPower/10;
784  if(capsule_power!=0)
785  {
786  if(actingRobot.status.capsules.length+1>actingRobot.specs.attack+actingRobot.specs.defense)
787  throw new RoboSimExecutionException("attempted to finish building capsule when already at max capsule capacity",actingRobot.player,actingRobot.assoc_cell);
788  actingRobot.status.capsules = ArrayUtility.addElement(actingRobot.status.capsules,capsule_power);
789  }
790  break;
791 
792  case ROBOT:
793  int skill_points = actingRobot.investedPower/20;
794  if(skill_points!=0)
795  {
796  //Check creation message correct size
797  if(creation_message!=null && creation_message.length!=64)
798  throw new RoboSimExecutionException("passed incorrect sized creation message to setBuildTarget()",actingRobot.player,actingRobot.assoc_cell,actingRobot.invested_assoc_cell);
799 
800  //Set default creation message if we don't have one
801  if(creation_message==null)
802  {
803  creation_message = new byte[64];
804  creation_message[1] = (byte)(turnOrder.size() % 256);
805  creation_message[0] = (byte)(turnOrder.size() / 256);
806  }
807 
808  //Create the robot
809  actingRobot.invested_assoc_cell.contents = Robot.GridObject.SELF;
810  RobotData data = actingRobot.invested_assoc_cell.occupant_data = new RobotData();
811  data.assoc_cell = actingRobot.invested_assoc_cell;
812  try
813  {
814  data.robot = (Robot)(Class.forName(actingRobot.player).getConstructor().newInstance());
815  }
816  catch(Exception e)
817  {
818  throw new RoboSimExecutionException("something went wrong calling student's constructor", actingRobot.player,actingRobot.assoc_cell, actingRobot.invested_assoc_cell);
819  }
820  data.player = actingRobot.player;
821  data.specs = checkSpecsValid(data.robot.createRobot(null, skill_points, creation_message), actingRobot.player, skill_points);
822  data.status = new Robot.Robot_Status();
823  data.status.charge = data.status.health = data.specs.power*10;
824  data.buffered_radio = new ArrayList<byte[]>();
825  turnOrder.add(data);
826  }
827  else
828  actingRobot.invested_assoc_cell.contents = Robot.GridObject.EMPTY;
829  break;
830  }
831  }
ArrayList< RobotData > turnOrder
Definition: RoboSim.java:94
Definition: Robot.java:11
static Robot.Robot_Specs checkSpecsValid(Robot.Robot_Specs proposed, String player, int skill_points)
Definition: RoboSim.java:167
SimGridCell invested_assoc_cell
Definition: RoboSim.java:76
final int WALL_HEALTH
Definition: RoboSim.java:89
Robot.Robot_Status status
Definition: RoboSim.java:69
SimGridCell assoc_cell
Definition: RoboSim.java:67
Robot.BuildStatus whatBuilding
Definition: RoboSim.java:74
Robot.Robot_Specs specs
Definition: RoboSim.java:68

Here is the call graph for this function:

Here is the caller graph for this function:

Robot.BuildStatus RoboSim.RoboAPIImplementor.getBuildStatus ( )

Tells us what we're in the middle of building.

Returns
BuildStatus object indicating what we're building. Is null if we're not building anything.

Implements WorldAPI.

Definition at line 738 of file RoboSim.java.

739  {
740  return actingRobot.whatBuilding;
741  }
Robot.GridCell RoboSim.RoboAPIImplementor.getBuildTarget ( )
Returns
GridCell indicating the target of our building efforts. Is null if we're not building anything.

Implements WorldAPI.

Definition at line 743 of file RoboSim.java.

744  {
745  return actingRobot.invested_assoc_cell;
746  }
int RoboSim.RoboAPIImplementor.getInvestedBuildPower ( )
Returns
how much we've invested in our current build target.

Implements WorldAPI.

Definition at line 748 of file RoboSim.java.

749  {
750  return actingRobot.investedPower;
751  }
Robot.GridCell [][] RoboSim.RoboAPIImplementor.getVisibleNeighborhood ( )

Gets a copy of the portion of the world visible to the robot. Range is equal to defense skill. Does not cost any power.

Returns
a 2-dimensional array containing a GridCell for each cell visible to the robot.

Implements WorldAPI.

Definition at line 965 of file RoboSim.java.

References RoboSim.RoboAPIImplementor.actingRobot, RoboSim.getSubGrid(), RoboSim.RobotData.player, RoboSim.sanitizeGrid(), and RoboSim.worldGrid.

966  {
967  //YAY! No parameters means NO ERROR CHECKING! YAY!
968  final int range = actingRobot.specs.defense;
969  final int xloc = actingRobot.assoc_cell.x_coord;
970  final int yloc = actingRobot.assoc_cell.y_coord;
971  final int x_left = (xloc - range < 0) ? 0 : (xloc - range);
972  final int x_right = (xloc + range > worldGrid.length-1) ? (worldGrid.length-1) : (xloc + range);
973  final int y_up = (yloc - range < 0) ? 0 : (yloc - range);
974  final int y_down = (yloc + range > worldGrid[0].length - 1) ? (worldGrid[0].length-1) : (yloc + range);
975  Robot.GridCell[][] to_return = sanitizeGrid(getSubGrid(x_left,y_up,x_right,y_down),actingRobot.player);
976 
977  //Set associated cell to SELF instead of ALLY
978  to_return[xloc - x_left][yloc - y_up].contents=Robot.GridObject.SELF;
979  return to_return;
980  }
SimGridCell[][] getSubGrid(int x_left, int y_up, int x_right, int y_down)
Definition: RoboSim.java:119
SimGridCell[][] worldGrid
Definition: RoboSim.java:93
static Robot.GridCell[][] sanitizeGrid(SimGridCell[][] simgrid, String player)
Definition: RoboSim.java:139

Here is the call graph for this function:

Robot.GridCell [][] RoboSim.RoboAPIImplementor.getWorld ( int  power) throws RoboSimExecutionException

Gets a copy of the entire world. Takes 3 power, plus additional if jamming is taking place (which won't be; jamming is not implemented).

Parameters
powerto spend attempting to get the world
Returns
a 2-dimensional array containing a GridCell for each cell in the world. Will be null if jamming has prevented the world from being retrieved.

Implements WorldAPI.

Definition at line 982 of file RoboSim.java.

References RoboSim.RoboAPIImplementor.actingRobot, RoboSim.RobotData.assoc_cell, RoboSim.getSubGrid(), RoboSim.RobotData.player, RoboSim.sanitizeGrid(), and RoboSim.worldGrid.

983  {
984  if(power!=3)
985  throw new RoboSimExecutionException("tried to get world with invalid power (not equal to 3)",actingRobot.player,actingRobot.assoc_cell);
986 
987  Robot.GridCell[][] to_return = sanitizeGrid(getSubGrid(0,0,worldGrid.length-1,worldGrid[0].length-1),actingRobot.player);
988 
989  //Set self to self instead of ally
990  to_return[actingRobot.assoc_cell.x_coord][actingRobot.assoc_cell.y_coord].contents=Robot.GridObject.SELF;
991  return to_return;
992  }
SimGridCell[][] getSubGrid(int x_left, int y_up, int x_right, int y_down)
Definition: RoboSim.java:119
SimGridCell[][] worldGrid
Definition: RoboSim.java:93
SimGridCell assoc_cell
Definition: RoboSim.java:67
static Robot.GridCell[][] sanitizeGrid(SimGridCell[][] simgrid, String player)
Definition: RoboSim.java:139

Here is the call graph for this function:

boolean RoboSim.RoboAPIImplementor.isAdjacent ( Robot.GridCell  adjacent_cell)
private

Utility method to check whether student's robot is adjacent to cell it is attacking. Note: diagonal cells are not adjacent.

Parameters
adjacent_cellcell to compare with student's robot's position

Definition at line 297 of file RoboSim.java.

References RoboSim.RoboAPIImplementor.actingRobot, RoboSim.RobotData.assoc_cell, and Robot.GridCell.x_coord.

Referenced by RoboSim.RoboAPIImplementor.charge(), RoboSim.RoboAPIImplementor.drop_capsule(), RoboSim.RoboAPIImplementor.meleeAttack(), RoboSim.RoboAPIImplementor.pick_up_capsule(), RoboSim.RoboAPIImplementor.rangedAttack(), and RoboSim.RoboAPIImplementor.setBuildTarget().

298  {
299  return (Math.abs(actingRobot.assoc_cell.x_coord-adjacent_cell.x_coord)==1 &&
300  actingRobot.assoc_cell.y_coord == adjacent_cell.y_coord ||
301  Math.abs(actingRobot.assoc_cell.y_coord-adjacent_cell.y_coord)==1 &&
302  actingRobot.assoc_cell.x_coord == adjacent_cell.x_coord);
303  }
SimGridCell assoc_cell
Definition: RoboSim.java:67

Here is the caller graph for this function:

Robot.AttackResult RoboSim.RoboAPIImplementor.meleeAttack ( int  power,
Robot.GridCell  adjacent_cell 
) throws RoboSimExecutionException

Melee attack: attack an adjacent grid cell

Parameters
powerPower to use for attack (may not exceed attack skill)
adjacent_cellAdjacent GridCell to attack
Returns
AttackResult indicating whether attack succeeded and/or destroyed target of attack.

Implements WorldAPI.

Definition at line 389 of file RoboSim.java.

References RoboSim.RoboAPIImplementor.actingRobot, RoboSim.RobotData.assoc_cell, Robot.GridCell.contents, RoboSim.RoboAPIImplementor.isAdjacent(), RoboSim.SimGridCell.occupant_data, RoboSim.RobotData.player, RoboSim.RoboAPIImplementor.processAttack(), RoboSim.RobotData.specs, RoboSim.RobotData.status, RoboSim.SimGridCell.wallforthealth, RoboSim.worldGrid, Robot.GridCell.x_coord, and Robot.GridCell.y_coord.

390  {
391  //Lots of error checking here (as everywhere...)
392  if(adjacent_cell==null)
393  throw new RoboSimExecutionException("passed null as argument to meleeAttack()",actingRobot.player);
394 
395  //Check that we're using a valid amount of power
396  if(power > actingRobot.status.power || power > actingRobot.specs.attack || power < 1)
397  throw new RoboSimExecutionException("attempted melee attack with illegal power level",actingRobot.player,actingRobot.assoc_cell);
398 
399  //Are cells adjacent?
400  if(!isAdjacent(adjacent_cell))
401  throw new RoboSimExecutionException("attempted to melee attack nonadjacent cell",actingRobot.player,actingRobot.assoc_cell);
402 
403  //Does cell exist in grid?
404  //(could put this in isAdjacent() method but want to give students more useful error messages)
405  if(adjacent_cell.x_coord > worldGrid.length || adjacent_cell.y_coord > worldGrid[0].length ||
406  adjacent_cell.x_coord < 0 || adjacent_cell.y_coord < 0)
407  throw new RoboSimExecutionException("passed invalid cell coordinates to meleeAttack()",actingRobot.player,actingRobot.assoc_cell,adjacent_cell);
408 
409  //Safe to use this now, checked for oob condition from student
410  SimGridCell cell_to_attack = worldGrid[adjacent_cell.x_coord][adjacent_cell.y_coord];
411 
412  //Is there an enemy, fort, or wall at the cell's location?
413  switch(cell_to_attack.contents)
414  {
415  case EMPTY:
416  throw new RoboSimExecutionException("attempted to attack empty cell",actingRobot.player,actingRobot.assoc_cell,cell_to_attack);
417  case BLOCKED:
418  throw new RoboSimExecutionException("attempted to attack blocked tile",actingRobot.player,actingRobot.assoc_cell,cell_to_attack);
419  case SELF:
420  if(cell_to_attack.occupant_data.player.equals(actingRobot.player))
421  throw new RoboSimExecutionException("attempted to attack ally",actingRobot.player,actingRobot.assoc_cell,cell_to_attack);
422  break;
423  case CAPSULE:
424  throw new RoboSimExecutionException("attempted to attack energy capsule",actingRobot.player,actingRobot.assoc_cell,cell_to_attack);
425  case ALLY:
426  throw new RuntimeException("ERROR in RoboSim.RoboAPIImplementor.meleeAttack(). This is probably not the student's fault. Contact Patrick Simmons about this message. (Not the Doobie Brother...)");
427  }
428 
429  //Okay, if we haven't thrown an exception, the cell is valid to attack. Perform the attack.
430  //Update this robot's charge status and power status.
431  actingRobot.status.charge-=power;
432  actingRobot.status.power-=power;
433 
434  //Begin calculation of our attack power
435  int raw_attack = actingRobot.specs.attack;
436 
437  //If we're outside a fort attacking someone in the fort, range penalty applies
438  if(cell_to_attack.wallforthealth > 0 && cell_to_attack.occupant_data!=null)
439  raw_attack/=2;
440 
441  //Attack adds power of attack to raw skill
442  int attack = raw_attack + power;
443 
444  //Process attack
445  return processAttack(attack,cell_to_attack,power);
446  }
Robot.AttackResult processAttack(int attack, SimGridCell cell_to_attack, int power)
Definition: RoboSim.java:323
SimGridCell[][] worldGrid
Definition: RoboSim.java:93
Robot.Robot_Status status
Definition: RoboSim.java:69
SimGridCell assoc_cell
Definition: RoboSim.java:67
boolean isAdjacent(Robot.GridCell adjacent_cell)
Definition: RoboSim.java:297
Robot.Robot_Specs specs
Definition: RoboSim.java:68

Here is the call graph for this function:

void RoboSim.RoboAPIImplementor.move ( int  steps,
Robot.Direction  way 
) throws RoboSimExecutionException

move: move robot

Parameters
stepshow far to move
waywhich way to move

Implements WorldAPI.

Definition at line 593 of file RoboSim.java.

References RoboSim.RoboAPIImplementor.actingRobot, RoboSim.RobotData.assoc_cell, RoboSim.RobotData.player, RoboSim.RobotData.status, and RoboSim.worldGrid.

594  {
595  if(steps<1)
596  return;
597 
598  int x_coord = actingRobot.assoc_cell.x_coord;
599  final int actor_x = x_coord;
600  int y_coord = actingRobot.assoc_cell.y_coord;
601  final int actor_y = y_coord;
602  switch(way)
603  {
604  case UP:
605  y_coord-=steps;
606  break;
607  case DOWN:
608  y_coord+=steps;
609  break;
610  case LEFT:
611  x_coord-=steps;
612  break;
613  case RIGHT:
614  x_coord+=steps;
615  break;
616  }
617 
618  //Is our destination in the map?
619  if(x_coord < 0 || x_coord > worldGrid.length || y_coord < 0 || y_coord > worldGrid[0].length)
620  throw new RoboSimExecutionException("attempted to move out of bounds",actingRobot.player,actingRobot.assoc_cell);
621 
622  //Is our destination empty?
623  if(worldGrid[x_coord][y_coord].contents!=Robot.GridObject.EMPTY && worldGrid[x_coord][y_coord].contents!=Robot.GridObject.FORT)
624  throw new RoboSimExecutionException("attempted to move onto illegal cell",actingRobot.player,actingRobot.assoc_cell,worldGrid[x_coord][y_coord]);
625 
626  //Are we approaching the fort from the right angle?
627  if(worldGrid[x_coord][y_coord].contents==Robot.GridObject.FORT && worldGrid[x_coord][y_coord].fort_orientation!=way)
628  throw new RoboSimExecutionException("attempted to move onto a fort from an illegal direction",actingRobot.player,actingRobot.assoc_cell,worldGrid[x_coord][y_coord]);
629 
630  //Okay, now we have to make sure each step is empty
631  final boolean x_left = x_coord<actor_x;
632  final boolean y_left = y_coord<actor_y;
633  if(x_coord!=actor_x)
634  {
635  for(int i=(x_left ? actor_x-1 : actor_x+1); i!=x_coord; i=(x_left ? i-1 : i+1))
636  if(worldGrid[i][y_coord].contents!=Robot.GridObject.EMPTY)
637  throw new RoboSimExecutionException("attempted to cross illegal cell",actingRobot.player,actingRobot.assoc_cell,worldGrid[i][y_coord]);
638  }
639  else
640  {
641  for(int i=(y_left ? actor_y-1 : actor_y+1); i!=y_coord; i=(y_left ? i-1 : i+1))
642  if(worldGrid[x_coord][i].contents!=Robot.GridObject.EMPTY)
643  throw new RoboSimExecutionException("attempted to cross illegal cell",actingRobot.player,actingRobot.assoc_cell,worldGrid[x_coord][i]);
644  }
645 
646  //Okay, now: do we have enough power/charge?
647  if(steps > actingRobot.status.power)
648  throw new RoboSimExecutionException("attempted to move too far (not enough power)",actingRobot.player,actingRobot.assoc_cell,worldGrid[x_coord][y_coord]);
649 
650  //Account for power cost
651  actingRobot.status.power-=steps;
652  actingRobot.status.charge-=steps;
653 
654  //Change position of robot.
655  actingRobot.assoc_cell.contents = Robot.GridObject.EMPTY;
656  actingRobot.assoc_cell.occupant_data = null;
657  actingRobot.assoc_cell = worldGrid[x_coord][y_coord];
658  actingRobot.assoc_cell.contents = Robot.GridObject.SELF;
659  actingRobot.assoc_cell.occupant_data = actingRobot;
660  }
SimGridCell[][] worldGrid
Definition: RoboSim.java:93
Definition: Robot.java:11
Robot.Robot_Status status
Definition: RoboSim.java:69
SimGridCell assoc_cell
Definition: RoboSim.java:67
void RoboSim.RoboAPIImplementor.pick_up_capsule ( Robot.GridCell  adjacent_cell) throws RoboSimExecutionException

pick_up_capsule: pick up a capsule

Parameters
adjacent_cellGridCell where capsule is that you want to pick up (must be adjacent)

Implements WorldAPI.

Definition at line 662 of file RoboSim.java.

References RoboSim.RoboAPIImplementor.actingRobot, RoboSim.RobotData.assoc_cell, Robot.GridCell.contents, RoboSim.RoboAPIImplementor.isAdjacent(), RoboSim.RobotData.player, RoboSim.RobotData.specs, RoboSim.RobotData.status, RoboSim.worldGrid, Robot.GridCell.x_coord, and Robot.GridCell.y_coord.

663  {
664  //Error checking, *sigh*...
665  //Can't pass us null
666  if(adjacent_cell==null)
667  throw new RoboSimExecutionException("passed null to pick_up_capsule()",actingRobot.player,actingRobot.assoc_cell);
668 
669  //Does cell exist in grid?
670  if(adjacent_cell.x_coord > worldGrid.length || adjacent_cell.y_coord > worldGrid[0].length || adjacent_cell.x_coord < 0 || adjacent_cell.y_coord < 0)
671  throw new RoboSimExecutionException("passed invalid cell coordinates to pick_up_capsule()",actingRobot.player,actingRobot.assoc_cell,adjacent_cell);
672 
673  //Cell in question
674  SimGridCell gridCell = worldGrid[adjacent_cell.x_coord][adjacent_cell.y_coord];
675 
676  //Cell must be adjacent
677  if(!isAdjacent(adjacent_cell))
678  throw new RoboSimExecutionException("attempted to pick up capsule in nonadjacent cell",actingRobot.player,actingRobot.assoc_cell,gridCell);
679 
680  //We need at least one power.
681  if(actingRobot.status.power==0)
682  throw new RoboSimExecutionException("attempted to pick up capsule with no power",actingRobot.player,actingRobot.assoc_cell,gridCell);
683 
684  //Is there actually a capsule there?
685  if(gridCell.contents!=Robot.GridObject.CAPSULE)
686  throw new RoboSimExecutionException("attempted to pick up capsule from cell with no capsule",actingRobot.player,actingRobot.assoc_cell,gridCell);
687 
688  //Do we have "room" for this capsule?
689  if(actingRobot.status.capsules.length+1>actingRobot.specs.attack+actingRobot.specs.defense)
690  throw new RoboSimExecutionException("attempted to pick up too many capsules",actingRobot.player,actingRobot.assoc_cell,gridCell);
691 
692  //If still here, yes.
693 
694  //Decrement our power
695  actingRobot.status.power--;
696 
697  //Put capsule in our inventory, delete it from world
698  actingRobot.status.capsules = ArrayUtility.addElement(actingRobot.status.capsules,gridCell.capsule_power);
699  gridCell.contents = Robot.GridObject.EMPTY;
700  gridCell.capsule_power = 0;
701  }
SimGridCell[][] worldGrid
Definition: RoboSim.java:93
Definition: Robot.java:11
Robot.Robot_Status status
Definition: RoboSim.java:69
SimGridCell assoc_cell
Definition: RoboSim.java:67
boolean isAdjacent(Robot.GridCell adjacent_cell)
Definition: RoboSim.java:297
Robot.Robot_Specs specs
Definition: RoboSim.java:68

Here is the call graph for this function:

Robot.AttackResult RoboSim.RoboAPIImplementor.processAttack ( int  attack,
SimGridCell  cell_to_attack,
int  power 
) throws RoboSimExecutionException
private

Process attack, assigning damage and deleting destroyed objects if necessary.

Parameters
attackattack skill of attacker (including bonuses/penalties)
cell_to_attackcell attacker is attacking containing enemy or obstacle
damagedamage if attack hits

Definition at line 323 of file RoboSim.java.

References RoboSim.RoboAPIImplementor.calculateHit(), RoboSim.RoboAPIImplementor.RoboAPIImplementor(), RoboSim.RoboAPIImplementor.setBuildTarget(), RoboSim.turnOrder, and RoboSim.turnOrder_pos.

Referenced by RoboSim.RoboAPIImplementor.capsuleAttack(), RoboSim.RoboAPIImplementor.meleeAttack(), and RoboSim.RoboAPIImplementor.rangedAttack().

324  {
325  //Holds result of attack
326  Robot.AttackResult to_return = Robot.AttackResult.MISSED;
327 
328  //Calculate defense skill of opponent
329  int defense = 0;
330  switch(cell_to_attack.contents)
331  {
332  case SELF:
333  defense = cell_to_attack.occupant_data.specs.defense + cell_to_attack.occupant_data.status.defense_boost;
334  break;
335 
336  case FORT:
337  case WALL:
338  defense = 10;
339  break;
340  }
341 
342 
343  //If we hit, damage the opponent
344  if(calculateHit(attack,defense))
345  {
346  //We hit
347  to_return = Robot.AttackResult.HIT;
348 
349  if(cell_to_attack.occupant_data!=null)
350  {
351  //we're a robot
352  for(int i=0; true; i++)
353  if(turnOrder.get(i)==cell_to_attack.occupant_data)
354  {
355  if((cell_to_attack.occupant_data.status.health-=power)<=0)
356  {
357  //We destroyed the opponent!
358  to_return = Robot.AttackResult.DESTROYED_TARGET;
359 
360  //Handle in-progress build, reusing setBuildTarget() to handle interruption of build due to death
361  (new RoboAPIImplementor(cell_to_attack.occupant_data)).setBuildTarget(null,null);
362 
363  //Handle cell
364  cell_to_attack.occupant_data = null;
365  cell_to_attack.contents = cell_to_attack.wallforthealth>0 ? Robot.GridObject.FORT : Robot.GridObject.EMPTY;
366 
367  //Handle turnOrder position
368  turnOrder.remove(i);
369  if(i<turnOrder_pos)
370  turnOrder_pos--;
371  }
372  break;
373  }
374  }
375  else
376  if((cell_to_attack.wallforthealth-=power)<=0)
377  {
378  //We destroyed the target!
379  to_return = Robot.AttackResult.DESTROYED_TARGET;
380 
381  cell_to_attack.wallforthealth = 0;
382  cell_to_attack.contents = Robot.GridObject.EMPTY;
383  }
384  }
385 
386  return to_return;
387  }
void setBuildTarget(Robot.BuildStatus status, Robot.GridCell location)
Definition: RoboSim.java:833
ArrayList< RobotData > turnOrder
Definition: RoboSim.java:94
RoboAPIImplementor(RobotData actingRobot_)
Definition: RoboSim.java:290
boolean calculateHit(int attack, int defense)
Definition: RoboSim.java:311
int turnOrder_pos
Definition: RoboSim.java:95

Here is the call graph for this function:

Here is the caller graph for this function:

Robot.AttackResult RoboSim.RoboAPIImplementor.rangedAttack ( int  power,
Robot.GridCell  nonadjacent_cell 
) throws RoboSimExecutionException

Ranged attack: attack nonadjacent grid cell within certain range

Parameters
powerPower to use for attack (may not exceed attack skill)
nonadjacent_cellnon-adjacent GridCell to attack
Returns
AttackResult indicating whether attack succeeded and/or destroyed target of attack.

Implements WorldAPI.

Definition at line 448 of file RoboSim.java.

References RoboSim.RoboAPIImplementor.actingRobot, RoboSim.RobotData.assoc_cell, RoboSim.RoboAPIImplementor.isAdjacent(), RoboSim.RobotData.player, RoboSim.RoboAPIImplementor.processAttack(), RoboSim.RobotData.specs, RoboSim.RobotData.status, RoboSim.worldGrid, Robot.GridCell.x_coord, and Robot.GridCell.y_coord.

449  {
450  //Lots of error checking here (as everywhere...)
451  if(nonadjacent_cell==null)
452  throw new RoboSimExecutionException("passed null as argument to rangedAttack()",actingRobot.player,actingRobot.assoc_cell);
453 
454 
455  //Check that we're using a valid amount of power
456  if(power > actingRobot.status.power || power > actingRobot.specs.attack || power < 1)
457  throw new RoboSimExecutionException("attempted ranged attack with illegal power level",actingRobot.player,actingRobot.assoc_cell);
458 
459  //Does cell exist in grid?
460  //(could put this in isAdjacent() method but want to give students more useful error messages)
461  if(nonadjacent_cell.x_coord > worldGrid.length || nonadjacent_cell.y_coord > worldGrid[0].length ||
462  nonadjacent_cell.x_coord < 0 || nonadjacent_cell.y_coord < 0)
463  throw new RoboSimExecutionException("passed invalid cell coordinates to rangedAttack()",actingRobot.player,actingRobot.assoc_cell,nonadjacent_cell);
464 
465  //Are cells nonadjacent?
466  if(isAdjacent(nonadjacent_cell))
467  throw new RoboSimExecutionException("attempted to range attack adjacent cell",actingRobot.player,actingRobot.assoc_cell);
468 
469  //Safe to use this now, checked for oob condition from student
470  SimGridCell cell_to_attack = worldGrid[nonadjacent_cell.x_coord][nonadjacent_cell.y_coord];
471 
472  //Do we have a "clear shot"?
473  Robot.GridCell[] shortest_path = Robot.RobotUtility.findShortestPath(actingRobot.assoc_cell,cell_to_attack,worldGrid);
474  if(shortest_path==null) //we don't have a clear shot
475  throw new RoboSimExecutionException("attempted to range attack cell with no clear path",actingRobot.player,actingRobot.assoc_cell,cell_to_attack);
476  else if(shortest_path.length>actingRobot.specs.defense) //out of range
477  throw new RoboSimExecutionException("attempted to range attack cell more than (defense) tiles away",actingRobot.player,actingRobot.assoc_cell,cell_to_attack);
478 
479  //Is there an enemy, fort, or wall at the cell's location?
480  switch(cell_to_attack.contents)
481  {
482  case EMPTY:
483  throw new RoboSimExecutionException("attempted to attack empty cell",actingRobot.player,actingRobot.assoc_cell,cell_to_attack);
484  case BLOCKED:
485  throw new RoboSimExecutionException("attempted to attack blocked tile",actingRobot.player,actingRobot.assoc_cell,cell_to_attack);
486  case SELF:
487  if(cell_to_attack.occupant_data.player.equals(actingRobot.player))
488  throw new RoboSimExecutionException("attempted to attack ally",actingRobot.player,actingRobot.assoc_cell,cell_to_attack);
489  break;
490  case CAPSULE:
491  throw new RoboSimExecutionException("attempted to attack energy capsule",actingRobot.player,actingRobot.assoc_cell,cell_to_attack);
492  case ALLY:
493  throw new RuntimeException("ERROR in RoboSim.RoboAPIImplementor.rangedAttack(). This is probably not the student's fault. Contact Patrick Simmons about this message. (Not the Doobie Brother...)");
494  }
495 
496  //Okay, if we haven't thrown an exception, the cell is valid to attack. Perform the attack.
497  //Update this robot's charge status.
498  actingRobot.status.charge-=power;
499  actingRobot.status.power-=power;
500 
501  //Begin calculation of our attack power
502  int raw_attack = actingRobot.specs.attack/2;
503 
504  //Attack adds power of attack to raw skill
505  int attack = raw_attack + power;
506 
507  //Process attack
508  return processAttack(attack,cell_to_attack,power);
509  }
Robot.AttackResult processAttack(int attack, SimGridCell cell_to_attack, int power)
Definition: RoboSim.java:323
SimGridCell[][] worldGrid
Definition: RoboSim.java:93
Robot.Robot_Status status
Definition: RoboSim.java:69
SimGridCell assoc_cell
Definition: RoboSim.java:67
boolean isAdjacent(Robot.GridCell adjacent_cell)
Definition: RoboSim.java:297
Robot.Robot_Specs specs
Definition: RoboSim.java:68

Here is the call graph for this function:

void RoboSim.RoboAPIImplementor.repair ( int  power) throws RoboSimExecutionException

Spend power to repair yourself. 2 power restores 1 health.

Parameters
poweramount of power to spend on repairs. Should be even.

Implements WorldAPI.

Definition at line 892 of file RoboSim.java.

References RoboSim.RoboAPIImplementor.actingRobot, RoboSim.RobotData.assoc_cell, RoboSim.RobotData.player, RoboSim.RobotData.specs, and RoboSim.RobotData.status.

893  {
894  if(power > actingRobot.status.power || power < 0)
895  throw new RoboSimExecutionException("attempted to apply invalid power to repair task",actingRobot.player,actingRobot.assoc_cell);
896  actingRobot.status.charge-=power;
897  actingRobot.status.power-=power;
898  actingRobot.status.health+=power/2;
899 
900  //Can't have more health than charge skill*10
901  if(actingRobot.status.health > actingRobot.specs.charge*10)
902  actingRobot.status.health = actingRobot.specs.charge*10;
903  }
Robot.Robot_Status status
Definition: RoboSim.java:69
SimGridCell assoc_cell
Definition: RoboSim.java:67
Robot.Robot_Specs specs
Definition: RoboSim.java:68
void RoboSim.RoboAPIImplementor.scanEnemy ( Robot.Robot_Specs  enemySpecs,
Robot.Robot_Status  enemyStatus,
Robot.GridCell  toScan 
) throws RoboSimExecutionException

Scans an enemy (or ally), retrieving information about the robot. The cell scanned must be visible (within defense cells from us).
Takes 1 power.

Parameters
enemySpecsempty Robot_Specs object to be filled in
enemyStatusempty Robot_Status object to be filled in
toScancell containing robot we want to scan

Implements WorldAPI.

Definition at line 994 of file RoboSim.java.

References RoboSim.RoboAPIImplementor.actingRobot, RoboSim.RobotData.assoc_cell, Robot.GridCell.contents, RoboSim.RobotData.player, RoboSim.RobotData.specs, RoboSim.RobotData.status, RoboSim.worldGrid, Robot.GridCell.x_coord, and Robot.GridCell.y_coord.

995  {
996  if(enemySpecs==null || enemyStatus==null || toScan==null
997  || toScan.x_coord < 0 || toScan.x_coord >= worldGrid.length || toScan.y_coord < 0 || toScan.y_coord >= worldGrid[0].length || actingRobot.status.power==0)
998  throw new RoboSimExecutionException("Invalid parameters passed to scanEnemy()",actingRobot.player,actingRobot.assoc_cell);
999 
1000  SimGridCell cell = worldGrid[toScan.x_coord][toScan.y_coord];
1001 
1002  //Are we within range?
1003  if(Math.abs(actingRobot.assoc_cell.x_coord - cell.x_coord) > actingRobot.specs.defense || Math.abs(actingRobot.assoc_cell.y_coord - cell.y_coord) > actingRobot.specs.defense)
1004  throw new RoboSimExecutionException("attempted to scan farther than range", actingRobot.player, actingRobot.assoc_cell);
1005 
1006  //Is there a robot in this cell?
1007  if(cell.contents != Robot.GridObject.SELF)
1008  throw new RoboSimExecutionException("attempted to scan invalid cell (no robot in cell)", actingRobot.player, actingRobot.assoc_cell, cell);
1009 
1010  //Register cost
1011  actingRobot.status.power--;
1012  actingRobot.status.charge--;
1013 
1014  //Okay, we're good. Fill in the data.
1015  enemySpecs.attack = cell.occupant_data.specs.attack;
1016  enemySpecs.defense = cell.occupant_data.specs.defense;
1017  enemySpecs.power = cell.occupant_data.specs.power;
1018  enemySpecs.charge = cell.occupant_data.specs.charge;
1019  enemyStatus.power = cell.occupant_data.status.power;
1020  enemyStatus.charge = cell.occupant_data.status.charge;
1021  enemyStatus.health = cell.occupant_data.status.health;
1022  enemyStatus.defense_boost = cell.occupant_data.status.defense_boost;
1023  enemyStatus.capsules = cell.occupant_data.status.capsules.clone();
1024  }
SimGridCell[][] worldGrid
Definition: RoboSim.java:93
Definition: Robot.java:11
Robot.Robot_Status status
Definition: RoboSim.java:69
SimGridCell assoc_cell
Definition: RoboSim.java:67
Robot.Robot_Specs specs
Definition: RoboSim.java:68
void RoboSim.RoboAPIImplementor.sendMessage ( byte[]  message,
int  power 
) throws RoboSimExecutionException

Spend additional power to get radio messages unavailable because of jamming.

Parameters
poweramount of power to spend to attempt to overcome jamming
Returns
messages received after additional power spent. Will include all messages included in simulator's call to act(). May be null if no messages were received. Sends a message to an ally or allies.
Parameters
message64-byte array containing message to transmit
poweramount of power to use for sending message

Implements WorldAPI.

Definition at line 937 of file RoboSim.java.

References RoboSim.RoboAPIImplementor.actingRobot, RoboSim.RobotData.assoc_cell, RoboSim.RobotData.player, RoboSim.turnOrder, and RoboSim.worldGrid.

938  {
939  if(power < 1 || power > 2)
940  throw new RoboSimExecutionException("attempted to send message with invalid power", actingRobot.player,actingRobot.assoc_cell);
941 
942  if(message.length!=64)
943  throw new RoboSimExecutionException("attempted to send message byte array of incorrect length", actingRobot.player,actingRobot.assoc_cell);
944 
945  Robot.GridCell target = null;
946  if(power==1)
947  {
948  target = Robot.RobotUtility.findNearestAlly(actingRobot.assoc_cell,worldGrid);
949  if(target!=null)
950  {
951  /*There's a way to "cheat" here and set up a power-free comm channel
952  *between two allied robots. If you can find it ... let me know, and
953  *you'll get extra credit :). Additional credit for a bugfix.*/
954  ((SimGridCell)(target)).occupant_data.buffered_radio.add(message);
955  }
956  return;
957  }
958  else //power==2
959  for(RobotData x : turnOrder)
960  if(x!=actingRobot && x.player.equals(actingRobot.player))
961  x.buffered_radio.add(message);
962  }
ArrayList< RobotData > turnOrder
Definition: RoboSim.java:94
SimGridCell[][] worldGrid
Definition: RoboSim.java:93
SimGridCell assoc_cell
Definition: RoboSim.java:67
void RoboSim.RoboAPIImplementor.setBuildTarget ( Robot.BuildStatus  status,
Robot.GridCell  location 
) throws RoboSimExecutionException

Tells the simulator the robot is beginning to build something in an adjacent cell (or, for capsules, inside itself).
In order to mark a capsule or robot as "done", call this method with both parameters null. This will destroy any in-progress build.

Note that you must not move from your current cell while in the process of building anything other than a capsule. If you do, you will lose any in-progress work on a wall or fort, and a robot will be automatically finalized with however many skill points you've invested up to that point.

Parameters
statuswhat we're going to start building (or, in the case of an energy capsule, resume building)
locationwhere to direct our building efforts. Must be an adjacent, empty location, or null if status=capsule.

Implements WorldAPI.

Definition at line 833 of file RoboSim.java.

Referenced by RoboSim.RoboAPIImplementor.processAttack().

834  {
835  setBuildTarget(status,location,null);
836  }
void setBuildTarget(Robot.BuildStatus status, Robot.GridCell location)
Definition: RoboSim.java:833

Here is the caller graph for this function:

void RoboSim.RoboAPIImplementor.setBuildTarget ( Robot.BuildStatus  status,
Robot.GridCell  location,
byte[]  creation_message 
) throws RoboSimExecutionException

Tells the simulator the robot is beginning to build something in an adjacent cell (or, for capsules, inside itself).
In order to mark a capsule or robot as "done", call this method with both parameters null. This will destroy any in-progress build.

Note that you must not move from your current cell while in the process of building anything other than a capsule. If you do, you will lose any in-progress work on a wall or fort, and a robot will be automatically finalized with however many skill points you've invested up to that point.

Parameters
statuswhat we're going to start building (or, in the case of an energy capsule, resume building)
locationwhere to direct our building efforts. Must be an adjacent, empty location, or null if status=capsule.
creation_messagemessage to send to newly created robot (if we're finalizing one)

Implements WorldAPI.

Definition at line 838 of file RoboSim.java.

References RoboSim.RoboAPIImplementor.actingRobot, RoboSim.RobotData.assoc_cell, Robot.GridCell.contents, RoboSim.RoboAPIImplementor.finalizeBuilding(), RoboSim.RoboAPIImplementor.isAdjacent(), RoboSim.RobotData.player, RoboSim.RobotData.whatBuilding, RoboSim.worldGrid, Robot.GridCell.x_coord, and Robot.GridCell.y_coord.

839  {
840  //If we're in the middle of building something, finalize it.
841  if(actingRobot.whatBuilding!=null)
842  finalizeBuilding(message);
843 
844  //Error checking, *sigh*...
845 
846  //Does cell exist in grid?
847  if(location!=null && (location.x_coord > worldGrid.length || location.y_coord > worldGrid[0].length || location.x_coord < 0 || location.y_coord < 0))
848  throw new RoboSimExecutionException("passed invalid cell coordinates to setBuildTarget()",actingRobot.player,actingRobot.assoc_cell,location);
849 
850  //Cell in question
851  SimGridCell gridCell = (location!=null ? worldGrid[location.x_coord][location.y_coord] : null);
852 
853  //Update status
854  actingRobot.whatBuilding = status;
855  actingRobot.investedPower = 0;
856  actingRobot.invested_assoc_cell = gridCell;
857 
858  //CAN pass us null, so special-case it
859  if(location==null)
860  {
861  //We must be building capsule, then.
862  if(actingRobot.whatBuilding!=null && actingRobot.whatBuilding!=Robot.BuildStatus.CAPSULE)
863  throw new RoboSimExecutionException("passed null to setBuildTarget() location with non-null and non-capsule build target",actingRobot.player,actingRobot.assoc_cell);
864  return;
865  }
866 
867  //If location NOT null, must not be building capsule
868  if(status == null || status == Robot.BuildStatus.CAPSULE)
869  throw new RoboSimExecutionException("attempted to target capsule or null building on non-null adjacent cell",actingRobot.player,actingRobot.assoc_cell,location);
870 
871  //Cell must be adjacent
872  if(!isAdjacent(location))
873  throw new RoboSimExecutionException("attempted to set build target to nonadjacent cell",actingRobot.player,actingRobot.assoc_cell,gridCell);
874 
875  //Is the cell empty?
876  if(gridCell.contents!=Robot.GridObject.EMPTY)
877  throw new RoboSimExecutionException("attempted to set build target to nonempty cell",actingRobot.player,actingRobot.assoc_cell,gridCell);
878 
879  //Okay, block off cell since we're building there now.
880  gridCell.contents = Robot.GridObject.BLOCKED;
881  }
void finalizeBuilding(byte[] creation_message)
Definition: RoboSim.java:753
SimGridCell[][] worldGrid
Definition: RoboSim.java:93
Definition: Robot.java:11
SimGridCell assoc_cell
Definition: RoboSim.java:67
boolean isAdjacent(Robot.GridCell adjacent_cell)
Definition: RoboSim.java:297
Robot.BuildStatus whatBuilding
Definition: RoboSim.java:74

Here is the call graph for this function:

Member Data Documentation


The documentation for this class was generated from the following file: