DefenderBot.java
Go to the documentation of this file.
1 
7 public class DefenderBot implements Robot
8 {
9  private Robot_Specs my_specs;
10 
11  public Robot_Specs createRobot(WorldAPI api, int skill_points, byte[] message)
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  }
30 
31  public void act(WorldAPI api, Robot_Status status, byte[][] received_radio)
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  }
79 }
Definition: Robot.java:11
Robot_Specs createRobot(WorldAPI api, int skill_points, byte[] message)
Robot_Specs my_specs
Definition: DefenderBot.java:9
void act(WorldAPI api, Robot_Status status, byte[][] received_radio)