Jump to content
  • Advertisement
Sign in to follow this  

Help on Game AI Design

This topic is 2122 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

Hey guys.


I'm "finishing" the development of a game, and one of the final tasks is to make a decent AI for the game.


I have already a very crude AI that took me like 2 hours to make 2 months ago, but it's way too dumb, and now I need to improve it to make the game challenging.


Of course there's no silver bullet in AI, so my plan was to give the experts some info so they can suggest the path they would take if they were developing the game, so I don't waste time on dead-ends.


So, as a background, the game is called Big Boss TV: it's a "Tycoon" game where each player runs a TV Station and compete against the other stations. For more info, this is the game: http://www.gamedev.net/page/indie/project.html/_/simulation/big-boss-tv-r11



If you're gonna skip the long explanation, think of the game as any other Tycoon (or business management) game. I believe the AI ideas will be similar. Old games such as Mad TV (which is the inspiration for this game), Pizza Tycoon, Detroit, Transport Tycoon, etc.


Full explanation:

On each stage there are 3 players competing for the same goal (1 human and 2 AIs). Lets say the goal is always the same no matter which stage you're playing (in fact it's not, but the AI don't need to be so flexible - as long as it plays well towards a fictitious goal, it's good enough for me). Let's say this fictitious goal is to accumulate $5 million before the 2 other players.


I'd rather have the AI not to cheat, so it would be better if it had limited knowledge like the human player does (for example, the human player doesn't know how much $ the other players have). But if this makes the AI programming much more complex (or too dumb), I can live with a cheating AI.


On a high level, the players have to do certain actions:

- buy movie tapes

- buy news tapes

- hire anchors

- buy antennas

- sign ad contracts

- schedule movies/ads


And the game is real time, so to do each of those actions the player must go to a certain place (which takes time).


One of the main challenges for a player is to know how much audience will a certain scheduled (future) program have. The better that guess, the easier is to plan ahead (which movies to buy, which ad contracts to sign, etc), so the outcome of the decisions is better. But the audience has 3 uncertainty elements:

- a "hidden complex formula" which the average human player will never know

- a random element

- and also depends on the actions of the other players (eg, if the competitor schedules a top notch movie on the same time, you're screwed)


Well, without making this post extremely long, hopefully this amount of info is enough to help you guys help me.


So, any pointers? I don't have experience and much knowledge in AI, so please use examples/references if possible smile.png .



Ah, forgot to mention: since the beginning I had this wish of having an API with the possible interactions (the game is designed as client-server, so I already have the API almost ready) and make the AI interact through this API. So far no big deal, but also I wanted to make the AI as an external script (Lua or something). Any pointers on this? I assume that since I have the API ready, this should be somewhat easy to implement.



My plan is to finish this AI tomorrow or mostly Thursday. So tomorrow morning I will start it, and I will keep this thread updated with my progress (even if it's to say "Finished already, thanks anyway" ;) ). Obviously your input will be very valuable and will make me lose less time, and probably do something with more quality, so hopefully I will get some input in time :) .



Edited by Rottz

Share this post

Link to post
Share on other sites

Hey all.


I had to do some other tasks yesterday and this morning (had to update my already existing game), but now Im finished so Im back to BBTV's AI.


So, yesterday I completed/rewrote the AI's API, that is, the exported game functions that the AI can call. Then I started making the AI itself (started fresh), and this below is what I came up and am doing. Please advise if you see a better path :) .


The AI is composed of a simple infinite loop:


- decide next task

- do task until finished or aborted


The task is an instance of a simple class that has the task type (walk to certain place, idle, buy certain movie tape, etc) and parameters (which movie tape to buy, where to walk, etc).


The 2nd part of the loop ("do task") is the simpler part, as there's no intelligence involved. It's a simple method that using the game API sends some commands when needed to make the computer's avatar do whatever it was commanded to do. For example, on the "buy movie" task, it checks whether the avatar is on the movie shop, and if not it commands the avatar to move to that destination. When it gets there, it sends the command "buy movie" to the API and then finishes the command and go back to the loop.


The 1st part ("decide next task") is the actual AI part and is what Im starting now. This is what I planned:


1) I created a "Strategy" class that controls the player current needs. Its basically a pack of indicators that value from 0 to 10 that tells how important is that factor right now based on the match context. For example, "money" is one of these indicators: if the player is low on cash (or even worse, negative), this indicator will be very high. Being very high, the idea is that on the array of possible actions, the action that solves this short term need will be highest ranked and selected. In an extreme case (say, the player has negative cash, so the score is 10) the action might be sell out some of his assets (tapes, antennas) to "survive".


2) Initially I need to actually calculate these strategy indicators, so this is where I call the game API to get lots of context information about the match. For example, the indicator "movie tapes need" can be high when the player has only a few tapes, or the competitor tapes are better, or he's not doing well on audience... 


3) Then I simulate all the possible actions. To do that I have pre-defined weights for each action type against each strategy indicators. Also I will need a second factor to weight in: I need to estimate how applicable is the exact action right now (given the game context). This factor I think it can be a percent: so if that action can be perfectly executed right now, then I give it a 100%. If it wont give any result at all, I give it a 0%, etc. To illustrate: when the player is low on cash, certainly one action that would be highly ranked is "Ask for a loan". But that action isnt always available, for example if you already have a loan, you cant take another (so "Ask Loan" would give no result in this case).


4) Then I simply set the next action as this that was just created.



The biggest problem is of course Step 3, given the potentially infinite number of possible actions. Before simulating individual actions I think I will rank the action types and select the top 3 action types (ex: buy movie, buy antenna, buy news). Then for each of these 3 action types I use some reasoning (no idea how yet) to simulate maybe 3 specific actions that I think that will succeed (buy movie A, buy mobie B, buy movie C, buy antenna size 2 on area 1, buy antenna size 1 on area 3, ... ). Then I generate the 9 actions, add a little random element to its score, rank it based on the score and select the best.


Well, I think it will be hard to finish this today, but hopefully tomorrow it will be ready.


Any inputs? Ideas? Problems? Optimizations?



Share this post

Link to post
Share on other sites

I have not done any AI for a while, but from memory I think the Naive Bayes Classifier might be appropriate here.


The classifier takes input in the form of scores you provide it. In a shooting game example, Say we have 3 input variables; Number of bullets, Health, Health of Target. If you have very little health and only 2 rounds left, you are unlikely to attack a strong opponent, so you give that action a low score. Running away on the other hand would be given a high score.


You create example scenarios, more are needed for accuracy as the number of input variables increases, and you give it to the classifier. The classifier then uses this example data, to calculate the probability of any given action given any input, aka input it has not been "trained" with.

So if you wanted a cautious AI, the classifier might learn from the training data, that attack is usually given a low score when bullets are low.


The advantage of using this technique, is you can easily adjust the personality of the ai simply by giving it different training data. I don't know if this is any use to you, but it is one possible approach. The game looks good btw, well done

Share this post

Link to post
Share on other sites

When making AI, I always try to remember not to over-complicate it, because it only needs to be viewed from the player's perspective. They often can't tell whether the AI makes a choice because it's clever, random or stupid. It's the same with a real opponent.


I might have lots of fun setting up a complex decision-making system based on needs analysis, 'thinking time', etc. Ok, I *will* have lots of fun doing that! :)


However, there may be a simpler way. For example, there may be a handful of different AI styles that could be simpler to program, then your game randomly chooses which style to use when assigning opponents.


The styles might be:

  1. Scrooge: the AI never spends big money on a tape (or anything), but instead tries to accumulate money without losing it.
  2. Ratings, ratings, ratings: the AI takes whatever action will get it the most ratings, in the short term. So, it might buy a great tape and then not have much money for a while.
  3. Steady as she goes: the AI buys mid-range tapes and has all settings to mid-range.
  4. Jackpot: the AI 'saves up' for one big move.

