Friday, February 06, 2009

More on Pathfinding

After re-reading my previous code, I have realised that there are a few things that can be done to optimise the code, whilst still keeping the same method of static arrays.
  1. The Struct list_s could be made to a typedef, and *path declared only inside the findpath function, eliminating the need for the initnodes() function.
  2. node.onopen and node.onclosed could become one variable of either TRUE, FALSE, or NULL.
  3. There's no need to keep the f value on the list.
  4. The instances of 40 need to be replaced with a constant tilesize or even tilew and tileh.
  5. The map and its associated dimensions could all be passed to the findpath function.
  6. Some error checking needs to be included, such as what if there is no possible path? At the same time, some checks already included might be able to be removed.
Also sorry if the code is a bit hard to read, it looks great in code::blocks, but the width of the blog restricts it. If you're having trouble, copy and paste it into your editor and it'll be a lot easier. When I get the chance I'll go and edit it to be easier to read.

Oh yeah, and on a side note, I've noticed that the code syntax highlighter I'm using (http://www.dreamprojections.com/syntaxhighlighter) doesnt seem to work properly in Firefox for Ubuntu. I'm not sure if its working in other firefoxes (such as windows) but it does work in Internet Explorer, which is what I'm using most of the time (I know - dont ask!).

No comments:

Post a Comment