Answers.Body: <h2>Evaluation Function</h2>
  <p>That measure is called the <a href="https://www.chessprogramming.org/Evaluation" rel="noreferrer"><strong>evaluation function</strong></a>. Each bot can have a different evaluation function depending on how you want it to behave. Will it favour dynamic play or will it play positionally and emphasize pawn structure? If your bot uses a <strong>classical evaluation</strong> function, these features can be weighted/tuned according to your needs.
  Here are some examples of features commonly used in classical evaluation functions:</p>
  <ul>
  <li>Material</li>
  <li>Pawn Structure</li>
  <li>Evaluation of Pieces (e.g. good vs bad minor piece)</li>
  <li>Mobility</li>
  <li>Center Control</li>
  <li>King Safety</li>
  <li>Space</li>
  </ul>
  <p>For example, if you want to create a bot that plays aggressively, you might try to make it value material and pawn structure less and mobility and king safety more. You can visit the <a href="https://www.chessprogramming.org/Evaluation" rel="noreferrer">Chessprogramming Wiki</a> to see more examples and how such features could be measured and implemented.
  You can also come up with own features such as <a href="https://lichess.org/@/Boris-Trapsky" rel="noreferrer">&quot;trappiness&quot;</a>, be creative! If you want it to make hyper-aggressive pawn thrusts, you could for example reward moves like g4 in the early game phase.</p>
  <p>I suggest you use Stockfish, for anything not related to the evaluation (a chess engine also needs a search) and use your own evaluation function, which should be pretty easy to do.</p>
  <p>This has already been done, <a href="https://lichess.org/@/simpleEval" rel="noreferrer">see the SimpleEval bot</a>. Your evaluation function does not even need to be extremely complex to reach acceptable playing strength, as you can see in that extreme example. Here is the bot's <a href="https://github.com/ddugovic/Stockfish/tree/simpleEval" rel="noreferrer">source code</a>.</p>
  <p>You can also try to use a <strong>neural network evaluation</strong> function. There is <a href="https://arxiv.org/abs/2006.01855" rel="noreferrer">research</a> on how to make neural network evals play &quot;human moves&quot; rather than &quot;computer moves&quot;, the result being the <a href="https://lichess.org/@/maia9" rel="noreferrer">Maia-bots</a>.
  You can try a similar approach to what they write in the paper, but instead of learning on random games learn on games of specific players (e.g. attacking players).
  This is easier said than done, however, as your training set will probably be extremely small compared to what Maia had to train.
  Here are some ideas on how you might make it work:</p>
  <ul>
  <li>learn on self-play or human games, but weigh the games of the players you want to mimic much more heavily</li>
  <li>try transfer learning</li>
  <li>do some original research</li>
  </ul>
  <p>That being said, I think that it should be easiest to use a classical evaluation as it is much easier and cheaper to test and tweak.</p>
  <p>If you do not want to write your own evaluation function, you can also take an existing one and tweak it. You might already get interesting results by tweaking the parameters of existing engines, e.g. <a href="https://github.com/LeelaChessZero/lc0/pull/1791" rel="noreferrer">contempt</a> (here is the <a href="https://www.chessprogramming.org/Contempt_Factor" rel="noreferrer">wiki entry</a>). The contempt factor will influence how much the engine tries to avoid (or seek) draws, therefore playing more riskily and aggressively (or solidly).
  Pair that with an opening book (see next section) - and tada - you already have a bot playing in a certain style!</p>
  <h2>Opening book</h2>
  <p>In order to help the bot to behave the way you intend, it is very advisable to give it an opening repertoire that suits its intended play-style.</p>
  <p>This is done on chess.com to create bots of famous players.</p>
  <p>If you prescribe your bot to play the sharpest variations of the Sicilian, it will be forced to play aggressively.</p>
  <p>This will be a head start for your bot and I expect the opening book to make your task much easier.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-12-21T19:06:20.250Z
Answers.Text: thank you for your explanation!
Answers.UserDisplayName: Chris Sanders
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-12-20T22:36:30.453Z
Answers.LastActivityDate: 2022-12-20T23:17:37.007Z
Answers.LastEditDate: 2022-12-20T23:17:37.007Z
Answers.UserDisplayName: Hauptideal
Body: <p>There are these cute chess.com bots against which you can play, which not only have different strengths but supposedly different playing styles.</p>
  <p>I haven't researched exactly how &quot;limiting engine strength&quot; is done, but since other programs do it I can look it up.</p>
  <p>But what is more interesting is how to program a bot that likes being aggressive or passive, that is dynamic or solid, etc.</p>
  <p>Could you describe how to measure whether a move is to the liking of a player with a certain style? What is that measure?</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2022-12-20T09:16:18.523Z
