Chess engine’s anatomy

[This article was originally published in my personal blog. This is a new version.]
A chess engine is simply a console program that reads some input (a move, a command…) from standard input and write output (a move, a command…) in standard output. But in which way a computer can play to chess? Well, it isn’t simple, but with simple words we can say that a chess engine:
  1. it reads a move
  2. it updates an internal representation of chess board
  3. from this position (root) it generates all possible moves
  4. for every moves: it generates all countermoves and so on…
  5. at the end it uses an evaluation function and measures the best position
  6. it writes (like output) the move that leads itself to the best position

Remember: this is a very simplified version! Now you can understand that to write a chess engine you need:

  • Some way to represent a chess board in memory;
  • Some way to update the chess board;
  • Some way to generate moves;
  • A technique to choose the move to make amongst all legal possibilities;
  • An evaluation function;
  • Some sort of user interface;

You can forget to program an user interface: we’ll use Winboard or Arena, two very popular freeware G.U.I. In that way we must write a simple console program that reads and writes from/to Standard Input/Output.

To start i suggest to schedule your work in this way:

  1. decide how to represent chessboard in memory
  2. write utility function to translate FEN position into your chessboard representation
  3. write moves generator
  4. write function to understand if a square is attacked by a color
  5. write functions to update your chessboard representation
  6. Main check point 1: stop, write a Perft function and debug!
  7. write a simple evaluation function
  8. write a search function
  9. write a function that drives this search
  10. write a simple function to talk with Winboard/Arena
  11. Main check point 2: stop and debug!

Remember it is better first to write a simple engine and then to improve it step by step.

You can find a lot of hints, info and papers in:

Leave a Reply

You must be logged in to post a comment.

Sponsored Links
Connect with Facebook
Login