The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

AI Search Simulator Assistance

I am trying to make a A-Star, Breadth-First, and Depth-First simulator for a homework assignment. I'm not sure what I am doing wrong as the search always tries to go out of bounds of the environment. I even had to add a temporary overload cheack to break out of the while statement I am using as it nevers reaches its conclusion.

Additionally I might have the canvas upside down, not sure how I did that.

I have included my entire Eclipse Project in the attachment. I would appreciate any assistance I can get since it is due tomorrow. I have been programming for 24+ hours straight now and need help, and yes sleep. Thank you in advance.

Re: AI Search Simulator Assistance

I apologize and Norm is right about the other forum, I will stop updating there. I updated the attachment with comments in the NavigationBot class since it is most definitely the source of my problem.

Here is the discription of the classes and the purpose:
The assignment involves a simulated 2D area with polygons whose points were given to me in the assignment.

The bot is given a start and end point and is to navigate through them each time using whichever of the three algorithms that was specified.

The four core classes and they purposes are that I have above are as follows:

PathCoord: Represents any coordinate in the 2D space. That space is 300 wide by 200 height.

Environment: Creates the polygons from the points I was given and loads them into an object array for later use. It also has two helper functions that are supposed to caclusate out the distance from the start, and the other from the end, based upon the current location.

GUIManager: Just takes the information and displays it on a canvas. It gives a starting menu for the user to choose which of the three algorithms to use.

NavigationBot: The core class and the source of my problems I am cerrtain. Based upon the selected algorithm, it is supposed to navigate from start to end, around the polygons.

I have not even began the code for Breadth-First and Depth-First other than a very basic selection system. That means my code I have trouble with is for A-Star. I have updated the NavigationBot class with comments and will provide a sample of the output in my next post.

Here is the sample of the output:

