DefenderBot Class Referenceabstract

#include <DefenderBot.hpp>

Inheritance diagram for DefenderBot:
Collaboration diagram for DefenderBot:

Public Member Functions

Robot_Specs createRobot (WorldAPI *api, int skill_points, vector< uint8_t > message)
 
void act (WorldAPI &api, Robot_Status status, vector< vector< uint8_t >> received_radio)
 
virtual Robot_Specs createRobot (WorldAPI *api, int skill_points, std::vector< std::uint8_t > message)=0
 
virtual void act (WorldAPI &api, Robot_Status status, std::vector< std::vector< std::uint8_t > > received_radio)=0
 

Private Attributes

Robot_Specs my_specs
 

Detailed Description

Definition at line 13 of file DefenderBot.hpp.

Member Function Documentation

void DefenderBot::act ( WorldAPI api,
Robot_Status  status,
vector< vector< uint8_t >>  received_radio 
)
inline

Definition at line 39 of file DefenderBot.hpp.

References robot_api::Robot_Specs::charge, robot_api::Robot_Status::charge, WorldAPI::defend(), robot_api::Robot_Specs::defense, robot_api::Robot_Status::health, robot_api::RoboSimExecutionException::msg, robot_api::Robot_Status::power, and WorldAPI::repair().

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  }
Robot_Specs my_specs
Definition: DefenderBot.hpp:16
virtual void defend(int power)=0
virtual void repair(int power)=0

Here is the call graph for this function:

virtual void Robot::act ( WorldAPI api,
Robot_Status  status,
std::vector< std::vector< std::uint8_t > >  received_radio 
)
pure virtualinherited

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 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.

Referenced by RoboSim::executeSingleTimeStep().

Here is the caller graph for this function:

Robot_Specs DefenderBot::createRobot ( WorldAPI api,
int  skill_points,
vector< uint8_t >  message 
)
inline

Definition at line 19 of file DefenderBot.hpp.

References robot_api::Robot_Specs::attack, robot_api::Robot_Specs::charge, robot_api::Robot_Specs::defense, and robot_api::Robot_Specs::power.

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  }
Robot_Specs my_specs
Definition: DefenderBot.hpp:16
virtual Robot_Specs Robot::createRobot ( WorldAPI api,
int  skill_points,
std::vector< std::uint8_t >  message 
)
pure virtualinherited

Entry point for your robot on its creation

Parameters
apia pointer to a WorldAPI object you can use to interact with the simulator, if it's not NULL (currently unused and always NULL)
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.

Referenced by RoboSim::RoboAPIImplementor::finalizeBuilding(), and RoboSim::RoboSim().

Here is the caller graph for this function:

Member Data Documentation

Robot_Specs DefenderBot::my_specs
private

Definition at line 16 of file DefenderBot.hpp.


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