Hi,

I've been working on this for several hours now and it is time to head to bed. I decided to post up my current attempt at writing A* where the cost is 0 for all nodes.

Currently, when I run this, the solution (which is the open list), contains every single node that the algorithm looked at. I am going by this description of the algorithm:

http://ai-depot.com/Tutorial/PathFinding.htmlThough either I am not understanding this properly or that example is flawed...

I know my algorithm is reaching the indicated node because it leaves a single node untouched...

So I need to know how to remove unwanted nodes from the list as I go.

Here is my code for the algorithm. If you require the entire program let me know.

The filled part tells the program to draw a filled rectangle as opposed to an outline of one.

Thanks for any assistance.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
| public static void pathFind(PathWindow window) {
Node startNode = window.getColumns().get(0).getNodeList().get(0); int cols = window.getColumns().size(); int rows = window.getColumns().get(0).getNodeList().size(); Node endNode = window.getColumns().get(cols-1).getNodeList().get(rows-1); LinkedList<Node> openList = new LinkedList<Node>(); openList.add(startNode); while(openList.size() > 0) { Node currentNode = openList.poll(); if(currentNode.equals(endNode)) { openList.add(currentNode); break; } if(currentNode.getAboveNode() != null) { if(openList.contains(currentNode.getAboveNode()) == false) { openList.add(currentNode); openList.add(currentNode.getAboveNode()); } } if(currentNode.getUnderNode() != null) { if(openList.contains(currentNode.getUnderNode()) == false) { openList.add(currentNode); openList.add(currentNode.getUnderNode()); } } if(currentNode.getLeftNode() != null) { if(openList.contains(currentNode.getLeftNode()) == false) { openList.add(currentNode); openList.add(currentNode.getLeftNode()); } } if(currentNode.getRightNode() != null) { if(openList.contains(currentNode.getRightNode()) == false) { openList.add(currentNode); openList.add(currentNode.getRightNode()); } } } System.out.println("openlist is:\n" + openList); for(int i = 0;i<openList.size();i++) { openList.get(i).setFilled(true); } window.repaint(); } |