Answers.Body: <p><strong>EDIT for comment</strong></p>
  
  <p>The most important by far is the material count and PST already discussed in your link. You won't go anywhere unless your engine can count materials properly. Other than that, the common knowledge such as rook behind a passed pawn, castled king, pawn majority and mobility are important. Your human knowledge to chess should be sufficient.</p>
  
  <p><strong>ORIGINAL</strong></p>
  
  <p>The best way to improve it is to study the Stockfish source code. Read the comments, and study the implementation.</p>
  
  <p>Code your engine, make it work with a simple evaluation function. Gradually and slowly apply Stockfish's ideas to your own engine.</p>
  
  <p>There's <strong>many</strong> possible improvements. I can only list some of those. I will give you a link to the Stockfish source code below.</p>
  
  <ul>
  <li>Two bishops advantage</li>
  <li>Interpolate between middle game and endgame scoring</li>
  <li>Bonus to pawn structures (the page only gives very simple PST values) </li>
  <li>Calibrate the values better with a statistical model</li>
  <li>Castled king</li>
  <li>Number of squares controlled</li>
  <li>Number of attacking squares near the enemy's king</li>
  <li>Asymmetric evaluation (Stockfish doesn't do that but some engines like Chess Genius does that)</li>
  <li>Pieces attacked by the king</li>
  <li>Rook behind a pawn</li>
  <li>Pawn on the check colour as bishop</li>
  <li>Mobility bonus</li>
  <li>Enemy checks</li>
  <li>Rook on semi- or open file</li>
  <li>Insufficient defended squares</li>
  <li>Passed pawn that is not blocked</li>
  <li>Candidate passed pawn (pawn majority)</li>
  <li>......</li>
  </ul>
  
  <p>Let's take some random examples from Stockfish. Please examine the source code yourself for details.</p>
  
  <blockquote>
    <p><a href="https://github.com/official-stockfish/Stockfish/blob/69eb391cd779223c331fb0de80392cbd323055a9/src/evaluate.cpp" rel="nofollow noreferrer">https://github.com/official-stockfish/Stockfish/blob/69eb391cd779223c331fb0de80392cbd323055a9/src/evaluate.cpp</a></p>
  </blockquote>
  
  <pre><code>// RookOnFile[semiopen/open] contains bonuses for each rook when there is no
  // friendly pawn on the rook file.
  const Score RookOnFile[] = { S(20, 7), S(45, 20) };
  </code></pre>
  
  <p>and</p>
  
  <pre><code>// ThreatByMinor/ByRook[attacked PieceType] contains bonuses according to
  // which piece type attacks which one. Attacks on lesser pieces which are
  // pawn-defended are not considered.
  const Score ThreatByMinor[PIECE_TYPE_NB] = {
    S(0, 0), S(0, 33), S(45, 43), S(46, 47), S(72, 107), S(48, 118)
  };
  </code></pre>
  
  <p>and</p>
  
  <pre><code>// Scale down bonus for candidate passers which need more than one
  // pawn push to become passed or have a pawn in front of them.
  if (!pos.pawn_passed(Us, s + pawn_push(Us)) || (pos.pieces(PAWN) &amp; forward_bb(Us, s)))
          mbonus /= 2, ebonus /= 2;
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-07-01T14:07:38.673Z
Answers.Text: Could you give any guide as to which features would be most important as I don't want to have a function which is too complex? Also, would you recommend changing any of my current weightings? I don't know how sensible they are
Answers.UserDisplayName: Matthew Barber
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-07-01T14:11:09.323Z
Answers.Text: @MatthewBarber I edited.
Answers.UserDisplayName: SmallChess
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-07-01T14:05:27.880Z
Answers.LastActivityDate: 2017-07-03T16:44:56.007Z
Answers.LastEditDate: 2017-07-03T16:44:56.007Z
Answers.UserDisplayName: SmallChess
Answers.Body: <p>I would like to add up a couple things to support the good answers you    have already.</p>
  
  <ul>
  <li>Stockfish never applies evaluation function for positions where king of
  either side is in check.</li>
  <li>Evaluation is based on the state of your Middle Game and End Game.</li>
  <li>Also a smooth transition between the phases of the game using a fine 
  grained numerical game phase value considering type of captured<br>
  pieces so far. This is called <a href="https://chessprogramming.wikispaces.com/Tapered+Eval" rel="nofollow noreferrer">"Tapered Eval"</a>.</li>
  </ul>
  
  <p>Here a snippet of my own evaluation for middle gale</p>
  
  <pre><code>EvalPhase middle_game_evaluation(&amp;pos) {
    int ev = 0;
    ev += piece_value_mg(pos) - piece_value_mg(colorflip(pos));
    ev += psqt_mg(pos) - psqt_mg(colorflip(pos));
    ev += imbalance_total(pos);
    ev += pawns_mg(pos) - pawns_mg(colorflip(pos));
    ev += pieces_mg(pos) - pieces_mg(colorflip(pos));
    ev += mobility_mg(pos) - mobility_mg(colorflip(pos));
    ev += threats_mg(pos) - threats_mg(colorflip(pos));
    ev += passed_mg(pos) - passed_mg(colorflip(pos));
    ev += space(pos) - space(colorflip(pos));
    ev += king_mg(pos) - king_mg(colorflip(pos));
    return EvalPhase(ev);
  }
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-03-29T22:50:16.480Z
Answers.Text: dead link here.
Answers.UserDisplayName: john k
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-07-21T14:47:47.967Z
Answers.LastActivityDate: 2017-07-21T14:53:55.987Z
Answers.LastEditDate: 2017-07-21T14:53:55.987Z
Answers.UserDisplayName: Carlos
Body: <p>I don't know very much about chess beyond the rules but I enjoy programming and am trying to write a chess engine. I recently found this evaluation function: <a href="https://chessprogramming.wikispaces.com/Simplified+evaluation+function" rel="noreferrer">Simple Evaluation Function</a>. What would be the best way to improve on what has been done there?</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-07-01T13:38:57.697Z
Comments.Text: Did you see https://chessprogramming.wikispaces.com/Evaluation and https://chessprogramming.wikispaces.com/Evaluation+function on the same website? Also you could take a look at the source code of Stockfish, which is one of the strongest (if not the strongest) chess engine out there.
Comments.UserDisplayName: user1583209
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-07-01T14:05:54.123Z
Comments.Text: I did take a look at them but the Stockfish evaluation is obviously very detailed and I am only looking to make small improvements on the simple evaluation function that I gave a link to. Because I don't really know much about chess, I'm not sure what to prioritise in adding to my evaluation or what sort of weightings it should receive and if that means I should change other parts of the current evaluation.
Comments.UserDisplayName: Matthew Barber
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-07-01T14:13:49.173Z
Comments.Text: @MatthewBarber Try out the common chess knowledge that even a beginner would know, like open files and semi-open files.
Comments.UserDisplayName: SmallChess
Tags: <engines><evaluation>
Title: How to write a chess evaluation function?
ThreadText: # How to write a chess evaluation function?
  
  (Asked by: username_0 on 2017-07-01)
  
  I don't know very much about chess beyond the rules but I enjoy programming and am trying to write a chess engine. I recently found this evaluation function: [Simple Evaluation Function](https://chessprogramming.wikispaces.com/Simplified+evaluation+function). What would be the best way to improve on what has been done there?
  
  **Tags:** engines, evaluation
  
  > **Comments:**
  > **username_1**: Did you see https://chessprogramming.wikispaces.com/Evaluation and https://chessprogramming.wikispaces.com/Evaluation+function on the same website? Also you could take a look at the source code of Stockfish, which is one of the strongest (if not the strongest) chess engine out there.  
  > **username_0**: I did take a look at them but the Stockfish evaluation is obviously very detailed and I am only looking to make small improvements on the simple evaluation function that I gave a link to. Because I don't really know much about chess, I'm not sure what to prioritise in adding to my evaluation or what sort of weightings it should receive and if that means I should change other parts of the current evaluation.  
  > **username_2**: @MatthewBarber Try out the common chess knowledge that even a beginner would know, like open files and semi-open files.  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_2 on 2017-07-01. Score: 2
  
  EDIT for comment
  The most important by far is the material count and PST already discussed in your link. You won't go anywhere unless your engine can count materials properly. Other than that, the common knowledge such as rook behind a passed pawn, castled king, pawn majority and mobility are important. Your human knowledge to chess should be sufficient.
  ORIGINAL
  The best way to improve it is to study the Stockfish source code. Read the comments, and study the implementation.
  Code your engine, make it work with a simple evaluation function. Gradually and slowly apply Stockfish's ideas to your own engine.
  There's many possible improvements. I can only list some of those. I will give you a link to the Stockfish source code below.
  
  Two bishops advantage
  Interpolate between middle game and endgame scoring
  Bonus to pawn structures (the page only gives very simple PST values) 
  Calibrate the values better with a statistical model
  Castled king
  Number of squares controlled
  Number of attacking squares near the enemy's king
  Asymmetric evaluation (Stockfish doesn't do that but some engines like Chess Genius does that)
  Pieces attacked by the king
  Rook behind a pawn
  Pawn on the check colour as bishop
  Mobility bonus
  Enemy checks
  Rook on semi- or open file
  Insufficient defended squares
  Passed pawn that is not blocked
  Candidate passed pawn (pawn majority)
  ......
  
  Let's take some random examples from Stockfish. Please examine the source code yourself for details.
  
  https://github.com/official-stockfish/Stockfish/blob/69eb391cd779223c331fb0de80392cbd323055a9/src/evaluate.cpp
  
  // RookOnFile[semiopen/open] contains bonuses for each rook when there is no
  // friendly pawn on the rook file.
  const Score RookOnFile[] = { S(20, 7), S(45, 20) };
  
  and
  // ThreatByMinor/ByRook[attacked PieceType] contains bonuses according to
  // which piece type attacks which one. Attacks on lesser pieces which are
  // pawn-defended are not considered.
  const Score ThreatByMinor[PIECE_TYPE_NB] = {
    S(0, 0), S(0, 33), S(45, 43), S(46, 47), S(72, 107), S(48, 118)
  };
  
  and
  // Scale down bonus for candidate passers which need more than one
  // pawn push to become passed or have a pawn in front of them.
  if (!pos.pawn_passed(Us, s + pawn_push(Us)) || (pos.pieces(PAWN) & forward_bb(Us, s)))
          mbonus /= 2, ebonus /= 2;
  
  > **Comments:**
  > **username_0**: Could you give any guide as to which features would be most important as I don't want to have a function which is too complex? Also, would you recommend changing any of my current weightings? I don't know how sensible they are  
  > **username_2**: @MatthewBarber I edited.  
  
  ---
  
  ### Answer by username_3 on 2017-07-21. Score: 1
  
  I would like to add up a couple things to support the good answers you    have already.
  
  Stockfish never applies evaluation function for positions where king of
  either side is in check.
  Evaluation is based on the state of your Middle Game and End Game.
  Also a smooth transition between the phases of the game using a fine 
  grained numerical game phase value considering type of captured
  pieces so far. This is called "Tapered Eval".
  
  Here a snippet of my own evaluation for middle gale
  EvalPhase middle_game_evaluation(&pos) {
    int ev = 0;
    ev += piece_value_mg(pos) - piece_value_mg(colorflip(pos));
    ev += psqt_mg(pos) - psqt_mg(colorflip(pos));
    ev += imbalance_total(pos);
    ev += pawns_mg(pos) - pawns_mg(colorflip(pos));
    ev += pieces_mg(pos) - pieces_mg(colorflip(pos));
    ev += mobility_mg(pos) - mobility_mg(colorflip(pos));
    ev += threats_mg(pos) - threats_mg(colorflip(pos));
    ev += passed_mg(pos) - passed_mg(colorflip(pos));
    ev += space(pos) - space(colorflip(pos));
    ev += king_mg(pos) - king_mg(colorflip(pos));
    return EvalPhase(ev);
  }
  
  > **Comments:**
  > **username_4**: dead link here.  
  
  ---
  
  