PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

Enemy A.I & DirectPlay SDK

Okay, I've been working on a 3D shooter for a little while now and have hit an assortment of problems, ever since i've started. I've now managed to sort out collision, terrain height problems, speed increases (31-35fps) but i seem to have hit a dead end at enemy intelligence. After i succeeded in adding enemy ships without slowing the game down, i've become kinda stumped with enemy A.I. Does ANYONE know of any docs, tutorials or ideas on how to approach this? I know it might seem kinda lame to certain high-profile coders, but remember that i've been out of coding for nearly 2 years, and i don't remember doing any clever a.i before that, anyway. I'm trying to make stealth an integral part of the gameplay (sneak into hq, retrieve x, get x to base, etc) but most of my attempts seem to backfire or become expensive. I really would appreciate any help.

If all else fails and i don't manage to add decent intelligence, i intend to turn it into a deathmatch-style shooter for 2 players, hopefully using the directplay sdk. Has anyone had any experience with this? If i do this 'deathmatch' alternative, i would like for it to be more than a simple 'shoot & hide' type game, and it would be passing more than a couple variables between the 2 devices. However, assuming the limits of IrDA (primary method of connection), has anyone experienced any 'lag' when using the sdk?

I know that i could probably answer my own questions simply by writing test code myself, but due to the nature of my work, i don't get a lot of time to code, but i do manage to do a fair bit of reading while on the road. I would greatly appreciate input or even assumptions from anyone with some knowledge.

Bugger it, if neither plan works out to my satisfaction, i'm just gonna give the current source to someone and let them turn it into something special...
Hello.

Steven Woodcock's (stop giggling at the back) AI page is the best AI page (for games) that I know of:

http://www.gameai.com/

(You want to look in the pathfinding section of the "Resources Quick Jump" frame).

When I was at Uni, I implemented an A* & D* algorithm (badly) to produce a (bad) "pursuit and evasion over a 3d terrain" system, with predators chasing prey all over the place. (Sounds good, but it wasn't).

For the type of game you describe, I'd use an A* or D* system. An A* system is essentially a heuristic based path-finding system that presumes that the terrain and "goal" are static. Given the correct heuristic, IIRC, it produces an optimal path from the start to the goal. I used a weighted grid (weighted on terrain type and on the height delta) to store the "cost" for the terrain.. but all of my animals were land-based... but that's probably overkill for you (my animals had energies, so they died when they starved and could only reproduce if they had enough energy, etc). Depending on what you want to do, a simple flag for each "unit" in the terrain (height-field in your case I think) could be enough to implement a path-finding system. Marking the walls as an infinite cost and everything else as 1 should work fine.

The dynamic A* algorithm (D*) is what you want, I think.. but it may be overkill, too. For a stealth game with a few "enemies" it probably is what you want.. if you're doing a "wave-based" shoot-em-up.. it probably isn't. The D* is essentially a more dynamic A* algorithm - the destination can change and the algorithm can be run in steps, so it's much "nicer" game-wise.

I implemented a rudimentary eye-sight system too:

true line-of-sight over the 3d terrain
eyesight range (angular and distance)

..it worked quite nicely sometimes (if only I'd put a learning system onto the animals and had them learn that they could sneak up on the stupid prey from behind).

The A*, D* algorithms can take up a lot of space for the tree if you're moving over long ranges. To combat that, I simply said that the animals could only move somewhere they could see and made the visual ranges small. It meant that the animals stopped chasing each other when they lost sight of each other, but that wasn't really a bad thing.

Hope that helps, let me know if you need any more info., cheers,

Refractor.
Hey thanks, that's one seriously useful resource! (How come i've never come across it? :) ) My first attempt at implementing line of sight wasn't particularly fruitful as i had enemy ships travelling in short bursts in straight lines until they 'spotted' the player, which wasn't particularly intelligent... You;re right though, the D* algorithm is what i need to implement, as the destination would change frequently, and i also intend to allow the player to 'beam' and move certain small objects. Having only briefly looked over the docs, i think i'm going have to plan my implementation quite thoroughly but hey... That's what a 5-hour plane flight tomorrow is there for, right?! Seriously, thanks for the help, it's greatly appreciated! :?

I would still like to implement an option for a 2-player mode at some point, though so i would still appreciate any input from anyone with experience with the directplay sdk. Surely someone's had some experience with it?
Johan · 01 Mar 2002, 20:48 UTC — OpenTrek
Hi T1,

