Answers.Body: <p>Based on your description, I'd maximize the following terms:</p>
  
  <ul>
  <li><code>i</code></li>
  <li><code>-max(f - 10 - (MAX_FIELD_INDEX - i), 0)</code> - assuming consumption of one fuel per field; this becomes negative when you have too much fuel</li>
  <li>a similar function of <code>p</code>, as spending them gets more important when approaching the goal</li>
  </ul>
  
  <p>As having fuel is probably a good thing in the beginning, you could use a term like <code>f</code>. Similarly for the "power packs" (or are they rather "weakness packs"?).</p>
  
  <p>I'd combine the terms using a linear function like you did and let it optimize. You may need more such terms. Maybe it's simpler to get rid of the power packs when you have enough fuel? Then something like <code>-max(p-f, 0)</code> may help.</p>
  
  <p>You may generate some ad-hoc expressions or add some products of your terms as new terms. You may want to do this after the coefficients of the simpler terms have already been optimized (so you help the more complex optimization with a good staring point).</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-01-12T06:09:13.450Z
Answers.Text: The fuel gets calculated as following: 1 + 2 + 3 + 4 = 10 for 4 fields and so on.. (the little gauss) so going it costs more to go more fields at once. Would this change anything in your function? I think if I have time I'll add the whole game instructions to the question later
Answers.UserDisplayName: po0l
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-01-12T06:54:26.133Z
Answers.Text: I meant for **advancing** 4 fields.. e.g. advancing 6 fields whereever you are costs 1+2+3+4+5+6 = 21 fuel
Answers.UserDisplayName: po0l
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-01-12T12:31:35.350Z
Answers.Text: @po0l Then you may need `-max(f - 10 - (MAX_FIELD_INDEX - i) * (MAX_FIELD_INDEX - i + 1) / 2, 0)` instead or in addition to the above expression.
Answers.UserDisplayName: maaartinus
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-01-12T04:09:39.310Z
Answers.LastActivityDate: 2018-01-12T04:09:39.310Z
Answers.UserDisplayName: maaartinus
Body: <p>I'm currently writing the <em>Alpha-Beta pruning</em> algorithm for a board game. Now I need to come up with a good evaluation function. The game is a bit like snakes and ladders (you have to finish the race first), so for a possible feature list I came up with the following:</p>
  <ul>
  <li>field index should be high</li>
  <li>in the lower fields my fuel should be high, when coming to the end it should be low (maximum of '10' required to enter the goal)</li>
  <li>all 'power-ups' must be spent to enter the goal, so prioritize them</li>
  <li>if it is possible to enter the goal (a legit move), do it!</li>
  </ul>
  <p>There could be some more for some special cases.</p>
  <p>I've read somewhere that it is the best (and easiest) to combine them in a linear function, for example:</p>
  <p><span class="math-container">$$0.75 * i - 5 * p - 0.25 * |(f - \text{MAX_FIELD_INDEX}/i)|,$$</span></p>
  <p>where</p>
  <ul>
  <li><span class="math-container">$i$</span> = field index</li>
  <li><span class="math-container">$p$</span> = power-ups</li>
  <li><span class="math-container">$f$</span> = fuel</li>
  </ul>
  <p>Since I can't ask an expert and I'm not an expert by myself, I have nobody to ask if those parameters are good, if I've forgotten something or if I've combined the factors correctly.</p>
  <p>The parameters aren't that big of a deal because I could use a genetic algorithm or something else to optimize them.</p>
  <p>My problem and question is: What do I have to do to find out how to put together my features optimally (how can I optimize the function/parameter arrangement itself)?</p>
  
Tags: <game-ai><evolutionary-algorithms><alpha-beta-pruning><evaluation-functions><board-games>
Title: How do I write a good evaluation function for a board game?
UserDisplayName: po0l
ThreadText: # How do I write a good evaluation function for a board game?
  
  (Asked by: username_0 on 2018-01-11)
  
  I'm currently writing the *Alpha-Beta pruning* algorithm for a board game. Now I need to come up with a good evaluation function. The game is a bit like snakes and ladders (you have to finish the race first), so for a possible feature list I came up with the following:
  
  * field index should be high
  * in the lower fields my fuel should be high, when coming to the end it should be low (maximum of '10' required to enter the goal)
  * all 'power-ups' must be spent to enter the goal, so prioritize them
  * if it is possible to enter the goal (a legit move), do it!
  
  There could be some more for some special cases.
  
  I've read somewhere that it is the best (and easiest) to combine them in a linear function, for example:
  
  $$0.75 \* i - 5 \* p - 0.25 \* |(f - \text{MAX\_FIELD\_INDEX}/i)|,$$
  
  where
  
  * $i$ = field index
  * $p$ = power-ups
  * $f$ = fuel
  
  Since I can't ask an expert and I'm not an expert by myself, I have nobody to ask if those parameters are good, if I've forgotten something or if I've combined the factors correctly.
  
  The parameters aren't that big of a deal because I could use a genetic algorithm or something else to optimize them.
  
  My problem and question is: What do I have to do to find out how to put together my features optimally (how can I optimize the function/parameter arrangement itself)?
  
  **Tags:** game-ai, evolutionary-algorithms, alpha-beta-pruning, evaluation-functions, board-games
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2018-01-12. Score: 1
  
  Based on your description, I'd maximize the following terms:
  
  * `i`
  * `-max(f - 10 - (MAX_FIELD_INDEX - i), 0)` - assuming consumption of one fuel per field; this becomes negative when you have too much fuel
  * a similar function of `p`, as spending them gets more important when approaching the goal
  
  As having fuel is probably a good thing in the beginning, you could use a term like `f`. Similarly for the "power packs" (or are they rather "weakness packs"?).
  
  I'd combine the terms using a linear function like you did and let it optimize. You may need more such terms. Maybe it's simpler to get rid of the power packs when you have enough fuel? Then something like `-max(p-f, 0)` may help.
  
  You may generate some ad-hoc expressions or add some products of your terms as new terms. You may want to do this after the coefficients of the simpler terms have already been optimized (so you help the more complex optimization with a good staring point).
  
  > **Comments:**
  > **username_0**: The fuel gets calculated as following: 1 + 2 + 3 + 4 = 10 for 4 fields and so on.. (the little gauss) so going it costs more to go more fields at once. Would this change anything in your function? I think if I have time I'll add the whole game instructions to the question later  
  > **username_0**: I meant for **advancing** 4 fields.. e.g. advancing 6 fields whereever you are costs 1+2+3+4+5+6 = 21 fuel  
  > **username_1**: @username_0 Then you may need `-max(f - 10 - (MAX_FIELD_INDEX - i) * (MAX_FIELD_INDEX - i + 1) / 2, 0)` instead or in addition to the above expression.  
  
  ---
  
  