Some newbie questions about AI

Started by
12 comments, last by ApochPiQ 12 years, 5 months ago

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.[/quote]

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

Omae Wa Mou Shindeiru

Advertisement

[quote name='ApochPiQ' timestamp='1319560939' post='4876810']
[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. :)
[/quote]


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)
--------------------------------------------[size="1"]Ratings are Opinion, not Fact
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.
--------------------------------------------[size="1"]Ratings are Opinion, not Fact

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.

Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]

This topic is closed to new replies.

Advertisement