artificial-intelligencegenetic-algorithmminimaxgame-ai

Fitness Function altenatives in Genetic Algorithms for game AI


I have created a Gomoku(5 in a row) AI using Alpha-Beta Pruning. It makes moves on a not-so-stupid level. First, let me vaguely describe the grading function of the Alpha-Beta algorithm.

When it receives a board as an input, it first finds all repetitions of stones and gives it a score out of 4 possible values depending on its usefulness as an threat, which is decided by length. And it will return the summation of all the repetition scores.

But, the problem is that I explicitly decided the scores(4 in total), and they don't seem like the best choices. So I've decided to implement a genetic algorithm to generate these scores. Each of the genes will be one of 4 scores. So for example, the chromosome of the hard-coded scores would be: [5, 40000,10000000,50000]

However, because I'm using the genetic algorithm to create the scores of the grading function, I'm not sure how I should implement the genetic fitness function. So instead, I have thought of the following:

Instead of using a fitness function, I'll just merge the selection process together: If I have 2 chromosomes, A and B, and need to select one, I'll simulate a game using both A and B chromosomes in each AI, and select the chromosome which wins.

1.Is this a viable replacement to the Fitness function?

2.Because of the characteristics of the Alpha-Beta algorithm, I need to give the max score to the win condition, which in most cases is set to infinity. However, because I can't use Infinity, I just used an absurdly large number. Do I also need to add this score to the chromosome? Or because it's insignificant and doesn't change the values of the grading function, leave it as a constant?

3.When initially creating chromosomes, random generation, following standard distribution is said to be the most optimal. However, genes in my case have large deviation. Would it still be okay to generate chromosomes randomly?


Solution

  • Is this a viable replacement to the Fitness function?

    Yes, it is. It's a fairly common way to define a fitness function for board games. Probably a single round is not enough (but you have to experiment).

    A slight variant is something like:

    double fitness(Agent_k)
      fit = 0
    
      repeat M times
        randomly extract an individual Agent_i (i <> k)
    
        switch (result of Agent_k vs Agent_i)
          case Agent_k wins:   fit = fit + 1
          case Agent_i wins:   fit = fit - 2
          case draw:           fit doesn't change
    
      return fit
    

    i.e. an agent plays against M randomly selected opponents from the population (with replacement but avoiding self match).

    Increasing M the noise decreases but longer simulation times are required (M=5 is a value used in some chess-related experiments).

    2.Because of the characteristics of the Alpha-Beta algorithm...

    Not sure of the question. A very large value is a standard approach for a static evaluation function signaling a winning condition.

    The exact value isn't very important and shouldn't probably be subject to optimization.

    3.When initially creating chromosomes, random generation, following standard distribution is said to be the most optimal. However, genes in my case have large deviation. Would it still be okay to generate chromosomes randomly?

    This is somewhat related to the specific genetic algorithm "flavor" you are going to use.

    A standard genetic algorithm could work better with not completely random initial values.

    Other variants (e.g. Differential Evolution) could be less sensitive to this aspect.

    Take also a look at this question / answer: Getting started with machine learning a zero sum game?