🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Newbie alert

Started by
3 comments, last by Grat 23 years, 1 month ago
I am very new at programming, and am programming in C, and am quite confused by all of this AI stuff. Firstly, i would love for someone to explain about all these pathfinding modes. Are they all just like theories, that you have to make yourself on the same basic principles, like A* there is no actual program or A* code, but its an idea that you use for pathfinding. I have been making a turn-based game, on a grid, and am in the middle of working on pathfinding on it. One problem that is worrying me is that everytime i play the same level the computer will take the same path everytime. From as far as ive worked out, this can be fixed by fuzzy logic or something but ive absolutely no idea of how to do this. I was going to post the source code up on my website and link to it, but im afraid that it would be too confusing for even the most understanding programmer to sort through. Also, there have been many bugs in the code that ive been doing tests to check for, and the extra, seemingly pointless code, would just add to the confusion. But basically my pathfinding code goes like this: choose a direction towards the player check if its clear if so, move there and update if not, look clockwise to a square thats empty if that square is empty move there check if ive reached the goal if not start again if so walk the first part of the path (this will change to move 2 or more squares once i get it working there is a bug in the code that i just cant sort out, if anyone wants to have a look at the code ask and ill post it up and link to it, but be warned that it wont be pretty!
Advertisement
A* is an algorithm. You probably won''t find any code that you can just plug into your engine, but there should be plenty of pseudocode which you can translate out there. It''s not only used for path-finding though. Originally, it was developed for searching through trees for things like chess games, but if you think of a map as a tree where each node points to the next possible places you could go (along with, for example, a "cost" factor for traversing that branch), then A* searching works quite well. Have a look on sites like this one, or flipcode, or gamasutra. There''s bound to be plenty of path-finding algorithms described there. You won''t get it given to you on a platter though, since every game is different - you can''t just write it once for everything.

A* is a good algorithm, since it''s what''s called "optimal". That means that the path it finds will "always" be the shortest (assuming you use an "admissable" heuristic for you estimation of the "remaining cost" to the destination. That is you never overestimate how far you have to go.) it will also find it in the smallest number of steps possible - there is no other possible algorithm that will find the best path in a shorter number of steps - ever.

War Worlds - A 3D Real-Time Strategy game in development.
Try tossing a few random numbers in the choicemaking, random numbers are great at making the ai seem more, heh "randomlike"...
The reason your AI units always take the same path is because they don''t have any cognitive abilities coupled with prior conditions. In other words, at gametime startup, your AI units have not been involved with any situations from before game startup and they don''t have any complex reasoning abilities to act on such prior situations even if your game provided them.

Nothing is really that random. You can use randomness to create the notion of more complex activity, but sometimes that random activity will just appear stupid. In reality (real life), another unit in an environmment would not always take the same path because the unit would be simultaneously processing and / or be distracted by sensory information and internal thinking process including, but not limited to: that fly buzzing around his head, the glint of light ahead on the floor, the girl he dated last night, whether his gun is loaded or not, the sound of footsteps down the hall, etc. In a complex agent AI, there would be thinking processes inside its head and sensors which create a number of disparate, sometimes distracting information which can lead to a number of possible choices. If at game startup, all these processes were EXACTLY the same, and all the sensed processes were EXACTLY the same, and the sensed activity of the player was EXACTLY the same, then the unit would take the same path everytime.

So, there you have it. Use randomness, or create a more complex unit that behaves on different initial preconditions including different preconditions of the history of the agent''s experiences.

_______________________________
"To understand the horse you'll find that you're going to be working on yourself. The horse will give you the answers and he will question you to see if you are sure or not."
- Ray Hunt, in Think Harmony With Horses
ALU - SHRDLU - WORDNET - CYC - SWALE - AM - CD - J.M. - K.S. | CAA - BCHA - AQHA - APHA - R.H. - T.D. | 395 - SPS - GORDIE - SCMA - R.M. - G.R. - V.C. - C.F.
Here''s a useable example. The agent''s girlfriend rejected him last night, therefore he feels he has less to live for and so takes bigger risks. If he takes bigger risks, he chooses paths which are more direct but open to more vulnerability. On the other hand, let''s say he recently came into a large fortune yesterday and is looking forward to retirement extremely soon. In this case, he doesn''t want to take risks at all, he just wants to survive. He will take safe routes, hide in waiting for a sure kill via some type of ambush.

Basically, give a random precondition describing your agent''s risk modifier over and above your agent''s baseline risk taking propensity.

Here''s another example. Your agents hear sounds, both of the player and the other agents. If the agent was aware of another agent in the vivinity, then the agent can reasonably assume that the sound came from that other friendly agent. If the agent was not aware of another in the vicinity, then perhaps the agent cannot identify who is making the sound. In this case, the agent''s level of caution should go way up, and this would change the agent''s tactics.


_______________________________
"To understand the horse you'll find that you're going to be working on yourself. The horse will give you the answers and he will question you to see if you are sure or not."
- Ray Hunt, in Think Harmony With Horses
ALU - SHRDLU - WORDNET - CYC - SWALE - AM - CD - J.M. - K.S. | CAA - BCHA - AQHA - APHA - R.H. - T.D. | 395 - SPS - GORDIE - SCMA - R.M. - G.R. - V.C. - C.F.
Thanks for all of your help. Ive finally got the pathfinding to a working model, but computer works on two states of mind. Check if you have line of sight. If you do, shoot, if you dont, set the pathfinding goal to the player''s co-ords. Hardly complex but im happy with it, at least ive made some advancement, now i can have some fun with the AI. The thing is, the pathfinding algorithm works so that the computer is obsessed with being on the same axis, be it x or y, as the computer, and to me it comes across as simple-minded behaviour. However, when i showed a friend, without having time to explain this, his reaction was ''cool, hes making use of the cover as he advances.'' This was because my friend was hiding at the end of a line of wall, and the wall had small indents in it. Due to the computer trying to have the same x axis, he would enter these indents every time he could. So basically the intelligence is in the state of mind of the player, another friend might think ''Jesus what an arsehole, why cant he just hurry up, he knows i cant get him''.

The task im having a problem with now is tactics, or at least some form of large-scale intelligence. I have no idea how to make the computer use ideas, no matter how trivial, like hiding around corners, or co-ordinating attacks, or waiting for me to come with him. Any help would be greatly appreciated. Also my pathfinding is slightly ''unoptimized'', in other words when he cant move directly to his target he does extremely stupid stuff like zigzaging, but i don want to be too over-dependant on this board to sort out my programming problems, so never mind about that, thanks for all your help again!

This topic is closed to new replies.

Advertisement