DefenderBot Class Reference
Inheritance diagram for DefenderBot:
Collaboration diagram for DefenderBot:

Public Member Functions

Robot_Specs createRobot (WorldAPI api, int skill_points, byte[] message)
 
void act (WorldAPI api, Robot_Status status, byte[][] received_radio)
 

Private Attributes

Robot_Specs my_specs
 

Detailed Description

DefenderBot: Robot implementation which just sits there and never moves or attacks. Uses its power to repair itself if it's damaged, then to charge if it's not fully charged, then to defend itself.

Definition at line 7 of file DefenderBot.java.

Member Function Documentation

void DefenderBot.act ( WorldAPI  api,
Robot_Status  status,
byte  received_radio[][] 
)

Each turn, this method is called to allow your robot to act.

Parameters
apia reference to a WorldAPI object you can use to interact with the simulator.
statusa reference to a Robot_Status object containing information about your current health and energy level
received_radiothe radio signals you have received this round. Each message is exactly 64 bytes long. You may be able to receive additional radio signals by calling getMessages() with a nonzero power if you are being jammed.

Implements Robot.

Definition at line 31 of file DefenderBot.java.

References Robot.Robot_Specs.charge, Robot.Robot_Specs.defense, Robot.Robot_Status.health, my_specs, and Robot.Robot_Status.power.

32  {
33  int remaining_power = status.power;
34  int remaining_charge = status.charge;
35 
36  //Are we damaged
37  if(status.health!=my_specs.charge*10)
38  {
39  int repair_amount = (my_specs.charge*10 - status.health) * 2;
40  if(repair_amount > status.power)
41  repair_amount = status.power - status.power%2;
42  try
43  {
44  api.repair(repair_amount);
45  }
46  catch(RoboSim.RoboSimExecutionException e)
47  {
48  System.out.println(e.getMessage());
49  }
50  remaining_power-=repair_amount;
51  remaining_charge-=repair_amount;
52  }
53 
54  /*Next priority is charging ourselves
55  We will automatically charge (charge skill) amount next
56  turn, so limit amount of power we save for charging to the
57  minimum required to get to (charge skill*9).
58  */
59  if(remaining_charge < my_specs.charge*9)
60  {
61  //How much to save?
62  int to_save = my_specs.charge*9 - remaining_charge;
63  if(to_save > remaining_power)
64  to_save = remaining_power;
65  remaining_power-=to_save;
66  }
67 
68  //Any remaining power we put toward defense
69  if(remaining_power > 0)
70  try
71  {
72  api.defend((remaining_power <= my_specs.defense) ? remaining_power : my_specs.defense);
73  }
74  catch(RoboSim.RoboSimExecutionException e)
75  {
76  System.out.println(e.getMessage());
77  }
78  }
Robot_Specs my_specs
Definition: DefenderBot.java:9
Robot_Specs DefenderBot.createRobot ( WorldAPI  api,
int  skill_points,
byte[]  message 
)

Entry point for your robot on its creation

Parameters
apia reference to a WorldAPI object you can use to interact with the simulator (currently unused)
skill_pointsthe number of skill points your robot is allowed to have.
messagea 64-byte message from the robot who created you. If you were created by the simulator, the first two bytes of the message will contain your ID, which is unique among the IDs of all your team's robots created by the world. Otherwise, the format of the message is unspecified: it's up to you to define it.
Returns
You are to return a Robot_Specs object containing the allocation of skill points you have chosen for yourself.

Implements Robot.

Definition at line 11 of file DefenderBot.java.

References my_specs.

12  {
13  Robot_Specs to_return = new Robot_Specs();
14  to_return.attack = 0;
15  to_return.power = to_return.charge = skill_points/3;
16  to_return.defense = skill_points/3 + skill_points%3;
17 
18  //This handles the pathological case where skill_points<3
19  if(skill_points<3)
20  {
21  to_return.defense = 0;
22  to_return.charge = 1;
23  to_return.power = skill_points - to_return.charge;
24  }
25 
26  //Keep track of our specs; simulator won't do it for us!
27  my_specs = to_return;
28  return to_return;
29  }
Robot_Specs my_specs
Definition: DefenderBot.java:9

Member Data Documentation

Robot_Specs DefenderBot.my_specs
private

Definition at line 9 of file DefenderBot.java.

Referenced by act(), and createRobot().


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