Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Code Snippets / TBS Pathfinding

Author
Message
mcb
20
Years of Service
User Offline
Joined: 27th Nov 2003
Location: Lincs, UK
Posted: 27th Nov 2003 23:31
Inspired by Interplay's M.A.X (1997), I'm going to try creating a TBS (turn-based strategy) game in DB Pro.
The first thing I've got working is the pathfinding system, which uses a variation of the A* algorithm (yes, another one ).
No proper graphics yet, so all you need to do is run the source code to see it in action.
There is one other file you need, which is a text file describing the map to be used. A sample one is available here:

http://darksun.united.net.kg/map.txt

Just bung it in the same dir as the exe.

How to use it:
The red squares are units. Click to select one, and click somewhere to send it off on a little expedition, avoiding all walls (white squares) in the way.

Controls:
Arrows: scroll screen
Ctrl/Shift: zoom (don't zoom out too far...)
Right click: add/delete wall

If you've got any comments/suggestions, please post them here.
This is only my 2nd DB project, so don't be too critical
genius
21
Years of Service
User Offline
Joined: 16th Oct 2003
Location: Utah, USA
Posted: 28th Nov 2003 01:19
Do have an exe or something for people without DB. I only have DBPro

Be happy, tomorrow is another day
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 28th Nov 2003 07:30
This is DBP, notice the TYPEs and GLOBAL variables.
But it doesn't run, I get a "command out of place" error, line 391.
Xanatus
21
Years of Service
User Offline
Joined: 15th Mar 2003
Location: Germany
Posted: 28th Nov 2003 15:48
You can walk through corner:




I think that should be fixed.

mcb
20
Years of Service
User Offline
Joined: 27th Nov 2003
Location: Lincs, UK
Posted: 28th Nov 2003 16:44
I'll attack the cornering tonight and see what I can do. I suppose it's debatable whether units should be able to move between corners like this - depends on the game.
genius
21
Years of Service
User Offline
Joined: 16th Oct 2003
Location: Utah, USA
Posted: 28th Nov 2003 18:13
Yah, it doesn't even run for me. I worked forever trying to get it going, and I still can't get it.

Be happy, tomorrow is another day
mcb
20
Years of Service
User Offline
Joined: 27th Nov 2003
Location: Lincs, UK
Posted: 28th Nov 2003 19:08
Quote: "Yah, it doesn't even run for me"


What happens if you try and run it? Do you also get a 'line 391' error?
If so, I'm afraid I can't explain it. Why should the code compile any differently on my DBPro than yours? Weird.

If you're interested in seeing what it should look like, you can get an exe here:

http://darksun.united.net.kg/pathfinder.exe
genius
21
Years of Service
User Offline
Joined: 16th Oct 2003
Location: Utah, USA
Posted: 28th Nov 2003 23:42 Edited at: 28th Nov 2003 23:47
I don't have the line 391 error, I have a 410 error. Then it starts saying that add array to stack has a problem. By the way, what patch are you using, that could be a clue.

Be happy, tomorrow is another day
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 29th Nov 2003 01:51
As for cutting corners, you should check to see if the corner of the square being cut is walkable. If so, then go ahead and cut the corner, otherwise walk around it.

Tried the exe, runtime error 105 file does not exist at line 494. Did you compile it with the map.txt file or do I have have the two in the same directory?
Xanatus
21
Years of Service
User Offline
Joined: 15th Mar 2003
Location: Germany
Posted: 29th Nov 2003 03:18 Edited at: 29th Nov 2003 03:18
As i said, it runs for me perfectly.
> patch 5 & newest editor.

Phaelax, make sure you run the EXE directly from where the map file exist.
If you run the EXE by using DBP, it could be that the EXE will be started from the TEMP directory, located where you have DBP installed, so it cant find the map.

HTH, Xanatus

Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 29th Nov 2003 11:52
Aye, that's what I thought. As for me, I'm still running patch 4.
mcb
20
Years of Service
User Offline
Joined: 27th Nov 2003
Location: Lincs, UK
Posted: 29th Nov 2003 14:09
OK, corners now work properly, it uses proper-ish (bitmap) graphics instead of squares, and runs a lot faster too.

http://darksun.united.net.kg/pfinder.zip

That zip includes an exe and all the media needed.
genius
21
Years of Service
User Offline
Joined: 16th Oct 2003
Location: Utah, USA
Posted: 29th Nov 2003 18:29
Quote: "As for me, I'm still running patch 4."

Same here. I love it. Actually, I am running patch 4.1 and have I think about a year and a half's old DBPro, I don't know if that would make a difference.

Be happy, tomorrow is another day
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 30th Nov 2003 05:42
Seems to work pretty fast. How many units do you think it could handle without slow down?
genius
21
Years of Service
User Offline
Joined: 16th Oct 2003
Location: Utah, USA
Posted: 30th Nov 2003 06:46
Did you get it to run Phaelax? Or did you download the EXE?

Be happy, tomorrow is another day
mcb
20
Years of Service
User Offline
Joined: 27th Nov 2003
Location: Lincs, UK
Posted: 30th Nov 2003 12:23
Quote: "How many units do you think it could handle without slow down?"


I get:
Default 2 units: 40FPS
Whole screen filled with units: 37FPS

It doesn't even try and draw any units which are off the screen, so it wouldn't drop any more frames if I added more off the screen.

At line 222, replace



with



then you can place units all over the map by holding return and right-clicing.
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 30th Nov 2003 12:23
the exe. I'm using 4.1 like you. I dont see what the newer patch would change to make the structure differ like that.
genius
21
Years of Service
User Offline
Joined: 16th Oct 2003
Location: Utah, USA
Posted: 9th Dec 2003 05:55
This post has been quiet for quite some time

Be happy, tomorrow is another day
Arkheii
21
Years of Service
User Offline
Joined: 15th Jun 2003
Location: QC, Philippines
Posted: 9th Dec 2003 12:45
Long live A*, even though I can't figure out how to implement it.

@mcb, I understand the concept of A* in my head, and I have actually written some notes that can be translated to code fairly quickly, but I can't figure out one thing - how do I know what tile to check next: the tile with the lowest F score, or check them in the order that they were added to the open list? I could really use help on this one...
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 12th Dec 2003 08:27
Actually maintaining and accessing the open and closed lists (especially the open list) is the hardest part of A*.

Most people approaching it for the first time either keep sorting the lists, or search the whole list to get the next item.

I used a different approach to mine - I used an arrangement known as a heap, which keeps the data arranged within an array so that the initial item is always the lowest cost, and maintenance is fast and cheap.

You can see example heap code in CodeBase : http://developer.thegamecreators.com/?m=codebase_view&i=604edc86c5cdb7db3d4d2681729356b0

You can also find my A* code in CodeBase, but I'll let you look for that yourself so that I don't get accused of hijacking this post

Plug-ins ... get 'em while they're hot, they're lovely
http://www.matrix1.demon.co.uk
mcb
20
Years of Service
User Offline
Joined: 27th Nov 2003
Location: Lincs, UK
Posted: 17th Dec 2003 14:33
Quote: "how do I know what tile to check next: the tile with the lowest F score, or check them in the order that they were added to the open list?"


In my code, the GetBest() function is used to get the tile with the lowest F score in the open list. If two have the same F score, it goes with the most recently added. Note: I don't know if this is the fastest way, it's just the way I did it.

Login to post a reply

Server time is: 2024-11-23 23:31:09
Your offset time is: 2024-11-23 23:31:09