You could even give the AI a particular name when it is using a particular style of play, so the player can get used to the strategy over time just like with fighting real regular opponents. And players can talk about their success and strategies for particular combinations of AI opponents, which makes the game more enjoyable for certain players.


AI is usually the most fun for me when simple systems produce unexpected and complicated behaviours. In the case of this system, the player will be facing two AIs with one of a large number of combinations of styles, which can lead to a very wide variety of game experiences if everyone is competing over the same resources.


When designing styles of play, the idea is to make the AI always do the same simple behaviours, so your CODE (your effort) isn't complicated, but the GAMEPLAY (effect for the player) is.


I should probably terminate my waffle there. I tried not to make this a long reply, and just give the general principles, because I think that's what you're looking for. I hope this helps!


Ben :)

Share this post

Link to post
Share on other sites

I don't have experience in AI specifically, but the recent approach Rottz chose sounds overcomplicated.


From what I read it seems like opponents can't actually win without doing tasks in the right order. You might as well cheat, let the AI know what the next perfect decision is, the next imperfect one and so on, roll a random number each time they decide for a chance of making a correct decision. You could be done in an hour.


If your goal for a challenge to the player is not the game, but the opponents themselves, then a tactically sound thinking calculating killing machine with some human-like flaws is perfect.

Share this post

Link to post
Share on other sites

Hey guys, thanks a lot for the replies!!


@foxcode : initially I wanted to go along the lines you described, but I didnt know the name or how to do it. I like the idea of "training" the AI, so I could leave the AI playing against itself for a few days, save all the training data and then load it on game start. I might try to go this way on the next implementation (which Im feeling will be needed before release), I just have to read a bit about it before trying, but knowing it's name solves half of the problem already :)


@BensBucketGames : yeah I love the challenge of it also, the problem is that Im short on time... I wish I had a couple extra weeks to work on it. But anyway, after releasing I can continue to work on the AI and improve it, so Im not so worried, as for the beginner player the opponents are not very much relevant (if they end up too smart, I will have to dumb them down). But I love the idea of having different personalities, that way I can mix different AI personalities on the same match so the AIs dont look and act exactly the same, providing a wider range of outputs for the gameplay.


@ActiveUnique : you have touched 2 very important points. 1) Yes, it is overcomplicated. While implementing it on Thursday/Friday I noticed it is way too complicated, and also it didnt work very well (I will make a new post about it when I actually finish or abandon that approach). 2) For most players (beginners) the challenge and fun is the game itself, and they will mostly ignore the opponents, so the AI isn't very important for those players.


Well, I will go back to the AI now and hopefully in a few hours I will have it finished. Hopefully I won't have to throw it away :) . But certainly I will have to restart it from scratch sometime soon.


Thanks again, and I will post an update here later.

Share this post

Link to post
Share on other sites

Hey again.


So, I've got the first version of the AI working. Cant tell if it's good yet, would have to play against them a few matches, but its working (as in "not crashing"), and seems to be (way) better than the last AI version.


Just as a recap, I had planned originally to decide and save a "goal", to then match the goal to a task, then create 3 tasks of each goal type, and then compare the task scores. I ended up not doing that, and what I will do now is simply create a single task of each type and assign a score to it. Then I pick one of the top tasks randomly based on the score.


Seems to be working fairly well, but I have to play and tweak the constants used on the formulas. But I think that for now it's fairly usable/testable.


What about the scripting part: does anyone have experience on that? That way it would be easier to allow other people (other programmers or even players) to help me on the AI.


Best and thanks again.

Share this post

Link to post
Share on other sites

Sorry, I forgot the API question in my obsession with AI. ;)


Not that I have anything helpful to add, as I have no experience with adding a scripting language. I've programmed in a scripting language before, on a MUD. However, there's bound to be a few helpful posts/articles here on GameDev.net. Let me/us know if you find anything particularly well-written?


Alternatively, you could just ask for the help in your actual language. Your helpers might need you to add some querying/setting functions into your existing code, but it shouldn't delay you quite as much as learning and implementing scripting.


Ben. smile.png

Edited by BensBucketGames

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!