Wednesday, August 14, 2019

How to Write a Chess Program

There are a number of reasons why you may be interested in how a chess program is written:

  • You are learning programming and interested in learning something different.
  • You are a programmer who is interesting in developing their programming experience.
  • You are a chess enthusiast and would like to improve your chess by learning how chess programs work.
  • You are interested in developing a chess program and playing against it.
  • You are interested in developing a chess program and having it play other engines.

You do need to be an expert programmer to understand this book. The code is written as simply as possible. The code is designed to be simple even for intermediate and even novice programmers.

If you are not a programmer, but am interested in chess, this book may be of interest.

The book includes the source code for a complete chess engine. The program can be compiled using a freely downloadable compiler. You can alter the code and see if you can make it stronger.

The engine is strong enough to beat most social players.

Features of the engine include:

  • The ability to load positions.
  • The ability to play in chess engine tournaments, with programs such as Arena.
  • Its very fast.
  • It displays the best line of play for both sides.
  • Detects reality of opponent’s pieces.
  • Detects checkmate.
  • Detects draws by repetition, 50 move rule, statemate or reduction of material.

Evaluation

The engine evaluates elements of a position including:

  • Material.
  • Piece position.
  • King safety.
  • Pawn structure.
  • Passed pawns.

Search

The engine uses a standard alpha-beta minimax search including:

  • Cut offs.
  • Move ordering.
  • History moves,
  • Hash tables.
  • Extensions.
  • Reductions.
  • Capture search.

And much more…

*/
int knight_score[64] = 
{
	-30, -20, -10,  -8,  -8, -10, -20, -30,
	-16, -6,   -2,   0,   0,   -2, -6, -16,
	-8,   -2,   4,   6,   6,   4,   -2, -8,
	-5,   0,   6,   8,   8,   6,   0, -5,
	-5,   0,   6,   8,   8,   6,   0, -5,
	-10,   -2,   4,   6,   6,   4,   -2, -10,
	-20, -10,   -2,   0,   0,   -2, -10, -20,
	-150, -20, -10, -5, -5, -10, -20, -150
};
/*
The knight gets stronger as it approaches the centre. The knight tends to be very weak in a corner on the opponent’s side. It is likely to be trapped there.

No comments:

Post a Comment