Answers.Body: <blockquote>
    <ol>
    <li>Is this a viable replacement to the Fitness function?</li>
    </ol>
  </blockquote>
  
  <p>Sure, the fitness is 1 for the winner and 0 for the loser. You're using some kind of the Tournament selection.</p>
  
  <p>It might be better to use more chromosomes and let A play against B, C, D... and define the fitness as the number of wins. Or not, as such an evaluation is more precise but also more time-consuming.</p>
  
  <blockquote>
    <ol start="2">
    <li>... Infinity ... Do I also need to add this score to the chromosome?</li>
    </ol>
  </blockquote>
  
  <p>Why should you? The exact value doesn't matter (as it only needs to be big enough), so there's nothing to evolve there. You don't represent the number  of players either, right? Just use common sense.</p>
  
  <blockquote>
    <ol start="3">
    <li>... Would it still be okay to generate chromosomes randomly?</li>
    </ol>
  </blockquote>
  
  <p>I guess so, but a distribution providing values closer to the expected outcome should be better. This depends on how you mutate them (adding a small random value won't bring you far, multiplying by <code>1 + small_random_value</code> would).</p>
  
  <p>Alternatively, you can generate values from some fixed interval and scale them up.</p>
  
  <p>Your values are IMHO far too big. Whatever your 5 and 40000 mean, I guess, that 5 and 400 would work the same.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-03-14T03:08:19.943Z
Answers.LastActivityDate: 2018-03-14T03:08:19.943Z
Answers.UserDisplayName: maaartinus
Body: <p>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 evaluation function of the Alpha-Beta algorithm.</p>
  <p>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 a threat, which is decided by length. And it will return the summation of all the repetition scores.</p>
  <p>But, the problem is that I explicitly decided the scores (4 in total), and they don't seem like the best choices.</p>
  <p>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 <span class="math-container">$[5, 40000, 10000000, 50000]$</span>.</p>
  <p>However, because I'm using the genetic algorithm to create the scores of the evaluation function, I'm not sure how I should implement the genetic fitness function. So, instead, I have thought of the following:</p>
  <p>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.</p>
  <ol>
  <li><p>Is this a viable replacement to the fitness function?</p>
  </li>
  <li><p>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?</p>
  </li>
  <li><p>When initially creating chromosomes, random generation, following standard distribution is said to be the most optimal. However, genes in my case have a large deviation. Would it still be okay to generate chromosomes randomly?</p>
  </li>
  </ol>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-12-04T22:44:54.717Z
Comments.Text: Why exactly four values for the score? What do these values exactly represent?
Comments.UserDisplayName: Andrea Iacono
Tags: <game-ai><genetic-algorithms><minimax><alpha-beta-pruning><fitness-functions>
Title: How do I use a genetic algorithm to generate the scores of an evaluation function for alpha-beta pruning?
UserDisplayName: Dashadower
ThreadText: # How do I use a genetic algorithm to generate the scores of an evaluation function for alpha-beta pruning?
  
  (Asked by: username_0 on 2017-11-29)
  
  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 evaluation 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 a 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 evaluation 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 a large deviation. Would it still be okay to generate chromosomes randomly?
  
  **Tags:** game-ai, genetic-algorithms, minimax, alpha-beta-pruning, fitness-functions
  > **Comments:**
  > **username_1**: Why exactly four values for the score? What do these values exactly represent?  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2018-03-14. Score: 1
  
  > 1. Is this a viable replacement to the Fitness function?
  
  Sure, the fitness is 1 for the winner and 0 for the loser. You're using some kind of the Tournament selection.
  
  It might be better to use more chromosomes and let A play against B, C, D... and define the fitness as the number of wins. Or not, as such an evaluation is more precise but also more time-consuming.
  
  > 2. ... Infinity ... Do I also need to add this score to the chromosome?
  
  Why should you? The exact value doesn't matter (as it only needs to be big enough), so there's nothing to evolve there. You don't represent the number of players either, right? Just use common sense.
  
  > 3. ... Would it still be okay to generate chromosomes randomly?
  
  I guess so, but a distribution providing values closer to the expected outcome should be better. This depends on how you mutate them (adding a small random value won't bring you far, multiplying by `1 + small_random_value` would).
  
  Alternatively, you can generate values from some fixed interval and scale them up.
  
  Your values are IMHO far too big. Whatever your 5 and 40000 mean, I guess, that 5 and 400 would work the same.
  
  
  ---
  
  