Jump to content

  • Log In with Google      Sign In   
  • Create Account

Some newbie questions about AI


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
13 replies to this topic

#1 qis   Members   -  Reputation: 100

Like
0Likes
Like

Posted 20 October 2011 - 12:11 PM

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.

Sponsor:

#2 IADaveMark   Moderators   -  Reputation: 2463

Like
0Likes
Like

Posted 20 October 2011 - 06:11 PM

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.
Dave Mark - President and Lead Designer of Intrinsic Algorithm LLC

Professional consultant on game AI, mathematical modeling, simulation modeling
Co-advisor of the GDC AI Summit
Co-founder of the AI Game Programmers Guild
Author of the book, Behavioral Mathematics for Game AI

Blogs I write:
IA News - What's happening at IA | IA on AI - AI news and notes | Post-Play'em - Observations on AI of games I play

"Reducing the world to mathematical equations!"

#3 rwilson1982   Members   -  Reputation: 118

Like
0Likes
Like

Posted 21 October 2011 - 06:34 AM

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.



#4 IADaveMark   Moderators   -  Reputation: 2463

Like
0Likes
Like

Posted 21 October 2011 - 07:22 AM

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.



Dave Mark - President and Lead Designer of Intrinsic Algorithm LLC

Professional consultant on game AI, mathematical modeling, simulation modeling
Co-advisor of the GDC AI Summit
Co-founder of the AI Game Programmers Guild
Author of the book, Behavioral Mathematics for Game AI

Blogs I write:
IA News - What's happening at IA | IA on AI - AI news and notes | Post-Play'em - Observations on AI of games I play

"Reducing the world to mathematical equations!"

#5 wodinoneeye   Members   -  Reputation: 818

Like
0Likes
Like

Posted 25 October 2011 - 03:34 AM

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.
--------------------------------------------Ratings are Opinion, not Fact

#6 J-dog   Members   -  Reputation: 120

Like
0Likes
Like

Posted 25 October 2011 - 03:44 AM

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.

#7 ApochPiQ   Moderators   -  Reputation: 15698

Like
1Likes
Like

Posted 25 October 2011 - 10:42 AM

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 ;-)




#8 Palidine   Members   -  Reputation: 1279

Like
3Likes
Like

Posted 25 October 2011 - 11:16 AM

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

#9 SWQUEENIFY   Members   -  Reputation: 82

Like
0Likes
Like

Posted 27 October 2011 - 06:52 PM

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



#10 J-dog   Members   -  Reputation: 120

Like
0Likes
Like

Posted 28 October 2011 - 12:00 AM


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 ;-)




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. :)

#11 LorenzoGatti   Crossbones+   -  Reputation: 2694

Like
0Likes
Like

Posted 28 October 2011 - 03:48 AM

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?

You can break the AI problem into manageable pieces through abstractions:
  • Fleet level AI gives very simple high level orders to ships: attack there, form a line here, etc.
  • Every ships interprets orders and acts independently from the others: where do I want to go? Which enemies should I shoot? Am I on a potential collision course?
  • Every ship maps a small set of objective types (e.g. arrive to a certain location with a certain angle and speed, shoot down a certain enemy, evade an incoming torpedo) to a small set of command types (turn and shoot guns, rudder, engine power) according to well-defined sensor inputs (e.g. see ships up to a certain very long distance).
  • This mapping from objectives to commands can be further structured and constrained: with states, as rwilson1982 suggests, with exact geometric computations (for example to obtain shortest paths and deadlines to steer before projected collisions), with rules, evaluation functions and random choice to select plans (for example, closing in for broadside shooting vs retreating to use long-range weapons), with fixed scripts (for example, retreat after taking "enough" damage), with pockets of opaque machine-learned behaviour (for example, a neural network that selects enemy ships to shoot based on their type and position).

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.


Every game type has its special concerns. In your case, ships:
  • Are unable to move freely, requiring high quality and unusually long term path planning.
  • Can collide with friendly units, requiring path planning to predict and avoid collisions. Compare with aircraft, which could realistically pass through each other in a 2D map by implicitly flying at slightly different height.
  • Have limited shots and possibly long weapon reload times, requiring attacks to be optimized.
  • Have very important weapon range and angle constraints, which need to be represented in detail and accounted for in order to attack and evade effectively. Compare with a FPS, where with few exceptions you can turn freely to shoot your only weapon at anything in sight.
  • Can keep going after losing a number of subsystems (guns, engines, etc.), requiring the AI to adapt to reduced capabilities.
  • Operate in formations, requiring some form of coordination (top-down with whole-fleet orders, bottom-up with rules applied by each ship, or both).

Produci, consuma, crepa

#12 wodinoneeye   Members   -  Reputation: 818

Like
0Likes
Like

Posted 05 November 2011 - 12:25 AM



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 ;-)




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. :)



Any wonder why I shudder when I hear people trying to use interpretive 'scripting' languages for 'AI' even when I know that what they are doing is very shallow AI
(versus real AI that takes magnitudes more CPU to even do a limited AI solution)
--------------------------------------------Ratings are Opinion, not Fact

#13 wodinoneeye   Members   -  Reputation: 818

Like
0Likes
Like

Posted 05 November 2011 - 12:33 AM

Your AI will have to contend with whatever game mechanics constitute your game.

If its a sailing game having the wind guage becomes a primary factor.

If its a modern sea game then spotting the enemy first and getting the first shots in is paramount.

If its WW1 then massing fire (destroying enemy in detail) is most important.

Ftleet games versus solo encounters offer further complications.


These are goals for your AI and it needs to figure out how to get into these advantageous situations (and deny the same to the enemy)



The AI has to plan into the future and estimate where the enemy units will/might move (and how the terrain will effect them).
Much Ai is designed to find optimum solutions when in real life its position with the most utility that MAY lead to a win is the smarter path.
--------------------------------------------Ratings are Opinion, not Fact

#14 ApochPiQ   Moderators   -  Reputation: 15698

Like
1Likes
Like

Posted 05 November 2011 - 10:12 PM

Any wonder why I shudder when I hear people trying to use interpretive 'scripting' languages for 'AI' even when I know that what they are doing is very shallow AI
(versus real AI that takes magnitudes more CPU to even do a limited AI solution)


You're gonna have to back that up with some seriously hefty evidence.


I've personally shipped several games that ran purely on DSLs for AI, and ran more agents at higher depth and richness simultaneously than practically any other contemporary titles. I know of many more titles that relied on high-level languages for AI implementation, and I'm sure there are still more out there that I'm not familiar with.

Basically, I would like to politely suggest that your "shuddering" is totally unfounded at best, and outright misleading and damaging to the uninitiated at worst.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS