So I'm starting a project which aims to make a good AI for my game monsters.

So far I have set up the GA and got some results.

There's two genes, with one chromosome each.

The monster either 'attacks on sight' or 'flee on sight' depending on the gene it got. The fitness function is based upon time alive and the crossover is just eliminating the worst gene.

As expected the 'flee on sight' gene got better result.

What I'm here to ask is what are some good uses of GA in developing AI. Which genes/chromosome/fitnessfunction/crossover should I implement in order to have a challenging AI.

The game is a rogue-like, it's still pretty simple, not much added, so I can make the game around the GA instead of the other way around.

This may be a too broad question, but bear in mind that I don't have any experience in gamedev and AI as a whole.


To make this question a bit more narrow.

Since my fitness function is just 'survive' it's quite obvious that all the enemy generations would get better at fleeing. So,

What should I put in consideration to a good fitness function.

Damage to the player is also quite one-way solver, a monster-healer which doesn't have any attack power would drop his staff and punch the player.

The perfect fitness function for me should translate to 'make the player struggle', but I don't know what that would mean in the game terms, and specially code terms.

  • 1
    \$\begingroup\$ Your question is valid, though worded in such a way that it sounds like polling for opinions. Try rewording it to make the actual question a bit more clear. Currently asking for "good uses" is ambiguous and not suited for this site. \$\endgroup\$
    – Evan
    Jun 22, 2014 at 13:15
  • \$\begingroup\$ This really depends on your game and what actors can do in it. \$\endgroup\$
    – Philipp
    Jun 22, 2014 at 16:36
  • \$\begingroup\$ Something to think about while working on your fitness function: adaptable, perfectly performing AI are both frustrating to play against and stop a player's learning process so that a person can never get better at your game, which is also very frustrating. In the end I suggest you create your fitness function so that it has a sense of what's fun for the player and not just perfectly playing. \$\endgroup\$ Jun 23, 2014 at 2:03

2 Answers 2


I think you have a good start. You certainly have your GA infrastructure in place. Now you need to expand and tweak. You also seem to be missing the part about random new genes, which is important.

I think, at a high level, you need to figure out what kind of actions you want your AI to take. Attacking and fleeing, are they enough?

Since you have a roguelike, I would suggest also incorporating the concept of "damage done to the player" into your fitness function.

The problem with these two chromosomes is that you get an either-or. Instead, you need something with a more range/spectrum. I would try something like "flee after N turns" or "flee when you reach N% health." You can add other ones that incorporate special attacks at certain points.

  • \$\begingroup\$ Oh yeah, I totally forgot the random new genes. I plan to add more genes, but since my game still doesn't have much(even the damage is fixed) I didn't add any. I had not thought of using N-turns for actions, I guess I'll start there. \$\endgroup\$ Jun 22, 2014 at 13:27
  • 1
    \$\begingroup\$ @f.rodrigues you need to sit down with a pen and paper and visualize the "ideal" monster interaction with a player, something that makes you think "wow that's super awesome!" From that written passage/points, you can deduce actions and genes. \$\endgroup\$
    – ashes999
    Jun 22, 2014 at 18:15

I think the parameter you are looking for is total number of player deaths in the vicinity of this monster devided by the number of monster deaths ([area kills]/[deaths]). This means that monsters will run if they know they can't win and will work together to kill of the players rather then just focus on damage output. Note you have a healer so you might want to give him genetic code so that he can heal other monsters, are you going to add more low level genes as well (movement patterns ext.) these could allow monsters to show some really interesting behaviour.

A bit of advice: if you use this method you are going to want to get a large number of real players to let the AI learn form, so why not simply let the game report back which monster with what DNA had players die nearby. If you then automatically process these results you won't have to manually update the game yet the monsters will react to a sort of metagame.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .