zondag 30 oktober 2011

Been studying a* pathfinding code

In the Blitzbasic language there was this pathfinding code on the archives. I have been studying the code. I retyped a part in blitz basic changing variable names and got it working. But when I placed the routine in a function the code stopped working. I could not figure out what the problem was. I then copy pasted from the original and recreated the pathfinding program.
I still practically do not understand how a pathfinding routine works. It is something like the floodfill pathfinding that I have on this blog that I made myself but different. I have converted a pathfinding program into the delphi language years ago to learn how it works but to no avail. It is so difficult to understand. But I read in my ai book that you should study source code multiple times and even on paper to learn how it works.
I was planning on converting the Blitz Basic pathfinding program into Java but I have no idea when I will do this. This pathfinding routine does not check terrain difficulty only blocked and open. But it is a pretty solid version that might turn into a nice applet to try it with.
I have an other pathfinding code in Blitz Basic that does use more than blocked values in pathplanning but it uses types and I have not enough programming experience to figure out how to convert that to Java. I really should buy a good book on Java to learn more about it. But the Blitz Basic language with the confusing Type code has little books for it. It is not that widely used.

The example I have been working with is made for Rogue type games. I modified the new version to only show random paths on bigger maps. I created random obstacles on the map each time you press the mouse on the screen. I have been thinking on how I would convert the code to Java since the code is in Blitz and uses strings to store the path into. I have not really worked with Strings with Java but I found on the Internet that Substring replaces the Mid function in Basic. The other parts of the code uses Multi Dimensional Arrays and other variables. I think I will be able to convert the code to Java with not to many difficulties. But one thing troubles me and that is the fact that I have no idea how I got that out of bound error while retyping the code. I see nothing in the code that prevents this and still no out of bounds error occurs in the original. I did notice that the map is larger then what is being used in the code so that must be a part of it, I have learned most of my programming by copying succesfull code so I must learn this thing to.

I also have been thinking of what to do with the pathfinding code. Shall I turn it into a game of some sorts. But I have no clues of what to add into the game. I really should select a type of game a clone it. Maybe a small Rogue type game would be neat but they are not my favourite types of games.

Well I barely program anymore but I did get stuff done this weekend.

Geen opmerkingen:

Een reactie posten

Opmerking: Alleen leden van deze blog kunnen een reactie posten.