ManualBot Class Reference
Inheritance diagram for ManualBot:
Collaboration diagram for ManualBot:

Public Member Functions

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

Static Public Attributes

static Scanner scanner
 

Private Member Functions

GridCell dumpGrid (GridCell[][] neighborhood)
 

Detailed Description

Definition at line 7 of file ManualBot.java.

Constructor & Destructor Documentation

ManualBot.ManualBot ( )

Definition at line 11 of file ManualBot.java.

References scanner.

12  {
13  if(scanner==null)
14  scanner = new Scanner(System.in);
15  }
static Scanner scanner
Definition: ManualBot.java:9

Member Function Documentation

void ManualBot.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 89 of file ManualBot.java.

References Robot.Direction.DOWN, dumpGrid(), WorldAPI.getVisibleNeighborhood(), Robot.Direction.LEFT, WorldAPI.meleeAttack(), WorldAPI.move(), WorldAPI.rangedAttack(), Robot.Direction.RIGHT, Robot.Direction.UP, Robot.GridCell.x_coord, and Robot.GridCell.y_coord.

90  {
91  GridCell[][] neighborhood = api.getVisibleNeighborhood();
92  GridCell self = dumpGrid(neighborhood);
93  System.out.print("ManualBot at ("+self.x_coord+","+self.y_coord+"):\n? ");
94  String command = scanner.next();
95  while(!command.equalsIgnoreCase("done"))
96  {
97  try
98  {
99  if(command.equalsIgnoreCase("move"))
100  {
101  System.out.print("Direction? ");
102  String dir = scanner.next();
103  System.out.print("Steps? ");
104  int steps = scanner.nextInt();
105 
106  Direction way = Direction.UP;
107  if(dir.equalsIgnoreCase("Up"))
108  way = Direction.UP;
109  else if(dir.equalsIgnoreCase("Down"))
110  way = Direction.DOWN;
111  else if(dir.equalsIgnoreCase("Left"))
112  way = Direction.LEFT;
113  else
114  way = Direction.RIGHT;
115 
116  api.move(steps,way);
117  }
118  else if(command.equalsIgnoreCase("attack"))
119  {
120  System.out.print("Type? ");
121  String typ = scanner.next();
122 
123  System.out.print("Location x y? ");
124  int x_coord = scanner.nextInt();
125  int y_coord = scanner.nextInt();
126 
127  System.out.print("Power? ");
128  int power = scanner.nextInt();
129 
130  AttackResult result = null;
131  if(typ.equalsIgnoreCase("melee"))
132  result = api.meleeAttack(power,neighborhood[x_coord - neighborhood[0][0].x_coord][y_coord - neighborhood[0][0].y_coord]);
133  else if(typ.equalsIgnoreCase("ranged"))
134  result = api.rangedAttack(power,neighborhood[x_coord - neighborhood[0][0].x_coord][y_coord - neighborhood[0][0].y_coord]);
135 
136  if(result!=null)
137  System.out.println(result.toString());
138  }
139  else if(command.equalsIgnoreCase("scan"))
140  {
141  Robot_Specs returnedSpecs = new Robot_Specs();
142  Robot_Status returnedStatus = new Robot_Status();
143  System.out.print("Location x y? ");
144  int x_coord = scanner.nextInt();
145  int y_coord = scanner.nextInt();
146  api.scanEnemy(returnedSpecs,returnedStatus,neighborhood[x_coord - neighborhood[0][0].x_coord][y_coord - neighborhood[0][0].y_coord]);
147 
148  System.out.println("Specs/Attack: "+returnedSpecs.attack);
149  System.out.println("Specs/Defense: "+returnedSpecs.defense);
150  System.out.println("Specs/Power: "+returnedSpecs.power);
151  System.out.println("Specs/Charge: "+returnedSpecs.charge);
152  System.out.println("Status/Power: "+returnedStatus.power);
153  System.out.println("Status/Charge: "+returnedStatus.charge);
154  System.out.println("Status/Health: "+returnedStatus.health);
155  System.out.println("Status/DefenseBoost: "+returnedStatus.defense_boost);
156  }
157  }
158  catch(RoboSim.RoboSimExecutionException e)
159  {
160  System.out.println(e.getMessage());
161  }
162 
163  //Print out new grid
164  dumpGrid(neighborhood = api.getVisibleNeighborhood());
165 
166  //Get next command ("?" for interface mimics ed)
167  System.out.print("? ");
168  command = scanner.next();
169  }
170  }
void move(int steps, Robot.Direction way)
GridCell dumpGrid(GridCell[][] neighborhood)
Definition: ManualBot.java:42
Robot.AttackResult meleeAttack(int power, Robot.GridCell adjacent_cell)
Robot.AttackResult rangedAttack(int power, Robot.GridCell nonadjacent_cell)
Robot.GridCell[][] getVisibleNeighborhood()

Here is the call graph for this function:

Robot_Specs ManualBot.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 17 of file ManualBot.java.

18  {
19  Robot_Specs to_return = new Robot_Specs();
20  System.out.println("***Creation***\nSkill points: "+skill_points);
21  try
22  {
23  System.out.print("Attack? ");
24  to_return.attack = Integer.parseInt(scanner.nextLine());
25  System.out.print("Defense? ");
26  to_return.defense = Integer.parseInt(scanner.nextLine());
27  System.out.print("Power? ");
28  to_return.power = Integer.parseInt(scanner.nextLine());
29  System.out.print("Charge? ");
30  to_return.charge = Integer.parseInt(scanner.nextLine());
31  }
32  catch(NumberFormatException e)
33  {
34  System.out.println(e.getMessage());
35  }
36 
37  //TODO: handle message
38 
39  return to_return;
40  }
GridCell ManualBot.dumpGrid ( GridCell  neighborhood[][])
private

Definition at line 42 of file ManualBot.java.

Referenced by act().

43  {
44  GridCell to_return = null;
45 
46  //The j-then-i nesting here is not a bug.
47  for(int j=0; j<neighborhood[0].length; j++)
48  {
49  for(int i=0; i<neighborhood.length; i++)
50  switch(neighborhood[i][j].contents)
51  {
52  case EMPTY: System.out.print("-");
53  break;
54  case BLOCKED: System.out.print("X");
55  break;
56  case SELF: System.out.print("@");
57  to_return = neighborhood[i][j];
58  break;
59  case ALLY: System.out.print("A");
60  break;
61  case ENEMY: System.out.print("E");
62  break;
63  case WALL: System.out.print("#");
64  break;
65  case FORT:
66  switch(neighborhood[i][j].fort_orientation)
67  {
68  case UP: System.out.print("^");
69  break;
70  case DOWN: System.out.print("V");
71  break;
72  case LEFT: System.out.print("<");
73  break;
74  case RIGHT: System.out.print(">");
75  break;
76  }
77  break;
78  case CAPSULE: System.out.print("C");
79  break;
80  }
81  System.out.println();
82  }
83 
84  if(to_return!=null)
85  System.out.println("Position: ["+to_return.x_coord+"]["+to_return.y_coord+"]");
86  return to_return;
87  }

Here is the caller graph for this function:

Member Data Documentation

Scanner ManualBot.scanner
static

Definition at line 9 of file ManualBot.java.

Referenced by ManualBot().


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