DefenderBot.hpp
Go to the documentation of this file.
1 #include "Robot.hpp"
2 #include <iostream>
3 
10 using std::cerr;
11 using std::endl;
12 
13 class DefenderBot : public Robot
14 {
15 private:
17 
18 public:
19  Robot_Specs createRobot(WorldAPI* api, int skill_points, vector<uint8_t> message)
20  {
21  Robot_Specs to_return;
22  to_return.attack = 0;
23  to_return.power = to_return.charge = skill_points/3;
24  to_return.defense = skill_points/3 + skill_points%3;
25 
26  //This handles the pathological case where skill_points<3
27  if(skill_points<3)
28  {
29  to_return.defense = 0;
30  to_return.charge = 1;
31  to_return.power = skill_points - to_return.charge;
32  }
33 
34  //Keep track of our specs; simulator won't do it for us!
35  my_specs = to_return;
36  return to_return;
37  }
38 
39  void act(WorldAPI& api, Robot_Status status, vector<vector<uint8_t>> received_radio)
40  {
41  int remaining_power = status.power;
42  int remaining_charge = status.charge;
43 
44  //Are we damaged
45  if(status.health!=my_specs.charge*10)
46  {
47  int repair_amount = (my_specs.charge*10 - status.health) * 2;
48  if(repair_amount > status.power)
49  repair_amount = status.power - status.power%2;
50  try
51  {
52  api.repair(repair_amount);
53  }
55  {
56  cerr << e.msg << endl;
57  }
58  remaining_power-=repair_amount;
59  remaining_charge-=repair_amount;
60  }
61 
62  /*Next priority is charging ourselves
63  We will automatically charge (charge skill) amount next
64  turn, so limit amount of power we save for charging to the
65  minimum required to get to (charge skill*9).
66  */
67  if(remaining_charge < my_specs.charge*9)
68  {
69  //How much to save?
70  int to_save = my_specs.charge*9 - remaining_charge;
71  if(to_save > remaining_power)
72  to_save = remaining_power;
73  remaining_power-=to_save;
74  }
75 
76  //Any remaining power we put toward defense
77  if(remaining_power > 0)
78  try
79  {
80  api.defend((remaining_power <= my_specs.defense) ? remaining_power : my_specs.defense);
81  }
83  {
84  cerr << e.msg << endl;
85  }
86  }
87 };
Definition: Robot.hpp:19
Robot_Specs my_specs
Definition: DefenderBot.hpp:16
void act(WorldAPI &api, Robot_Status status, vector< vector< uint8_t >> received_radio)
Definition: DefenderBot.hpp:39
virtual void defend(int power)=0
Robot_Specs createRobot(WorldAPI *api, int skill_points, vector< uint8_t > message)
Definition: DefenderBot.hpp:19
virtual void repair(int power)=0