Difference between revisions of "Thread:Talk:Main Page/Running Error - Robot is not stopping, forcing a stop"
Lavenderwong (talk | contribs) m (New thread: Running Error - Robot is not stopping, forcing a stop) |
Lavenderwong (talk | contribs) m |
||
Line 3: | Line 3: | ||
Thank you. | Thank you. | ||
+ | |||
***** BATTLE 1, ROUND 1 ***** | ***** BATTLE 1, ROUND 1 ***** | ||
+ | |||
TURN 1: StudentRobot* (1) hard deadline exceeded - 532809us | TURN 1: StudentRobot* (1) hard deadline exceeded - 532809us | ||
+ | |||
Err> Robot StudentRobot* (1) is not stopping. Forcing a stop. | Err> Robot StudentRobot* (1) is not stopping. Forcing a stop. | ||
+ | |||
Err> Robot StudentRobot* (2) is not stopping. Forcing a stop. | Err> Robot StudentRobot* (2) is not stopping. Forcing a stop. | ||
− | + | ||
− | |||
− | |||
− | |||
− | |||
− | |||
Average computation time per turn: 511706 | Average computation time per turn: 511706 | ||
+ | |||
Max turn computation time: 532809 | Max turn computation time: 532809 | ||
− | |||
− | |||
+ | <code> | ||
+ | private boolean pathFinding_BFS(Node start, Node end){ | ||
+ | LinkedList<Node> queue = new LinkedList<Node>(); | ||
− | |||
− | |||
queue.add(start); | queue.add(start); | ||
+ | |||
start.setMarked(); | start.setMarked(); | ||
+ | |||
while (!queue.isEmpty()){ | while (!queue.isEmpty()){ | ||
+ | |||
Node temp = (Node)queue.poll(); | Node temp = (Node)queue.poll(); | ||
+ | |||
System.out.println("first node:" + temp.getPointInPath().getX() + " y " + temp.getPointInPath().getY()); | System.out.println("first node:" + temp.getPointInPath().getX() + " y " + temp.getPointInPath().getY()); | ||
+ | |||
if (temp.equals(end)){ | if (temp.equals(end)){ | ||
+ | |||
temp.setPrevNodeInPath(temp.getPrevNodeInPath()); | temp.setPrevNodeInPath(temp.getPrevNodeInPath()); | ||
+ | |||
return true; | return true; | ||
+ | |||
}else{ | }else{ | ||
+ | |||
for (Node n : temp.getAdjacentNode()){ | for (Node n : temp.getAdjacentNode()){ | ||
− | System.out.println("in node:" + n.getPointInPath().getX() + " y " + n.getPointInPath().getY()); | + | |
+ | System.out.println("in node:" + n.getPointInPath().getX() + " y " + | ||
+ | n.getPointInPath().getY()); | ||
+ | |||
if (!n.isMarked()){ | if (!n.isMarked()){ | ||
+ | |||
n.setMarked(); | n.setMarked(); | ||
+ | |||
n.setPrevNodeInPath(temp); | n.setPrevNodeInPath(temp); | ||
+ | |||
System.out.println("test n"); | System.out.println("test n"); | ||
+ | |||
queue.add(n); //problem here | queue.add(n); //problem here | ||
+ | |||
} | } | ||
} | } | ||
Line 47: | Line 63: | ||
} | } | ||
+ | |||
public List<Point> getShortestPath(Point start){ | public List<Point> getShortestPath(Point start){ | ||
+ | |||
Node src = new Node(start); | Node src = new Node(start); | ||
+ | |||
List<Point> path = new ArrayList<Point>(); | List<Point> path = new ArrayList<Point>(); | ||
+ | |||
for (int i=0;i<endup.size();i++){ | for (int i=0;i<endup.size();i++){ | ||
+ | |||
Node destination = new Node(endup.get(i)); | Node destination = new Node(endup.get(i)); | ||
+ | |||
if (pathFinding_BFS(src, destination)){ | if (pathFinding_BFS(src, destination)){ | ||
+ | |||
while (destination.getPrevNodeInPath() != null){ | while (destination.getPrevNodeInPath() != null){ | ||
+ | |||
destination = destination.getPrevNodeInPath(); | destination = destination.getPrevNodeInPath(); | ||
+ | |||
path.add(destination.getPointInPath()); | path.add(destination.getPointInPath()); | ||
+ | |||
} | } | ||
+ | |||
Collections.reverse(path); | Collections.reverse(path); | ||
+ | |||
return path; | return path; | ||
} | } | ||
Line 64: | Line 92: | ||
return path; | return path; | ||
} | } | ||
+ | </code> |
Revision as of 08:13, 7 December 2013
When I start the battlefield,my robot and other enemy are frozen. The println messages are not displayed in the robot console. But the command prompt shows the following error. I check that the cause of error is the addition of node in my queue (queue.add(n)). However, this line of code shall be fine i guess. So I would like to ask how to solve this error message? (this part of my program is for path finding using bfs)
Thank you.
- BATTLE 1, ROUND 1 *****
TURN 1: StudentRobot* (1) hard deadline exceeded - 532809us
Err> Robot StudentRobot* (1) is not stopping. Forcing a stop.
Err> Robot StudentRobot* (2) is not stopping. Forcing a stop.
Average computation time per turn: 511706
Max turn computation time: 532809
private boolean pathFinding_BFS(Node start, Node end){
LinkedList<Node> queue = new LinkedList<Node>();
queue.add(start);
start.setMarked();
while (!queue.isEmpty()){
Node temp = (Node)queue.poll();
System.out.println("first node:" + temp.getPointInPath().getX() + " y " + temp.getPointInPath().getY());
if (temp.equals(end)){
temp.setPrevNodeInPath(temp.getPrevNodeInPath());
return true;
}else{
for (Node n : temp.getAdjacentNode()){
System.out.println("in node:" + n.getPointInPath().getX() + " y " +
n.getPointInPath().getY());
if (!n.isMarked()){
n.setMarked();
n.setPrevNodeInPath(temp);
System.out.println("test n");
queue.add(n); //problem here
}
}
}
}
return false;
}
public List<Point> getShortestPath(Point start){
Node src = new Node(start);
List<Point> path = new ArrayList<Point>();
for (int i=0;i<endup.size();i++){
Node destination = new Node(endup.get(i));
if (pathFinding_BFS(src, destination)){
while (destination.getPrevNodeInPath() != null){
destination = destination.getPrevNodeInPath();
path.add(destination.getPointInPath());
}
Collections.reverse(path);
return path;
}
}
return path;
}