Friday, December 14, 2012

Chess Engine Programming - the 3 most important elements of a chess engine which enable it to think and decide the best


Legal Move Generator


This chess engine component checks whether the moves are valid or legal. There are certain movement rules for each piece of the board as well as special moves. There are 5 important pawn moves: Promotion, En passant (e.p.), Capture, Two-square move, and one-square move. Knights move in L-shaped squares and can move backwards. Bishops move along diagonals of the same color and can also move backwards. Rooks move any number of squares straight vertically or straight horizontally. Castling is a special rook movement in which it jumps over the King. The Queen moves like a Bishop and a Rook. It moves along diagonals, files, and ranks any number of squares forward or backward. The King can move any direction as long as it is one square only. The only exception to this rule is when it is castling wherein it moves two squares. The Legal Move Generator also checks Draws by three-fold repetition, Draw by 50-move rule, Draw by insufficient material to checkmate, White King checks, Black King checks, Checkmate and more.


Score Evaluation Function

This is the "brain" of the chess engine. It "thinks" and forms the basis for decision of the chess engine. It assigns values for any situation within the board. For every movement of the pieces there is a corresponding score computed. For example a move leading to a checkmate would have a high score, an exchange leading to a material advantage, a pawn promotion, a move making the opponent's pieces in a cramped position, centered pawns, centered Knights, centered Bishops, isolated pawns, rook-pawns, doubled pawns, discovered checks, rook battery, absolute pin, forks, regular pin, etc.


Search Algorithm

Chess engine programmers often use the Minimax algorithm to search the best move possible in a given particular board position and situation. It takes and tests moves from the Legal Move Generator and checks to find the minimum score for the opponent while maximum score for the engine. Minimax can also be understood as an algorithm to search for the best possible move in a given situation. The more move turns (plies) it searches, the deeper and better will be the move that will be generated. Time is also a function to bring out the best move. Transposition tables also provide a superior search return. Searches from a book of similar played games with known variations leading to a win is also a good supplement.

No comments:

Post a Comment