3

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?

1

1 Answer 1

5

Evaluation Function

That measure is called the evaluation function. 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 to see more examples and how such features could be measured and implemented. You can also come up with own features such as "trappiness", 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. 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.

You can also try to use a neural network evaluation function. There is research on how to make neural network evals play "human moves" rather than "computer moves", the result being the Maia-bots. 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 (here is the wiki entry). 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.

1
  • 1
    thank you for your explanation! Commented Dec 21, 2022 at 19:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.