• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0

Game Ai advice

6 posts in this topic

My first post here. Please forgive the post length. I'll provide some background. I'm a mature-age hobby programmer working in a small team that is working on an addon/enhancement for a commercial combat flight simulator game. The game already has collision models, flight models, aircraft models, maps, terrain textures & all those things necessary for a combat flight simulator. Aircraft and ground objects 'missions' are scripted in a text file ie waypoints with actions to be taken along the path. Objects already interact independently of scripted code. eg. An anti-aircraft unit will automatically start to fire at an enemy plane when the plane comes within range.


What we are aiming to do is to build a persistent-war for the sim. One where on-line players can jump in & the Ai is 'controlling' the war much as a 'General' would control his army. ie deciding where units are sent, what their missions will be, what the current overall strategic situation is like, what the strategic goals of the army objective will be (which may change over time or as the battle progresses). It is intended that this 'war' could run for weeks. The scripting language is C# which I'm confortable using. The game code exposes many different events within the game eg OnAircraftTakeoff method will be fired when an aircraft takes off from an airfield. game events, outcomes, stats and any other needed information would be stored in a MySql database (again we know how to do this OK).


I'm interested in using something like a simulated annealing approach to developing a strategic Ai to 'control/manage' the war. I'm not dumb, I understand the idea behind the algorithm heuristics, but I can't get my head around the practicalities of coding such an approach.


1. How to determine overall META strategy for an army? (This would be equivelent to a General controlling the army)

  • attack enemy airfields (to destroy planes)?
  • attack enemy shipping (to reduce supply)?
  • attack enemy factories (to reduce production)?


2. How would the Ai 'decide' when to switch META strategy?


3. Once META strategy is determined, how to get the Ai to 'decide' which missions to run & what strategy each squadron/army sub unit should use? (This would be equivelent to a wing commander, division Colonal or Brigade Commander controlling forces under his command)

  • Send bombers to bomb a factory? Which factory?
  • Send fighters to scout-out enemy aircraft as a defensive manouver?
  • When to move AA units to be more effective to intercepting enemy bombers?
  • When would a bomber squadron 'decide' not to travel a certain route to target due to AA losses?
Edited by aussalmo

Share this post

Link to post
Share on other sites

