DemoBot Class Reference
Inheritance diagram for DemoBot:
Collaboration diagram for DemoBot:

Public Member Functions

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

Static Private Member Functions

static boolean isAdjacent (GridCell c1, GridCell c2)
 
static int searchAndDestroy (GridCell self, GridCell[][] neighbors, WorldAPI api, int remaining_power) throws RoboSim.RoboSimExecutionException
 

Private Attributes

Robot_Specs my_specs
 

Detailed Description

DemoBot: Demo Robot implementation for OffenseBot

Definition at line 5 of file DemoBot.java.

Member Function Documentation

void DemoBot.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 82 of file DemoBot.java.

References searchAndDestroy(), and Robot.GridObject.SELF.

83  {
84  int remaining_power = status.power;
85  int remaining_charge = status.charge;
86 
87  try
88  {
89  GridCell[][] neighbors = api.getVisibleNeighborhood();
90 
91  //What's our position?
92  GridCell self=null;
93  for(int i=0; i<neighbors.length; i++)
94  for(int j=0; j<neighbors[0].length; j++)
95  if(neighbors[i][j].contents==GridObject.SELF)
96  {
97  self=neighbors[i][j];
98  break;
99  }
100 
101  //Visible and reachable enemy? Attack!
102  remaining_power = searchAndDestroy(self,neighbors,api,remaining_power);
103 
104  //Do we still have power? Then we haven't attacked anything.
105  //Perhaps we couldn't find an enemy...
106  if(remaining_power > 3)
107  {
108  GridCell[][] world = api.getWorld(3);
109  remaining_power-=3;
110  searchAndDestroy(self,world,api,remaining_power);
111  }
112  }
113  catch(RoboSim.RoboSimExecutionException e)
114  {
115  System.err.println(e.getMessage());
116  }
117  }
static int searchAndDestroy(GridCell self, GridCell[][] neighbors, WorldAPI api, int remaining_power)
Definition: DemoBot.java:48

Here is the call graph for this function:

Robot_Specs DemoBot.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 9 of file DemoBot.java.

References my_specs.

10  {
11  Robot_Specs to_return = new Robot_Specs();
12  to_return.attack = to_return.defense = to_return.power = to_return.charge = skill_points/4;
13  //This handles the pathological case where skill_points<4
14  if(skill_points<4)
15  {
16  to_return.charge = 1;
17  skill_points--;
18  if(skill_points > 0)
19  {
20  to_return.power = 1;
21  skill_points--;
22  }
23  if(skill_points > 0)
24  {
25  to_return.defense = 1;
26  skill_points--;
27  }
28  }
29  else
30  {
31  skill_points-=(skill_points/4)*4;
32  to_return.attack += skill_points;
33  }
34 
35  //Keep track of our specs; simulator won't do it for us!
36  my_specs = to_return;
37  return to_return;
38  }
Robot_Specs my_specs
Definition: DemoBot.java:7
static boolean DemoBot.isAdjacent ( GridCell  c1,
GridCell  c2 
)
staticprivate

Definition at line 40 of file DemoBot.java.

References Robot.GridCell.x_coord.

Referenced by searchAndDestroy().

41  {
42  return (Math.abs(c1.x_coord-c2.x_coord)==1 &&
43  c1.y_coord == c2.y_coord ||
44  Math.abs(c1.y_coord-c2.y_coord)==1 &&
45  c1.x_coord == c2.x_coord);
46  }

Here is the caller graph for this function:

static int DemoBot.searchAndDestroy ( GridCell  self,
GridCell  neighbors[][],
WorldAPI  api,
int  remaining_power 
) throws RoboSim.RoboSimExecutionException
staticprivate

Definition at line 48 of file DemoBot.java.

References Robot.Direction.DOWN, Robot.GridObject.ENEMY, isAdjacent(), Robot.Direction.LEFT, Robot.Direction.RIGHT, and Robot.Direction.UP.

Referenced by act().

49  {
50  for(int i=0; i<neighbors.length; i++)
51  for(int j=0; j<neighbors[0].length; j++)
52  if(neighbors[i][j].contents==GridObject.ENEMY)
53  {
54  GridCell[] path = RobotUtility.findShortestPath(self,neighbors[i][j],neighbors);
55  if(path!=null)
56  for(int k=0; k<path.length-1 && remaining_power > 0; k++)
57  {
58  Direction way = null;
59  if(path[k].x_coord < self.x_coord)
60  way = Direction.LEFT;
61  else if(path[k].x_coord > self.x_coord)
62  way = Direction.RIGHT;
63  else if(path[k].y_coord < self.y_coord)
64  way = Direction.UP;
65  else
66  way = Direction.DOWN;
67  api.move(1,way);
68  remaining_power--;
69  self = path[k];
70  }
71 
72  if(remaining_power > 0 && isAdjacent(self,neighbors[i][j]))
73  {
74  api.meleeAttack(remaining_power,neighbors[i][j]);
75  remaining_power = 0;
76  }
77  }
78 
79  return remaining_power;
80  }
static boolean isAdjacent(GridCell c1, GridCell c2)
Definition: DemoBot.java:40

Here is the call graph for this function:

Here is the caller graph for this function:

Member Data Documentation

Robot_Specs DemoBot.my_specs
private

Definition at line 7 of file DemoBot.java.

Referenced by createRobot().


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