If you want to build network games, I have a serious alternative coming up: OpenTrek!

<begin announcement babble> :)

This weekend I will release the free multiplayer networking platform OpenTrek. It contains all the features from DirectPlay (safe and unsafe UDP messages, layered multicast groups etc), but has a different focus.

With DirectPlay, you have to create your own "lobby", waiting for players to join etc. OpenTrek can more be seen as an ICQ client without a GUI or any messaging services. Add a custom full screen "awareness" plugin and you have a complete game lobby! Add a chat and you have a messaging service! The cool thing is that the user can choose views on the fly, all of which can be used to start your game! Also, YOU don't have to create lobby applications to get your game working. Just add support for OpenTrek, recompile and begin send network packages (in 5 minutes)!

OpenTrek comes for both Pocket PCs and Windows 2000/XP. You can use it with GAPI or whatever. You can fully "brand" the client for the end user. Adding support for OpenTrek to your game usual takes around 5-10 minutes (to get the single player working). OpenTrek is a project with nearly 2 years in the making, and is based on my previous work as a middleware consultant for Ericsson, Saab and Volvo.

OpenTrek is layered slightly above DirectPlay, and has an open source messaging protocol. It supports development of games using both C, C++ and C++ with MFC.

Be sure to checkout http://www.opentrek.com on Sunday. :D

<end announcement babble>

Best regards,
Johan
Sounds juicy :) . I'll definitely take a look.
Enemy AI is something I have spent a lot of time on. There is quite a bit out there in print on the subject.

I typically employ Prolog or some other AI language for the task, but if you are looking to make smart enemies for the PPC, you should look into the idea of state machines and the like.

And, A* is pretty good stuff for pathfinding.
When you say "in print", do you have the names of any decent books on the subject? I have a strong feeling that i would like to further my knowledge in this area, more complex ai being something that i'm sure i'll implement more in the future.


BTW If anyone's interested, i've updated the left screenshot below to a more current one. I plan to add particle handling soon... :)
Here's a couple. There are sooo many. Go searc around for Artificial Intelligence books, maybe put the word games in the search too.
Be careful though, game programers think AI is path-finding and dump if-thens usually. If you really want AI, you need to look at expert-systems, fuzzy-logic, and evolving state machines. It's a VERY complex subject, but worth picking up on.
I'd suggest just grabbing something on AI and reading. Not even with the intent of using it to code with. Most books will start you thinking about AI in a totally new way, and if it doesn't, it's the wrong book.
<a href="http://www.amazon.com/exec/obidos/ASIN/1584500778/qid=1015096906/sr=1-1/ref=sr_1_1/104-9178739-5958329">Not released yet</a>
<a href="http://www.amazon.com/exec/obidos/ASIN/3790813486/qid=1015096906/sr=1-2/ref=sr_1_2/104-9178739-5958329">Decent background</a>

We should start a new thread on this! :) Personally I have developed expert systems and the like in Prolog. My business partner and I worked out some stuff that we are looking for venture capital for right now. We're talkin' about AI with short/long term memory, learning and growth, evolution and such.

Anyway, back to the point, I would think, that on a PPC a state machine of some sort (optimized for mem usage) would be your best bet. It is gonna be tough to do anything else in C++, the language is just not designed to do that kind of work.
I hope you get your AI working. I've only worked on following paths & zooming to moving objects in 2D so I can't really help but here's a question for you >

Did you make up your collision detection or is it based on a standard algorithm? Any hints

( I'm just starting my first 3D game but I'm using PocketGL as the maths for 3D takes me too long & usually never works. )


Ian
Ah, collision detection! :? For me, that was definitely the most time-consuming and hardest thing to implement. I also had problems with fluctuating frame rates due to the ineffeciency of my original code. There are some good docs on GameDev (http://www.gamedev.net/reference/list.asp?categoryid=45#99), and there are also some good references for ai & other stuff that i only noticed recently. I would also recommend that you think about collision while in the planning stages of your game: In my experience, trying to add it after I already coded some stuff made it particularly tricky to implement. I used the bounding-box method initially which was fast but inaccurate for irregular-shaped objects. It all depends on the type of your game, the type of collision to implement.

I also have a very useful Word document on collision which helped answer some of my basic questions. Let me know if you'd like a copy of it. Good luck!