There are a few algorithms to determine your actions, I believe the most simple one is the minimax (https://en.wikipedia.org/wiki/Minimax).


Here is my five minutes explanation to give you the main idea of the way it works (probably not really good, but there are thousands of great articles on the internet about it).


First must define an evaluation function that given an army, determines one score for each strategy, this is probably a hard and subjetive task and pretty likely you will need to put a lot of twinking on it. For instance of points you can check to determine the score of an strategy:

- you can check how well defended are the airfields, the shipping and the factories.

- In case of a direct conflict how many resources you will lost and compare it with enemy loses, you may also include some factor for resource aquisition (for instance, I will lose more resources, but I have a lot remaining, while my enemy has nearly none, so this is good for me) and rate of production (I will take 2 minutes to recreate the lost unities, my enemy will take 4, so this is good for me).


After you got this function, you run it for the possible strategies for your army, then you check the counter mesures your enemy would take and run the function to those, and so on. In the end you will have a decision tree (look at the wikipedia article, this forum won't let me post in svg format). Now you pick the best result when it is your turn, and the worst when it is your enemy's turn (hence minimax). In the end you will filter the path of the best strategy. Keep running this algorithm from time to time to assert if you should keep your plan.


This is one of multiple ways, I believe it is the most simple one, and a good one because it will make your logic more organized (as you just need to twink the evaluation function), otherwise you may end up in an if-else hell.

Edited by KnolanCross

Share this post

Link to post
Share on other sites

Instead, you should think about the "I" part of AI. A handy mnemonic is "What would I do?" - not just "I" in the sense of an abbreviation for "intelligence", but also "I" as in "me."
Think about how you would play the game you're writing an AI for.
As ApochPiQ says, this is all AI does, it just plays the game for you.
So to write AI, you pretend you're the AI, then just write code to do what you would do.
then you test it to see how good your strategy is.
and then comes the tweaking and perfecting. eliminating weaknesses in the strategy, adding more code to handle more special cases or handle common cases even better, etc.
the natural evolution of this process tends to lead to a hierarchy of expert systems and states. essentially a big decision tree. at each decision point, some branch is taken, defining a "state". 
so for example the top level expert system would select targeting planes vs supplies vs production as the overall strategy or "state". lets say it selects "production". so then the production strategy expert system takes over and makes the next lower level decision, and so on, right down to pull the stick back, kick hard left rudder, roll left, full throttle, "gunza! gunza! gunza!".
how an expert system at any level actually decides what to do is up to you. you can use stuff like min-max etc. but usually, just playing the game shows you what the AI ought to do, and it seldom requires weirdo complex AI algos.
for something like planes vs supply vs production, you might apply rules as follows:
1. if any of the 3 strategies can be accomplished much more easily than the others, use it. IE if their air force is almost dead, then try to finish them off. if their factories are almost gone, try to get the few remaining. if their merchant fleet is almost wiped out, go after that as the way to a quick victory.
2. else if they have a lot of planes, go after planes to establish air superiority.
3. else if merchant fleet is almost dead, go after supply.
4. else go after production. going after the enemies means of waging war is usually a very effective strategy.
coding up something like this would not be too difficult.
you might use some variables such as % left alive for air force, merchant fleet, and factories.
then the AI rules above reduce to simple checks like:
if (airforce < 10%) attack_planes_AI
else if (fleet < 10% attack_shiping_AI
else if (factories < 10%) attack_production_AI
else if (airforce > 50%) attack_planes_AI
else if (fleet < 33%) attack_shipping_AI
else attack_production_AI
the above is an example of what the code for the top level expert system might look like.

Share this post

Link to post
Share on other sites

the behavior of the example above would be as follows:


at the start of the war, the AI would go after planes. once  the enemy air strength was reduced to 50%, it would switch to factories, unless the merchant fleet was 2/3's dead, in which case it would go after shipping. anywhere along the way, if enemy air power, shipping, or production falls to 10%, it would switch tactics and concentrate on that as a knock out blow.


already one improvement:


irregardless of the strategy (planes, ships, factories) you'd probably want to allocate 10% of your forces to each of the ones not chosen. IE 80% ships, 10% planes, 10% factories, etc. 


you'll also want to take into consideration the condition of your air force, shipping, and factories, and what the enemy is doing. if you're low on factories and the enemy is targeting your factories, you'll want to go after planes to protect your factories and avoid defeat.


often times, the checks for avoiding defeat will appear first:


if (half_dead()) run_away()


followed by the checks for achieving success:


if (hostiles_nearby()) fly_to_closest_hostile()

if (hostile_in_LineOfFire) shoot()


Share this post

Link to post
Share on other sites
The actual task of your AI is providing the combat flight simulator player with fun missions, not winning the war; as its only opponent is a copy of itself rather than a human strategist, it needs to make reasonable and plausible decisions, not particularly optimal ones. Subtly cheating against the player's faction when it's ahead would be a good way to ramp up difficulty for the player and make a campaign last longer. In exchange for not even trying to be optimal, your AI needs to care about what missions the player can choose: among several possible missions of similar type, how can you predict which one is more fun? Is there a good variety of available missions at all times?

Share this post

Link to post
Share on other sites

The actual task of your AI is providing the combat flight simulator player with fun missions, not winning the war


so its really a campaign and mission generator, not AI to run a "side" in the game.


different, yet somewhat similar.


I did a space flight sim where a politics engine drove something like a dozen campaign generators, which in turn drove something like two or three dozen mission generators. and the mission generators could generate hundreds or thousands of possible missions, before you even got into number appearing and initial placement. the game had something ridiculous like 58,000 different possible missions.


again there, i used an of AI like expert system (the politics engine) to determine what type of campaign to run (similar to air superiority vs anti-shipping vs anti-production in this case). the generator for a given type of campaign controlled mission flow and assigned missions based on current game state, again using its own expert system to choose missions. a mission generator determined things like target type.


so the approach will be the same, but you'll think about it from the commander-in-chief's point of view: "if i were the boss, what strategies would i pursue under which circumstances?". this gives you your AI rules for selecting strategies.


once a strategy is selected, the question becomes: "given that i'm pursuing strategy 'X', what are appropriate missions to assign, and under which circumstances?".

this gives you your AI rules for assigning missions.


then you just code up the rules into your expert systems. one to choose strategy, and one for each strategy to choose missions. no real balancing required. just a little tweaking of the odds of getting this mission vs that mission kinda thing.


Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  
Followers 0