Jump to content
  • Advertisement
Sign in to follow this  
rexem

Some newbie questions about AI

This topic is 2598 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello,
I'm very new to game developing (it's definitely not something I do for a living, but I figured it's a nice and fun hobby to keep my brains active). I've done all the usual "beginners steps", like creating TicTacToe and such and now I'm creating a real-time game involving battle between ships at sea. The main goal of it is to learn as much as possible, practice my math, logic and such. All goes slowly but steady, and now I reached a point where I want to create a computer player, but since I have no experience creating real-time AIs, I have quite a few questions, with hope someone might lead me to the right path.
I have read tons of tutorials and such, but (I guess I can't find the "right" one) most of them focus on specific algorithms instead of the broad picture.

I just simply don't know where should I even begin? I know my question is not very specific, but I guess I'm not even looking for specific answer. When I'm programming my AI actions should I simply think "what would I do" in one or other situation and code it in hundreds of different "if (..) else (..)" branches covering all possible scenarios?

Well, in other words, let's say you want to implement a simple AI for sea battle game - that is, ship can move around and fire at enemy. What would be your concepts and thought on creating it? Again, I'm not asking for anything very specific, just a basic idea and abstract concepts how such things are usually done. Well, since I'm very lost at this point, any insights or suggestions are much appreciated.

Thank you for reading.

Share this post


Link to post
Share on other sites
Advertisement
Step 1: Break your problem down into the core components of information that you think are relevant to process. e.g. "Where is the enemy?" Think numbers, relationships, and logic.
Step 2: Figure out how to combine those components in ways that are relevant to make decisions with.

Share this post


Link to post
Share on other sites
When starting out with AI for a game it is important to get the scope correct. For example there is little point in developing a self-learning, all singing, all dancing AI that uses every technique from A-Z if it is only going to be in your game with an average lifespan of five seconds...

For me this would usually consist of thinking in terms of "states" for the AI in the game (e.g. Idle, Follow, Attack, Flee, Use_Item etc). You would then create a state transition diagram demonstrating how the AI can switch between states. What is the enter and exit criteria for a state (think numbers, data) that causes a transition etc? You would not want to code states as a series of if-else statements as you will get major spaghetti code plus it is not scalable. This is when you would come across the Finite State Machine (FMS) algorithm which is usually one of the first things people learning game AI come across.

I would recommend reading the book "Programming Game AI By Example" by Matt Buckland. I read a lot of stuff on game AI development as it always interested me but this is the first thing I ever read that really made it click.

Share this post


Link to post
Share on other sites
I would recommend reading the book "Programming Game AI By Example" by Matt Buckland. I read a lot of stuff on game AI development as it always interested me but this is the first thing I ever read that really made it click.

Yep... I second this. Mat's book is a great way to start.


Share this post


Link to post
Share on other sites
Its not just "how would I do it"

its:

Whats the situation (what kind of situation)

then : What am I supposed to do about it (possibly more than one solution that has to be decided upon)

Evaluating the situation is often a big chunk of the processing when dealing with a multi factored situation.

Then the solution decided upon may be more than a single action (a solution with a number of sub actions in sequence)
and that solution may be a whole bunch of sub solutions that have to in turn be evaluated and picked from alternatives

Another frequent complication is ' how long do I do that (chosen solution) before reevaluation again and possibly doing something else'
Dynamic situations keep changing and the current solution might not be relevant any more.

----------

More complicated 'learning' AIs might try to evaluate how well the solution picked actually worked and either increase the chance that
the successful ones are picked OR make the logic that classifies the situation more exact to the factors involved so that a particular solution
that is appropriate to that flavor of situation is chosen by via the modified logic.

Share this post


Link to post
Share on other sites
Well, as step 1 I would suggest this: "don't overestimate the complexity of AI" - it's a lot like diving into real-time graphics in that much of which you see is really smoke and mirrors, so to speak. A lot of game AI relies on relatively simple state machines. Be aware that more complex agorithms (neural networks, particle swarms, game trees, etc.) are just too computationally expensive to use in games, but even so, you can borrow aspects of them when you roll your own AI.

Otherwise, you've gotten some decent replies here already.

Share this post


Link to post
Share on other sites

Be aware that more complex agorithms (neural networks, particle swarms, game trees, etc.) are just too computationally expensive to use in games, but even so, you can borrow aspects of them when you roll your own AI.


Ehh... it's not a matter of being too expensive, so much as there being more efficient ways to accomplish the same results with less resources and often better fidelity in the end product.

Machine learning is used in some games, swarm intelligence has been applied in realtime simulations, and game trees are a fundamental part of many non-realtime games - chess being the big elephant in the room.

There's an awful lot of CPU time available on modern machines. If you want really interesting AI techniques, chances are you can squeeze out enough cycles to make them happen... at least, that's my perspective. I come from humble beginnings on a 1MHz (yes, megahertz, not gigahertz) CPU with 32KB of RAM, so the world seems full of untapped potential ;-)


