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.

DarkBASIC Professional Discussion / Help: Generating Nodes more efficiently!

Author
Message
Mokraton
14
Years of Service
User Offline
Joined: 4th Dec 2011
Location:
Posted: 31st Mar 2012 04:29
A couple of months ago, I worked on a DarkBASIC Project for my Science Fair Project about Artifical Intellgience and once the project was finished I abandoned it temporarily, but have recently begun work on it again.

Its a simple game. The Objective is to kill the opponent by shooting bullets at him. The AI of my game is that the Oppenent will Dodge the Bullets, Shoot back at the player, and over the Wall in the middle of the map.

_______________
| * | This is how my Map is designed (quite simple)
| | | The astericks in there are my nodes, points
| * | * | the map that my AI will travel to if he canno
|_____*________| t see the player. I currently have identified these node points as follows:



What I am trying to do before I go any further with this project, is clean up my code a little

The way my code works:





Is that the AI determines first whether he can see the player or not, then if he cannot, he runs through a check to see which node the player is closest to and if that node is in his Line Of Sight(which is a straight line). He will travel to these nodes until he can see the player again and begin shooting.

I have attached my entire Project to this Post (.rar file) for the entire code is quite long. If anyone can look at my game, I would like to make must more complex maps and need a finer way of adjusting the node positions, and running through the distance calculations. If I find a solution to this problem then I will post it for others to see. Thank You!

Beginning Programmer
Professional Nerd
MrValentine
AGK Backer
15
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 31st Mar 2012 12:31




keeping my eyes on this one...

Zotoaster
21
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 31st Mar 2012 13:51 Edited at: 31st Mar 2012 13:51
Don't use constants. They can't ever change, they can't be loaded in, they don't have any type, they're just not good in this scenario (though they are useful sometimes).

Use arrays and types.


The type:



Array:


"everyone forgets a semi-colon sometimes." - Phaelax
Jeff032
18
Years of Service
User Offline
Joined: 13th Aug 2007
Location:
Posted: 1st Apr 2012 06:26 Edited at: 1st Apr 2012 06:26
When trying to find the closest node, you can avoid the slower sqrt() call by just comparing distance squared instead.

Login to post a reply

Server time is: 2026-07-10 18:58:28
Your offset time is: 2026-07-10 18:58:28