7 import java.util.LinkedList;
9 import java.util.HashMap;
10 import java.util.TreeMap;
29 public Object
clone() throws CloneNotSupportedException
30 {
return super.clone(); }
65 public Object
clone() throws CloneNotSupportedException
68 to_return.capsules = capsules.clone();
74 public enum GridObject { EMPTY, BLOCKED, SELF, ALLY, ENEMY,
WALL, FORT, CAPSULE };
98 public Object
clone() throws CloneNotSupportedException
99 {
return super.clone(); }
142 public boolean validCell(
GridCell cell) {
return true; }}, grid);
147 return path[path.length-1];
166 public boolean validCell(
GridCell maybeTarget)
168 return maybeTarget==target;
172 public boolean validCell(
GridCell maybePassable)
183 int x_offset = grid[0][0].x_coord;
184 int y_offset = grid[0][0].y_coord;
187 TreeMap<Integer,LinkedList<GridCell>> unvisited_nodes =
new TreeMap<Integer,LinkedList<GridCell>>();
188 Map<GridCell,LinkedList<GridCell>> current_costs =
new HashMap<GridCell,LinkedList<GridCell>>();
191 LinkedList<GridCell> origin_path =
new LinkedList<GridCell>();
192 origin_path.add(origin);
195 current_costs.put(origin,origin_path);
196 unvisited_nodes.put(0,origin_path);
198 while(unvisited_nodes.size()!=0)
200 Map.Entry<Integer,LinkedList<GridCell>> current_entry = unvisited_nodes.firstEntry();
201 int our_cost = current_entry.getKey();
202 GridCell our_cell = current_entry.getValue().pop();
203 LinkedList<GridCell> current_path = current_costs.get(our_cell);
207 return current_path.toArray(
new GridCell[0]);
210 if(current_entry.getValue().size()==0)
211 unvisited_nodes.remove(our_cost);
216 LinkedList<GridCell> adjacent_nodes =
new LinkedList<GridCell>();
217 int gridX_value = our_cell.x_coord - x_offset;
218 int gridY_value = our_cell.y_coord - y_offset;
220 adjacent_nodes.add(grid[gridX_value-1][gridY_value]);
221 if(gridX_value!=grid.length-1)
222 adjacent_nodes.add(grid[gridX_value+1][gridY_value]);
224 adjacent_nodes.add(grid[gridX_value][gridY_value-1]);
225 if(gridY_value!=grid[0].length-1)
226 adjacent_nodes.add(grid[gridX_value][gridY_value+1]);
234 if(!isPassable.
validCell(x) && !isTarget.validCell(x))
238 LinkedList<GridCell> x_proposed_path = (LinkedList<GridCell>)(current_path.clone());
239 x_proposed_path.add(x);
242 List<GridCell> clcp = current_costs.get(x);
244 if(clcp!=null && clcp.size()-1>our_cost+1)
246 LinkedList<GridCell> old_unvisited = unvisited_nodes.get(clcp.size()-1);
247 old_unvisited.removeFirstOccurrence(x);
248 if(old_unvisited.size()==0)
249 unvisited_nodes.remove(clcp.size()-1);
251 else if(clcp!=null && clcp.size()-1<=our_cost+1)
254 LinkedList<GridCell> new_unvisited = unvisited_nodes.get(our_cost+1);
255 if(new_unvisited==null)
257 new_unvisited =
new LinkedList<GridCell>();
258 unvisited_nodes.put(our_cost+1,new_unvisited);
260 new_unvisited.add(x);
261 current_costs.put(x,x_proposed_path);
Direction fort_orientation
static GridCell[] findShortestPath(GridCell origin, final GridCell target, GridCell[][] grid)
static GridCell[] findShortestPathInternal(GridCell origin, FSPPredicate isTarget, FSPPredicate isPassable, GridCell[][] grid)
abstract boolean validCell(GridCell cell)
void act(WorldAPI api, Robot_Status status, byte[][] received_radio)
static GridCell findNearestAlly(GridCell origin, GridCell[][] grid)
Robot_Specs createRobot(WorldAPI api, int skill_points, byte[] message)