ManualBot.java
Go to the documentation of this file.
1 
6 import java.util.Scanner;
7 public class ManualBot implements Robot
8 {
9  public static Scanner scanner;
10 
11  public ManualBot()
12  {
13  if(scanner==null)
14  scanner = new Scanner(System.in);
15  }
16 
17  public Robot_Specs createRobot(WorldAPI api, int skill_points, byte[] message)
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  }
41 
42  private GridCell dumpGrid(GridCell[][] neighborhood)
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  }
88 
89  public void act(WorldAPI api, Robot_Status status, byte[][] received_radio)
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  }
171 }
Robot_Specs createRobot(WorldAPI api, int skill_points, byte[] message)
Definition: ManualBot.java:17
Definition: Robot.java:11
static Scanner scanner
Definition: ManualBot.java:9
void move(int steps, Robot.Direction way)
GridCell dumpGrid(GridCell[][] neighborhood)
Definition: ManualBot.java:42
void act(WorldAPI api, Robot_Status status, byte[][] received_radio)
Definition: ManualBot.java:89
Robot.AttackResult meleeAttack(int power, Robot.GridCell adjacent_cell)
Robot.AttackResult rangedAttack(int power, Robot.GridCell nonadjacent_cell)
Robot.GridCell[][] getVisibleNeighborhood()