Comments.Text: https://chess.stackexchange.com/questions/34977/can-a-chess-engine-play-like-a-particular-famous-player and https://chess.stackexchange.com/questions/7607/how-to-make-a-computer-play-like-a-player - do these answers help?
Comments.UserDisplayName: Hauke Reddmann
Tags: <engines><programming><style>
Title: How do you program a chess bot with specific style?
ThreadText: # How do you program a chess bot with specific style?
  
  (Asked by: username_0 on 2022-12-20)
  
  There are these cute chess.com bots against which you can play, which not only have different strengths but supposedly different playing styles.
  
  I haven't researched exactly how "limiting engine strength" is done, but since other programs do it I can look it up.
  
  But what is more interesting is how to program a bot that likes being aggressive or passive, that is dynamic or solid, etc.
  
  Could you describe how to measure whether a move is to the liking of a player with a certain style? What is that measure?
  
  **Tags:** engines, programming, style
  
  > **Comments:**
  > **username_1**: https://chess.stackexchange.com/questions/34977/can-a-chess-engine-play-like-a-particular-famous-player and https://chess.stackexchange.com/questions/7607/how-to-make-a-computer-play-like-a-player - do these answers help?  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2022-12-20. Score: 5 | Accepted answer
  
  ## Evaluation Function
  
  That measure is called the [**evaluation function**](https://www.chessprogramming.org/Evaluation). Each bot can have a different evaluation function depending on how you want it to behave. Will it favour dynamic play or will it play positionally and emphasize pawn structure? If your bot uses a **classical evaluation** function, these features can be weighted/tuned according to your needs.
  Here are some examples of features commonly used in classical evaluation functions:
  
  * Material
  * Pawn Structure
  * Evaluation of Pieces (e.g. good vs bad minor piece)
  * Mobility
  * Center Control
  * King Safety
  * Space
  
  For example, if you want to create a bot that plays aggressively, you might try to make it value material and pawn structure less and mobility and king safety more. You can visit the [Chessprogramming Wiki](https://www.chessprogramming.org/Evaluation) to see more examples and how such features could be measured and implemented.
  You can also come up with own features such as ["trappiness"](https://lichess.org/@/Boris-Trapsky), be creative! If you want it to make hyper-aggressive pawn thrusts, you could for example reward moves like g4 in the early game phase.
  
  I suggest you use Stockfish, for anything not related to the evaluation (a chess engine also needs a search) and use your own evaluation function, which should be pretty easy to do.
  
  This has already been done, [see the SimpleEval bot](https://lichess.org/@/simpleEval). Your evaluation function does not even need to be extremely complex to reach acceptable playing strength, as you can see in that extreme example. Here is the bot's [source code](https://github.com/ddugovic/Stockfish/tree/simpleEval).
  
  You can also try to use a **neural network evaluation** function. There is [research](https://arxiv.org/abs/2006.01855) on how to make neural network evals play "human moves" rather than "computer moves", the result being the [Maia-bots](https://lichess.org/@/maia9).
  You can try a similar approach to what they write in the paper, but instead of learning on random games learn on games of specific players (e.g. attacking players).
  This is easier said than done, however, as your training set will probably be extremely small compared to what Maia had to train.
  Here are some ideas on how you might make it work:
  
  * learn on self-play or human games, but weigh the games of the players you want to mimic much more heavily
  * try transfer learning
  * do some original research
  
  That being said, I think that it should be easiest to use a classical evaluation as it is much easier and cheaper to test and tweak.
  
  If you do not want to write your own evaluation function, you can also take an existing one and tweak it. You might already get interesting results by tweaking the parameters of existing engines, e.g. [contempt](https://github.com/LeelaChessZero/lc0/pull/1791) (here is the [wiki entry](https://www.chessprogramming.org/Contempt_Factor)). The contempt factor will influence how much the engine tries to avoid (or seek) draws, therefore playing more riskily and aggressively (or solidly).
  Pair that with an opening book (see next section) - and tada - you already have a bot playing in a certain style!
  
  ## Opening book
  
  In order to help the bot to behave the way you intend, it is very advisable to give it an opening repertoire that suits its intended play-style.
  
  This is done on chess.com to create bots of famous players.
  
  If you prescribe your bot to play the sharpest variations of the Sicilian, it will be forced to play aggressively.
  
  This will be a head start for your bot and I expect the opening book to make your task much easier.
  
  > **Comments:**
  > **username_0**: thank you for your explanation!  
  
  ---
  
  