Share this post


Link to post
Share on other sites

Ehh... it's not a matter of being too expensive, so much as there being more efficient ways to accomplish the same results with less resources and often better fidelity in the end product.


Yeah. Of course it depends on the game but the biggest reason that we don't use any of those solutions is that they aren't "directable": in the sense of directing actors. Most single-player action games require hand tuned encounters with the AI doing very specific things at very specific moments or at least being able to be directed by the level designers to achieve a certain effect. Most of the more complicated "real AI" algorithms are meant to be emergently intelligent and/or act more like an actual human. While that may be fun in multiplayer, it's often not fun at all in single-player. Single-Player AI tends to be more about smoke and mirrors and the illusion of intelligence; think of most game AI as a foil for the player mechanics, not as some kind of artificial human.

A friend of mine said it the best "the role of single-player AI is to die convincingly".

-me

Share this post


Link to post
Share on other sites
I am be a noob too in AI but I know a pinch not enough to help really but i know that it's about breaking down a problem and solving it with logic which applies in a programming sense.

for example you can incorpate little AI such as if you draw one object like imagine a grid and you draw one object at point X 50, Y 0. 50 pixels to the right from the top left and Y 0 means right at the top of the grid. if you place an object under it and tell it to move left and right continously then you have a control function tell the object to move accordingly to its initial X position from the other object. this is, in fact, AI to a very small extenet. but beyond that sorry! im learning too. :P hope i was kinda helpful and serry for spelling

Share this post


Link to post
Share on other sites

[quote name='J-dog' timestamp='1319535895' post='4876680']
Be aware that more complex agorithms (neural networks, particle swarms, game trees, etc.) are just too computationally expensive to use in games, but even so, you can borrow aspects of them when you roll your own AI.


Ehh... it's not a matter of being too expensive, so much as there being more efficient ways to accomplish the same results with less resources and often better fidelity in the end product.

Machine learning is used in some games, swarm intelligence has been applied in realtime simulations, and game trees are a fundamental part of many non-realtime games - chess being the big elephant in the room.

There's an awful lot of CPU time available on modern machines. If you want really interesting AI techniques, chances are you can squeeze out enough cycles to make them happen... at least, that's my perspective. I come from humble beginnings on a 1MHz (yes, megahertz, not gigahertz) CPU with 32KB of RAM, so the world seems full of untapped potential ;-)



[/quote]

You're right, of course... I should have been more concise with what I said, as I was generalizing popular real-time genres there. Having said that, I guess the idea is that a lot of these learning algorithms are overkill in most (gaming AI) instances. And although you're right in saying that there is an awful lot of CPU time available these days, I think it also stands to reason that it is awfully easy to hoard / waste that time if you aren't careful. For instance, I coded chess AI with game trees once - and although I admit I did not code it very elegantly (it was just a straight-up game tree, using OOP no less), it was almost unsettling seeing how performance could deteriorate if the algorithm used a large enough depth. The computer opponent would eventually take close to 10 minutes to make a move as the game went on!

Of course... that was a brute force approach. There are always ways to optimize that - or - just plain cheat. :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!