DemoBot Class Referenceabstract

#include <DemoBot.hpp>

Inheritance diagram for DemoBot:
Collaboration diagram for DemoBot:

Public Member Functions

Robot_Specs createRobot (WorldAPI *api, int skill_points, vector< uint8_t > message)
 
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 Member Functions

void act (WorldAPI &api, Robot_Status status, vector< vector< uint8_t >> received_radio)
 

Static Private Member Functions

static bool isAdjacent (const GridCell &c1, const GridCell &c2)
 
static int searchAndDestroy (GridCell &self, vector< vector< GridCell >> neighbors, WorldAPI &api, int remaining_power)
 

Private Attributes

Robot_Specs my_specs
 

Detailed Description

DemoBot: Demo Robot implementation for OffenseBot

Definition at line 12 of file DemoBot.hpp.

Member Function Documentation

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:

void DemoBot::act ( WorldAPI api,
Robot_Status  status,
vector< vector< uint8_t >>  received_radio 
)
inlineprivate

Definition at line 97 of file DemoBot.hpp.

References robot_api::Robot_Status::charge, WorldAPI::getVisibleNeighborhood(), WorldAPI::getWorld(), robot_api::RoboSimExecutionException::msg, robot_api::Robot_Status::power, and robot_api::SELF.

98  {
99  int remaining_power = status.power;
100  int remaining_charge = status.charge;
101 
102  try
103  {
104  auto neighbors = api.getVisibleNeighborhood();
105 
106  //What's our position?
107  GridCell self;
108  for(int i=0; i<neighbors.size(); i++)
109  for(int j=0; j<neighbors[0].size(); j++)
110  if(neighbors[i][j].contents==SELF)
111  {
112  self=neighbors[i][j];
113  break;
114  }
115 
116  //Visible and reachable enemy? Attack!
117  remaining_power = searchAndDestroy(self,neighbors,api,remaining_power);
118 
119  //Do we still have power? Then we haven't attacked anything.
120  //Perhaps we couldn't find an enemy...
121  if(remaining_power > 3)
122  {
123  auto world = api.getWorld(3);
124  remaining_power-=3;
125  searchAndDestroy(self,world,api,remaining_power);
126  }
127  }
129  {
130  cerr << e.msg << endl;
131  }
132  }
virtual vector< vector< GridCell > > getVisibleNeighborhood()=0
virtual vector< vector< GridCell > > getWorld(int power)=0
static int searchAndDestroy(GridCell &self, vector< vector< GridCell >> neighbors, WorldAPI &api, int remaining_power)
Definition: DemoBot.hpp:58

Here is the call graph for this function:

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

Definition at line 18 of file DemoBot.hpp.

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

19  {
20  Robot_Specs to_return;
21  to_return.attack = to_return.defense = to_return.power = to_return.charge = skill_points/4;
22  //This handles the pathological case where skill_points<4
23  if(skill_points<4)
24  {
25  to_return.charge = 1;
26  skill_points--;
27  if(skill_points > 0)
28  {
29  to_return.power = 1;
30  skill_points--;
31  }
32  if(skill_points > 0)
33  {
34  to_return.defense = 1;
35  skill_points--;
36  }
37  }
38  else
39  {
40  skill_points-=(skill_points/4)*4;
41  to_return.attack += skill_points;
42  }
43 
44  //Keep track of our specs; simulator won't do it for us!
45  my_specs = to_return;
46  return to_return;
47  }
Robot_Specs my_specs
Definition: DemoBot.hpp:15
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:

static bool DemoBot::isAdjacent ( const GridCell c1,
const GridCell c2 
)
inlinestaticprivate

Definition at line 50 of file DemoBot.hpp.

References robot_api::GridCell::x_coord, and robot_api::GridCell::y_coord.

51  {
52  return (abs(c1.x_coord-c2.x_coord)==1 &&
53  c1.y_coord == c2.y_coord ||
54  abs(c1.y_coord-c2.y_coord)==1 &&
55  c1.x_coord == c2.x_coord);
56  }
static int DemoBot::searchAndDestroy ( GridCell self,
vector< vector< GridCell >>  neighbors,
WorldAPI api,
int  remaining_power 
)
inlinestaticprivate

Definition at line 58 of file DemoBot.hpp.

References robot_api::DOWN, robot_api::ENEMY, robot_api::RobotUtility::findShortestPath(), robot_api::LEFT, WorldAPI::meleeAttack(), WorldAPI::move(), robot_api::RIGHT, and robot_api::UP.

59  {
60  //cout << "Self: (" << self.x_coord << "," << self.y_coord << ")" << endl;
61  for(int i=0; i<neighbors.size(); i++)
62  for(int j=0; j<neighbors[0].size(); j++)
63  if(neighbors[i][j].contents==ENEMY)
64  {
65  auto path = RobotUtility::findShortestPath(self,neighbors[i][j],neighbors);
66  if(path.size())
67  {
68  auto end_pos = path.end();
69  end_pos--;
70  for(auto k=path.begin(); k!=end_pos && remaining_power > 0; k++)
71  {
72  //cout << "Move: (" << (*k)->x_coord << "," << (*k)->y_coord << ")";
73  Direction way;
74  if((*k)->x_coord < self.x_coord)
75  way = LEFT;
76  else if((*k)->x_coord > self.x_coord)
77  way = RIGHT;
78  else if((*k)->y_coord < self.y_coord)
79  way = UP;
80  else
81  way = DOWN;
82  api.move(1,way);
83  remaining_power--;
84  self = **k;
85  }
86  }
87  if(remaining_power > 0 && isAdjacent(self,neighbors[i][j]))
88  {
89  api.meleeAttack(remaining_power,neighbors[i][j]);
90  remaining_power = 0;
91  }
92  }
93 
94  return remaining_power;
95  }
virtual AttackResult meleeAttack(int power, GridCell &adjacent_cell)=0
static bool isAdjacent(const GridCell &c1, const GridCell &c2)
Definition: DemoBot.hpp:50
virtual void move(int steps, Direction way)=0

Here is the call graph for this function:

Member Data Documentation

Robot_Specs DemoBot::my_specs
private

Definition at line 15 of file DemoBot.hpp.


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