Not shorter distance
In History
Not shorter distance
Not shorter distance
Not shorter distance
Not shorter distance
next X: 21
next Y: 151
Direction Change
Not shorter distance
In History
Not shorter distance
Not shorter distance
Not shorter distance
Not shorter distance
next X: 22
next Y: 152
Not shorter distance
In History
Not shorter distance
Not shorter distance
Not shorter distance
Not shorter distance
next X: 23
next Y: 153
Not shorter distance
In History
Not shorter distance
Not shorter distance
Not shorter distance
Not shorter distance
next X: 24
next Y: 154
Not shorter distance
In History
Not shorter distance
Not shorter distance
Not shorter distance
Not shorter distance
next X: 25
next Y: 155
Not shorter distance
In History
Not shorter distance
Not shorter distance
Not shorter distance
Not shorter distance
next X: 26
next Y: 156
Not shorter distance
In History
Not shorter distance
Not shorter distance
Not shorter distance
Not shorter distance
next X: 27
next Y: 157
Not shorter distance
In History
Not shorter distance
Not shorter distance
Not shorter distance
Not shorter distance
next X: 28
next Y: 158
Not shorter distance
In History
Not shorter distance
Not shorter distance
Not shorter distance
Not shorter distance
next X: 29
next Y: 159
Not shorter distance
In History
Not shorter distance
Not shorter distance
Not shorter distance
Not shorter distance
next X: 30
next Y: 160
Not shorter distance
In History
Not shorter distance
Not shorter distance
Not shorter distance
Not shorter distance
next X: 31
next Y: 161
Not shorter distance
In History
Not shorter distance
Not shorter distance
Not shorter distance
Not shorter distance
next X: 32
next Y: 162
Not shorter distance
In History
Not shorter distance
Not shorter distance
Not shorter distance
Not shorter distance
next X: 33
next Y: 163
Not shorter distance
In History
Not shorter distance
Not shorter distance
Not shorter distance
Not shorter distance
next X: 34
next Y: 164
Not shorter distance
In History
Not shorter distance
Not shorter distance
Not shorter distance
Not shorter distance
next X: 35
next Y: 165
Not shorter distance
In History
Not shorter distance
Not shorter distance
Not shorter distance
Not shorter distance
next X: 36
next Y: 166
Not shorter distance
In History
Not shorter distance
Not shorter distance
Not shorter distance
Not shorter distance
next X: 37
next Y: 167
Not shorter distance
In History
Not shorter distance
Not shorter distance
Not shorter distance
Not shorter distance
next X: 38
next Y: 168
Not shorter distance
In History
Not shorter distance
Not shorter distance
Not shorter distance
Not shorter distance
next X: 39
next Y: 169
Not shorter distance
In History
Not shorter distance
Not shorter distance
Not shorter distance
Not shorter distance
next X: 40
next Y: 170
Not shorter distance
In History
Not shorter distance
Not shorter distance
Not shorter distance
Not shorter distance
next X: 41
next Y: 171
Not shorter distance
In History
Not shorter distance
Not shorter distance
Not shorter distance
Not shorter distance
next X: 42
next Y: 172
Not shorter distance
In History
Not shorter distance
Not shorter distance
Not shorter distance
Not shorter distance
next X: 43
next Y: 173
Not shorter distance
In History
Not shorter distance
Not shorter distance
Not shorter distance
Not shorter distance
next X: 44
next Y: 174
Not shorter distance
In History
Not shorter distance
Not shorter distance
Not shorter distance
Not shorter distance
next X: 45
next Y: 175
Not shorter distance
In History
Not shorter distance
Not shorter distance
Not shorter distance
Not shorter distance
next X: 46
next Y: 176
Not shorter distance
In History
Not shorter distance
Not shorter distance
Not shorter distance
Not shorter distance
next X: 47
next Y: 177
Not shorter distance
In History
Not shorter distance
Not shorter distance
Not shorter distance
Not shorter distance
next X: 48
next Y: 178
Not shorter distance
In History
Not shorter distance
Not shorter distance
Not shorter distance
Not shorter distance
next X: 49
next Y: 179
Not shorter distance
In History
Not shorter distance
Not shorter distance
Not shorter distance
Not shorter distance
next X: 50
next Y: 180
Not shorter distance
In History
Not shorter distance
Not shorter distance
Not shorter distance
Not shorter distance
next X: 51
next Y: 181
Not shorter distance
In History
Not shorter distance
Not shorter distance
Not shorter distance
Not shorter distance
next X: 52
next Y: 182
Not shorter distance
In History
Not shorter distance
Not shorter distance
Not shorter distance
Not shorter distance
next X: 53
next Y: 183
Not shorter distance
In History
Not shorter distance
Not shorter distance
Not shorter distance
Not shorter distance
next X: 54
next Y: 184
Not shorter distance
In History
Not shorter distance
Not shorter distance
Not shorter distance
Not shorter distance
next X: 55
next Y: 185
Not shorter distance
In History
Not shorter distance
Not shorter distance
Not shorter distance
Not shorter distance
next X: 56
next Y: 186
Not shorter distance
In History
Not shorter distance
Not shorter distance
Not shorter distance
Not shorter distance
next X: 57
next Y: 187
Not shorter distance
In History
Not shorter distance
Not shorter distance
Not shorter distance
Not shorter distance
next X: 58
next Y: 188
Not shorter distance
In History
Not shorter distance
Not shorter distance
Not shorter distance
Not shorter distance
next X: 59
next Y: 189
Not shorter distance
In History
Not shorter distance
Not shorter distance
Not shorter distance
Not shorter distance
next X: 60
next Y: 190
Not shorter distance
In History
Not shorter distance
Not shorter distance
Not shorter distance
Not shorter distance
next X: 61
next Y: 191
Not shorter distance
In History
Not shorter distance
Not shorter distance
Not shorter distance
Not shorter distance
next X: 62
next Y: 192
Not shorter distance
In History
Not shorter distance
Not shorter distance
Not shorter distance
Not shorter distance
next X: 63
next Y: 193
Not shorter distance
In History
Not shorter distance
Not shorter distance
Not shorter distance
Not shorter distance
next X: 64
next Y: 194
Not shorter distance
In History
Not shorter distance
Not shorter distance
Not shorter distance
Not shorter distance
next X: 65
next Y: 195
Not shorter distance
In History
Not shorter distance
Not shorter distance
Not shorter distance
Not shorter distance
next X: 66
next Y: 196
Not shorter distance
In History
Not shorter distance
Not shorter distance
Not shorter distance
Not shorter distance
next X: 67
next Y: 197
Not shorter distance
In History
Not shorter distance
Not shorter distance
Not shorter distance
Not shorter distance
next X: 68
next Y: 198
Not shorter distance
In History
Not shorter distance
Not shorter distance
Not shorter distance
Not shorter distance
next X: 69
next Y: 199
Not shorter distance
In History
Not shorter distance
Not shorter distance
Not shorter distance
Not shorter distance
next X: 70
next Y: 200
Not In Bounds
Not shorter distance
In History
Not In Bounds
Not shorter distance
Not shorter distance
Not In Bounds
next X: 71
next Y: 201

Re: AI Search Simulator Assistance

It goes out of bounds and stays there. I ended the tracing print at that point. Sorry I should have stated that. It should also be making some sort of attempt to head in the direction of the end coordinate which is toward the upper right of the area, but instead it just tries to head downward at an angle.

Re: AI Search Simulator Assistance

I changed that to something a bit more reliable as well as removing the code in the AStar function that preloaded the start location. It seems to work much batter and is actually trying to navigate past the first shape now.

Now I just get an "ArrayIndexOutOfBoundsException: 60000" issue because I am trying to add too many objects to the PathCoordArray array. This tells me that my code for determining if there is a direction change is totally wrong as it is calling it all of the time. I have included my updated code.

Re: AI Search Simulator Assistance

All I can suggest is to keep adding printlns to show what is happening, look at what is printed out and see if the code is doing as you want it to do.
Add the following to your PathCoord class for better debug printouts.