maandag 31 oktober 2011

Bought a Java Book - A natural introduction to Computer programming with Java

Last night I bought a digital Java book. It was only 8 euro's and I could pay directly through internet. I have been looking through the book and I see that it is a beginners book. There are over 600 pages of material. I already looked through the Array chapter but it did not have the multidimensional array setup covered. Though I will be using this book for studying. I still copy and paste and modify older sourcecode to make new things. So I need to learn how to code from nothing up to the end result. The last thing that I went through was classes. I worked with Types in Blitz Basic and I thought that classes replace this. Still I need to be certain that the applets work on this blog so I have some experimenting to do.
Edit: I found a older post from the blog here where I used linked lists to store classes into. Classes do replace types. You can even add functions to classes. There is a different class compiled for each class declared in the sourcecode.

Last night I also started working on a new example for my blog. A fog of war example. I am making a scrolling map where a oval is centered in the middle of the map that can be moved through the map. The fog of war is something that I programmed a number of times already. The map is covered in black and a brush in a array draws in a hidden_tiles_array where the oval is and sets the tile values to unhidden. This way when you move through the map the map becomes visible. The map draw routine draws the tiles and checks if it can draw a tile if the flag is set to unhidden. An extra map array is needed. I have selected a older example from my blog as a base for this fog of war example. I am hoping to finish the fog of war example today though I may do different things. But I placed the fog of war example on my to do list for the weblog.

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.

dinsdag 4 oktober 2011

Trying to learn a* (again)

For years I have not been able to understand how the a* pathfinding thing works. A couple of weeks ago I memorized the g h and f variables. F is the combined g and h values. G is the movement cost and H is the estimated movement cost. Memorizing these got me a little further in understanding the a* algorithm. But I still have a long way to go to fully understand it.

For instance. How do you expand the search area. I can not understand this yet.

I wish there were more articles on a* for people who do not understand the algorithm. I have under 10 different source codes of a* but what the codes do is still a mystery.

Update :
I learned that the h cost is the distance to the end position. And that g is the distance from the start position. I think that anyways after studying the examples I found. Still I am still stuck on how to find that path itself. I have no idea on how to do that. I plan to study sourcecode and I hope to learn something on that.