Hebi

Behavior RPG AI and Fairness - player's characters stats public to AI

Recommended Posts

What worries me is fairness, I don't want an AI with "god eyes".

In a first attempt, the AI wasn't smart at all. It has a set of rules, that could be customized per possible enemy formation, that makes the AI acts as it has personality. For example: Wolves had a 80% prob of using Bite and 20% of using Tackle.

Then I tried to make the AI do things with sense, by coding a reusable algorithm, then I can use rules to give different enemies formations different personalities, like this one is more raw damage focused and this other more status ailment focused. To achieve this I was trying to make the AI player to collect stats about the human player skills and characters by looking at the log, my game has a console that logs everything like most RPGs (think Baldur's Gate). An attack looks like this in the console:
 

Wolf uses Bite

Mina takes 34 points of damage

Mina uses Fire Ball

Wolf takes 200 points of damage

The AI player has a function, run(), that is triggered each time a character it controls is ready to act. Then it analyzes the log and collect stats to two tables. One with stats per skills, like how many times it was used and how many times it did hit or was dodged, so the AI player knows what skills are more effective again the human player's team. These skills stats are per target. The second table is for human player's character stats. The AI player is constantly trying to guess the armor, attack power, etc, the enemies have.

But coding that is quite difficult so I switched to a simpler method. I gave the AI player "god eyes". It has now full access to human player's stats, two tables aren't required anymore as the real character structure is accessible to the AI player. But the AI player pretends that it doesn't have "god eyes" by, for example, acting like it ignores a character armor again fire, until a fire attack finally hit that character, then a boolean flag is set, and the AI player can stop pretending it doesn't know the target exact armor again fire.

Currently, the AI player can assign one of two roles to the characters it controls. Attacker and Explorer. More will be developed, like Healer, Tank, etc. For now there are Attackers and Explorers.

These roles has nothing to do with character classes. They are only for the use of AI player.

Explorer: will try to hit different targets with different skills to "reveal" their stats, like dodge rate, armor again different types of damage. They must chose which skills to use by considering all skills of all characters in the team, but I'm still figuring the algorithm so right now they are random but at least they take care to not try things that they already tried on targets that they already hit. Explorers will switch to attackers at some time during a battle.

Attacker: will try to hit the targets that can be eliminated in less turns. When no stats are known they will chose own skills based on raw power, once the different types of armors are known to the AI, they will switch to skills that exploits this info, if such skills are available to them. Attackers will try different skills if a skill chosen based on raw power was halved by half or more and all enemy armors aren't known yet, but won't try for the best possible skill if one that isn't halved by as much as half its power is already known. Attackers may be lucky an select the best possible skill in the first attempt, but I expect a formation to work better if there are some explorers.

This system opens up interesting gameplay possibilities. If you let a wolf escape, the next pack may come already knowing your stats, and that implies that their attackers will take better decisions sooner as the AI requires now less exploration.

So, the description of an enemy formation that you can encounter during the game may be:
 

PackOfWolves1: {

    formation: ["wolf", null,   "wolf", null,   "wolf",

                null,   "wolf", null,   "wolf", null,

                null,   null,   null,   null,   null],

    openStatrategy: ["Explorer", null,      "Explorer", null,       "Explorer",

                     null,       "Attacker", null,      "Attacker", null,

                     null,       null,       null,      null,       null]

}

What do you think about these ideas? Was something similar tried before? Would you consider unfair an AI with "god eyes"?

Edited by Hebi
Important paragraph omitted before, correcting.

Share this post


Link to post
Share on other sites

Never programmed an AI, but as far as I know it's horribly complicated, and common practice is to "cheat" like you do.

I believe it is mure important to keep a random element in it, it is very boring if you always get the same set of enemies, and if they always make the same moves.

Random elements also hide somewhat that you're cheating, they have the effect of getting less precise knowledge than you really have.

Share this post


Link to post
Share on other sites

So cheating may not be so uncommon. That gives me some confidence.

Same as you, I never programmed and AI, other than implementing A* for 2D isometric prototypes. Enemy actions were always based on some kind of roll. I want a more challenging AI this time, one that does things with sense other than roll for everything.

If a smart player confirmed that an enemy is vulnerable to fire, not exploiting that has no sense, and destroys the illusion you are playing again an intelligence. But, choosing always the same action pattern also destroy that illusion, it's true. I think then, that I need some kind of configurable parameters to make the AI vary behavior. If it looks like the AI is doing that to avoid being predictable then it's fine, I guess.

Edited by Hebi
grammar

Share this post


Link to post
Share on other sites

Basically don't try to make the game fun for the computer, try to make it fun for the player.

 

At least part of the joy of playing an RPG (at least for me) is wondering what the enemies going to do, and see'ing whether or not I get screwed over. If the AI is smart enough to always pick the best choice, they feel pointless and I wish I could autoplay the game at 100X the normal speed since I already know what's going to happen.

Share this post


Link to post
Share on other sites

So this is a classic example of the blurry line between game design and game AI.

On the one hand, yes, you have a challenge presented here, in that the AI needs to operate under certain constraints - or at least perceived constraints.

The flip side of course is that this isn't really about how to build an AI, it's about how to design a compelling opponent in the first place.

Many AI decisions rest on game design foundations, as you're finding here. The trick is to solve the game design questions first and foremost, and then do whatever it takes to make the AI play the way you've designed it to.

As far as cheating goes, it's rampant in almost every game from an AI perspective. Sometimes it just doesn't make sense to simulate ignorance. Then again, sometimes it does - and this is back to game design. Stealth games without simulated ignorance would just be shooters, for just one example.

Ultimately you need to plan ahead from a perspective of "what should the gameplay feel like?" and work towards a suitable AI implementation from there.

Share this post


Link to post
Share on other sites
7 hours ago, conquestor3 said:

Basically don't try to make the game fun for the computer, try to make it fun for the player.

 

At least part of the joy of playing an RPG (at least for me) is wondering what the enemies going to do, and see'ing whether or not I get screwed over. If the AI is smart enough to always pick the best choice, they feel pointless and I wish I could autoplay the game at 100X the normal speed since I already know what's going to happen.

I agree, but that doesn't mean that the enemy must do completely random things. am I right? A certain algorithm is still needed.

 

4 hours ago, ApochPiQ said:

So this is a classic example of the blurry line between game design and game AI.

On the one hand, yes, you have a challenge presented here, in that the AI needs to operate under certain constraints - or at least perceived constraints.

The flip side of course is that this isn't really about how to build an AI, it's about how to design a compelling opponent in the first place.

Many AI decisions rest on game design foundations, as you're finding here. The trick is to solve the game design questions first and foremost, and then do whatever it takes to make the AI play the way you've designed it to.

As far as cheating goes, it's rampant in almost every game from an AI perspective. Sometimes it just doesn't make sense to simulate ignorance. Then again, sometimes it does - and this is back to game design. Stealth games without simulated ignorance would just be shooters, for just one example.

Ultimately you need to plan ahead from a perspective of "what should the gameplay feel like?" and work towards a suitable AI implementation from there.

Then I may be trying to solve a design problem, not AI problem. I definitely want the AI to be able to win, and the game to feel challenging, not impossible of-course. It is an RPG, no doubt, but I imagined battles as very tactical (think Baldur's Gate, where encounters aren't random and you can lose any of them).

Edited by Hebi
Extending last paragraph.

Share this post


Link to post
Share on other sites

One thing to remember is that players are really good at coming up with explanations for the NPC behaviors even when there isn't one. They will ascribe meaning and intent to what is pouring out of a random die roll. If you start with perfect knowledge and then fuzzy it up a bit, it may look just as plausible as your "exploration and learning" method... but with a lot less work.

Share this post


Link to post
Share on other sites

There is a balance to it, and the balance is so difficult it is often a big part of what goes in to regular patches for long-term games.

Balancing a game AI is tricky. Make a game too easy and players won't enjoy it. Make a game too difficult and players will hate it.  Generally there are options for different levels of difficulty, often each needs to be fine-tuned individually.  

Nobody wants to fight a perfect AI. A machine that always makes the ideal decisions, always follows the ideal path, always makes perfect shots, always makes the perfect corrections and countermoves to the player's actions.  On the other hand, nobody wants a stupid AI. A machine that always makes predictable decisions, that regularly makes the same mistakes, that never really plans ahead.

And as for hidden stuff, you as a player realize things about hidden stuff all the time.  You know the location of all the mines and resources. You have learned all the great positions for being a sniper, or the great positions for picking up tons of loot. That stuff isn't shown on the map, but it is something you have learned.  The AI isn't doing complex machine learning, nor is it likely to retain knowledge between levels. The AI also needs a bit of unpredictability so it doesn't follow the same path around the map every game, always falling for the same traps, always routing through the same funnels.  To compensate, most game AI's look at information that isn't shown to the player.

Further, understand there is more to randomized behavior than a dice roll.  There are many different distribution curves that can be used, various statistical models and probability options.  Numbers can be biased high or biased low. Odds can be heavily skewed. Distribution curves can be modified at runtime, adapting to skew right or left to automatically balance based on how the player is performing.  

 

Consider games like Mario Kart, the series has done well at dumbing-down the AI to make horrible mistakes when the player is trailing, or pushing the AI to perfect or near-perfect performance with full knowledge of the board when the player is performing exceptionally well.  Even if the player understands the computer is 'cheating' and occasionally loses to it, the players still adapt and play the game because it is fun and challenging.

Share this post


Link to post
Share on other sites
15 hours ago, IADaveMark said:

One thing to remember is that players are really good at coming up with explanations for the NPC behaviors even when there isn't one. They will ascribe meaning and intent to what is pouring out of a random die roll. If you start with perfect knowledge and then fuzzy it up a bit, it may look just as plausible as your "exploration and learning" method... but with a lot less work.

I think I have seen players "filling the holes" with their imagination before. I remember all those fandom wikis trying to explain some characters behavior or tactics. Some are good at reverse engineering and do quite a good work figuring the rules behind some bosses attack patterns.

Am I over-thinking things?

11 hours ago, frob said:

There is a balance to it, and the balance is so difficult it is often a big part of what goes in to regular patches for long-term games.

Balancing a game AI is tricky. Make a game too easy and players won't enjoy it. Make a game too difficult and players will hate it.  Generally there are options for different levels of difficulty, often each needs to be fine-tuned individually.  

Nobody wants to fight a perfect AI. A machine that always makes the ideal decisions, always follows the ideal path, always makes perfect shots, always makes the perfect corrections and countermoves to the player's actions.  On the other hand, nobody wants a stupid AI. A machine that always makes predictable decisions, that regularly makes the same mistakes, that never really plans ahead.

And as for hidden stuff, you as a player realize things about hidden stuff all the time.  You know the location of all the mines and resources. You have learned all the great positions for being a sniper, or the great positions for picking up tons of loot. That stuff isn't shown on the map, but it is something you have learned.  The AI isn't doing complex machine learning, nor is it likely to retain knowledge between levels. The AI also needs a bit of unpredictability so it doesn't follow the same path around the map every game, always falling for the same traps, always routing through the same funnels.  To compensate, most game AI's look at information that isn't shown to the player.

Further, understand there is more to randomized behavior than a dice roll.  There are many different distribution curves that can be used, various statistical models and probability options.  Numbers can be biased high or biased low. Odds can be heavily skewed. Distribution curves can be modified at runtime, adapting to skew right or left to automatically balance based on how the player is performing.  

 

Consider games like Mario Kart, the series has done well at dumbing-down the AI to make horrible mistakes when the player is trailing, or pushing the AI to perfect or near-perfect performance with full knowledge of the board when the player is performing exceptionally well.  Even if the player understands the computer is 'cheating' and occasionally loses to it, the players still adapt and play the game because it is fun and challenging.

Mario Kart is also a good example of AI showing personality more than intelligence. I will think about it.

I know that roll a dice is not the only way of doing it. But random() and shuffle() are always good friends and I think a lot of RPG out there are just rolling dices. I always thought that turn based battle systems, or semi real-time ones (with focus and cooldown times that vary per skill) but usually with no free movement, are an attempt to make roll based AI possible. For example, in classic turn based JRPGs, you can roll once to select a target then again to select skill, discarding the ones that are a certain miss. I can't offer a concrete implementation as evidence, it's something I'm guessing.

When using a per formation roll based rules system, I decided that having to test all formations would require too much time, so I switched to a more complex but reusable AI code. The idea is that I don't need to teach the AI player how to win per every possible formation. The AI is able to scan all skills in its own characters and take decisions. I invented a function, that I called rdps, "Relative Damage Per Second", that the Attacker role uses to figure out the best skill. When the target armor is unknown, a middle class armor is assumed, when known the real value is used. Right now the AI doesn't understand status ailments, nor it knows how to counter them.

If I follow ApochPiQ advice and define the game design questions first, so far I have:

  • Enemies are able to win.
  • Enemies behavior doesn't look random.
  • Enemies behavior shows personality.
  • No per formation AI scripting/rule set.

Maybe the last is more an optimization and I should just remove it for now, and the third one is more a wish, or a plus if time constraints permit, than something present in my current implementation.

It may be out of place for an RPG, but bringing RTEs to the table, what I have observed is that most AIs have a finite set of possible strategies, some apply to many civilizations and some to a specific civilization, the strategy that will be used is decided at the start of a match, maybe for some titles it can be switched at the middle of the match.

I think a sense of personality may be given to the different formations/enemy species, by removing certain strategies from some formations and enforcing certain strategies to others. For example, a story based forced rule, maybe during a certain boss fight: "If Mina is in the player's formation, lock her as target of all Attackers until she dies at least once. Attackers are free to test for armors but not to change target".

I got from this thread that make the human player's character structures public to the AI isn't a bad practice nor something new.

Edited by Hebi
Added a paragraph

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


  • Forum Statistics

    • Total Topics
      627787
    • Total Posts
      2979031
  • Similar Content

    • By Tootooni
      Good day dear people

      I'm completely new here and very nervous to be honest. I started with 3D-Design at my traineeship and can slowly start with my ideas for a survival/rpg game in 3d But since I only used RPG Makers until now I wonder how is the best way to start with a game, and what I would need for that.

      Have a wonderful day! ^.^)/)

      Tootooni
    • By menyo
      I'm currently testing out behaviortree's with the LibGDX AI library. I have read a lot about behaviortree's past couple days but it's hard to get clear how I need to build the tree for my specific scenario. I'm looking to use a behaviortree for a Rimworld like game where the players units are not directly controllable. In the first place I'm wondering if I should have a single big tree for the complete AI or many smaller tree's, for example a separate tree for:
      Moving an item Building a building Crafting an item Resting when sleepy Eating when hungry In the examples I have seen they all talk about a "single job". Like entering a building, GoTo -> Open Door -> GoTo -> Close door. But what if I need to check if I have the keys on me? And I need to check a lot of these variables.
      When A unit is Idle I'd like him to maintain his primary needs if he has access to them. If his needs are satisfied enough he can take on certain jobs like building walls or crafting items. I have a a lot of different jobs but jobs like building or crafting items are relatively the same with a different outcome so I could probably make a abstract job for that, it helps but I will still end up with a really huge tree though.
      Another issue I'm facing is that when tasks are running, and something more important pops up (enemy spotted or some kind of emergence task) the unit should stop it's current task and act accordingly to the interruption. So since the task is running I need to do those checks on each runnable task then returned failed/cancelled and further down the sequence I need to do another check for these interruptions and handle them accordingly. I have briefly read into dynamic branches, not sure if GDX AI supports this but adding a behavior to the tree to handle an interruption seems a good idea. These dynamic branches also opens the opportunity to hold behaviors at the jobs and once a unit accepts a job it inserts that branch into it's own tree.
      I hope I'm clear, it's hard to explain and get a global view of a complex behavior tree. I have read several times that behavior tree's are very easy to understand and implement. Well, that might be the case for those small tree's I find everywhere. On the other hand I might be over complicating things.
    • By ApochPiQ
      I've just posted a pre-release edition of Curvature, my utility-theory AI design tool. Curvature provides a complete end-to-end solution for designing utility-based AI agents; you can specify the knowledge representation for the world, filter the knowledge into "considerations" which affect how an agent will make decisions and choose behaviors, and then plop a few agents into a dummy world and watch them run around and interact with things.
      Preview 1 (Core) contains the base functionality of the tool but leaves a lot of areas unpolished. My goal with this preview is to get feedback on how well the tool works as a general concept, and start refining the actual UI into something more attractive and fluid. The preview kit contains a data file with a very rudimentary "scenario" set up for you, so you can see how things work without cutting through a bunch of clutter.
      Give it a test drive, let me know here or via the Issue Tracker on GitHub what you like and don't like, and have fun!
    • By Marc Klein
      Hello,
      I'm using BMfont to create a Bitmap font for my text Rendering. I noticed some strange behaviour when I use the option "force Offsets to Zero".
      If I use this option my rendering resultions looks ok, but without it, there is some missing space between some characters.
      I attached the BMFont configuration files and font that I used.
      In the rendering result with variable Offset you can see that there is missing space right next to the "r" letter.
      To get the source and destination of my render rectangles I basically to following:
      void getBakedQuad(const fontchar_t* f, int* x_cursor, int * y_cursor, SDL_Rect* src, SDL_Rect* dest) {
      dest->x = *x_cursor + f->xoffset;
      dest->y = *y_cursor + f->yoffset;
      dest->w = f->width;
      dest->h = f->height;
      src->x = f->x;
      src->y = f->y;
      src->w = f->width;
      src->h = f->height;
      *x_cursor += f->xadvance;
      }
      Has somebody noticed a similar behaviour?
      orbitron-bold.otf
      SIL Open Font License.txt
      variable_offset.bmfc
      variable_offset.fnt


      zero_offset.bmfc
      zero_offset.fnt


  • Popular Now