Answers.Body: <p>Why can't you just make a Winboard chess engine, but evaluate a position statically??</p>
  
  <p>You will need to follow the Winboard protocol:</p>
  
  <blockquote>
    <p><a href="https://www.gnu.org/software/xboard/engine-intf.html" rel="nofollow noreferrer">https://www.gnu.org/software/xboard/engine-intf.html</a></p>
  </blockquote>
  
  <p>Although everybody uses alpha-beta/nega-max pruning, but Winboard doesn't know your code. All you need to do is just give an evaluation score from your static function.</p>
  
  <p>Your "engine" will wait for the <code>go</code> Winboard command. Print thinking output like:</p>
  
  <blockquote>
    <p>ply score time nodes pv</p>
  </blockquote>
  
  <p>where score will be your static evaluation score. Your engine doesn't need to make a move, Winboard will wait forever for a move. You can always setup a new position in Winboard.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-09-12T17:21:17.113Z
Answers.Text: Sorry but I'm unfamiliar with the Winboard protocol. Is there a better tutorial on how I can use it?
Answers.UserDisplayName: A. Napster
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-09-13T05:26:54.690Z
Answers.Text: https://chessprogramming.wikispaces.com/UCI explains how to interface with winboard and has a link to the old manual.
Answers.UserDisplayName: Fred Knight
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-09-14T00:47:39.743Z
Answers.Text: @A.Napster Fred Knight's links is good.
Answers.UserDisplayName: SmallChess
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-09-12T08:56:17.270Z
Answers.LastActivityDate: 2017-09-12T08:56:17.270Z
Answers.UserDisplayName: SmallChess
Answers.Body: <p>The easiest way to accomplish the goal is to download Winboard with its own engine.  The GUI can be set to output the current evaluation.  You can recode the eval function to your own parameters.</p>
  
  <p><a href="http://chessprogramming.wikispaces.com/Evaluation" rel="nofollow noreferrer">http://chessprogramming.wikispaces.com/Evaluation</a> provides some resources about programming the eval function.  However, getting a well-documented source code for the eval function I find easier.  Avoid the higher engines like Crafty, but a simple one like <a href="http://www.tckerrigan.com/Chess/TSCP/" rel="nofollow noreferrer">http://www.tckerrigan.com/Chess/TSCP/</a> is easy to understand.</p>
  
  <p>Winboard is the best option, but you can create your own interface.  You could modify a PGN viewer to return an eval after every move or put the FENs into a PGN file and loop through all games.  You could download <a href="https://www-lucaschess.rhcloud.com/" rel="nofollow noreferrer">https://www-lucaschess.rhcloud.com/</a> or another chess interface which can analyse a game and use its output.</p>
  
  <p>For the actual question, the chess eval is broken up into many factors.</p>
  
  <p>The easiest is material:  just loop over the board and count the material.</p>
  
  <p>Next is pawn structure.  Assign a penalty to isolated and doubled pawns.  A bonus for passed pawns.  (Pawns near the king is under king threats.)  This can be modified further by changing the penalty based on the distance from the center.</p>
  
  <p>Next is the pieces in relation to the pawns.  A bonus for a rook on a open or half-open file.  A bonus for a bishop which isn't trapped behind its own pawns.</p>
  
  <p>Next is the pieces in relation to the center.  The closer to the center the piece is, the more it is worth.  This also includes a bonus for a rook on the seventh rank.  (Trapping the king would improve this score, but this would fall under king safety.)</p>
  
  <p>There is a bonus for having a bishop pair and the values of the minor pieces (the bishops and the knights) are adjusted based upon how closed the center is.  A bonus can be added for more mobility (either absolute or for each piece) and/or space control.  (Concentrated force(s) is a factor normally reserved for mating threats.)</p>
  
  <p>This is a short list.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-09-13T05:25:55.700Z
Answers.LastActivityDate: 2017-09-13T05:25:55.700Z
Answers.UserDisplayName: Fred Knight
Body: <p>I want to evaluate positions statically. So I've written a code which evaluates from a FEN string. </p>
  
  <p>However it is a tedious to copy FEN and then paste for a complete game. So I wanted to know if it is possible to write such a code which can run with <code>WinBoard</code> and which could evaluate the current position statically. </p>
  
  <p>It does not need to generate moves,be able to play a game, deep evaluation ,quiescent search etc. </p>
  
  <p>I'm also not interested in performing <code>King Safety</code>/<code>Mate Threats</code>. </p>
  
  <p>So the program should just give me only a number as output when loaded in <code>WinBoard</code>. </p>
  
  <p>Is there a simple way to perform such a task or a simple enough engine I can modify to do this? </p>
  
Tags: <engines><programming><evaluation>
Title: How to write a simple chess engine to statically evaluate a position?
ThreadText: # How to write a simple chess engine to statically evaluate a position?
  
  (Asked by: username_0 on 2017-09-12)
  
  I want to evaluate positions statically. So I've written a code which evaluates from a FEN string.
  
  However it is a tedious to copy FEN and then paste for a complete game. So I wanted to know if it is possible to write such a code which can run with `WinBoard` and which could evaluate the current position statically.
  
  It does not need to generate moves,be able to play a game, deep evaluation ,quiescent search etc.
  
  I'm also not interested in performing `King Safety`/`Mate Threats`.
  
  So the program should just give me only a number as output when loaded in `WinBoard`.
  
  Is there a simple way to perform such a task or a simple enough engine I can modify to do this?
  
  **Tags:** engines, programming, evaluation
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2017-09-12. Score: 2 | Accepted answer
  
  Why can't you just make a Winboard chess engine, but evaluate a position statically??
  
  You will need to follow the Winboard protocol:
  
  > <https://www.gnu.org/software/xboard/engine-intf.html>
  
  Although everybody uses alpha-beta/nega-max pruning, but Winboard doesn't know your code. All you need to do is just give an evaluation score from your static function.
  
  Your "engine" will wait for the `go` Winboard command. Print thinking output like:
  
  > ply score time nodes pv
  
  where score will be your static evaluation score. Your engine doesn't need to make a move, Winboard will wait forever for a move. You can always setup a new position in Winboard.
  
  > **Comments:**
  > **username_0**: Sorry but I'm unfamiliar with the Winboard protocol. Is there a better tutorial on how I can use it?  
  > **username_2**: https://chessprogramming.wikispaces.com/UCI explains how to interface with winboard and has a link to the old manual.  
  > **username_1**: @A.Napster username_2's links is good.  
  
  ---
  
  ### Answer by username_2 on 2017-09-13. Score: 0
  
  The easiest way to accomplish the goal is to download Winboard with its own engine. The GUI can be set to output the current evaluation. You can recode the eval function to your own parameters.
  
  <http://chessprogramming.wikispaces.com/Evaluation> provides some resources about programming the eval function. However, getting a well-documented source code for the eval function I find easier. Avoid the higher engines like Crafty, but a simple one like <http://www.tckerrigan.com/Chess/TSCP/> is easy to understand.
  
  Winboard is the best option, but you can create your own interface. You could modify a PGN viewer to return an eval after every move or put the FENs into a PGN file and loop through all games. You could download <https://www-lucaschess.rhcloud.com/> or another chess interface which can analyse a game and use its output.
  
  For the actual question, the chess eval is broken up into many factors.
  
  The easiest is material: just loop over the board and count the material.
  
  Next is pawn structure. Assign a penalty to isolated and doubled pawns. A bonus for passed pawns. (Pawns near the king is under king threats.) This can be modified further by changing the penalty based on the distance from the center.
  
  Next is the pieces in relation to the pawns. A bonus for a rook on a open or half-open file. A bonus for a bishop which isn't trapped behind its own pawns.
  
  Next is the pieces in relation to the center. The closer to the center the piece is, the more it is worth. This also includes a bonus for a rook on the seventh rank. (Trapping the king would improve this score, but this would fall under king safety.)
  
  There is a bonus for having a bishop pair and the values of the minor pieces (the bishops and the knights) are adjusted based upon how closed the center is. A bonus can be added for more mobility (either absolute or for each piece) and/or space control. (Concentrated force(s) is a factor normally reserved for mating threats.)
  
  This is a short list.
  
  
  ---
  
  