# $ +  GNU Chess heuristics
 Copyright (C) 1986, 1987 Free Software Foundation, Inc.
This file is part of CHESS.
CHESS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY.  No author or distributor accepts responsibility to anyone for the consequences of using it or for whether it serves any particular purpose or works at all, unless he says so in writing.  Refer to the CHESS General Public License for full details.
Everyone is granted permission to copy, modify and redistribute CHESS, but only under the conditions described in the CHESS General Public License. A copy of this license is supposed to have been given to you along with CHESS so you can know your rights and responsibilities.  It should be in a file named COPYING.  Among other things, the copyright notice and this notice must be preserved on all copies. */
 -- requested by main author
Heuristic descriptions for CHESS.
Revision: 12-16-87
Copyright (c) 1987 by John Stanback
 Here is a brief description of the heuristics used in the positional evaluator of the GNU Chess program. Many heuristics are functions of the stage of the game which is based on the total non-pawn material remaining for both sides. 
PAWNS
 The material value of a pawn is 100 points. Isolated pawns get a penalty depending on which file they occupy: (12,14,16,20,20,16,14,12) for files (a..h). Doubled pawns (which are not also isolated) get a penalty of 12 points. Backward pawns (defined simply as not being defended by a pawn with the square in front also not defended by a a pawn) are penalized 6 points. A 4 point penalty is also invoked for each attack by the opponent to a backward pawn and for a backward pawn on a half-open file. Pawn Advancement in the centre is given a bonus of about 4 points per rank in the opening increasing to about 8 points per rank in the ending. Advancement on the edges is given a lower bonus. Pawns on the e and d files and on the 2nd rank are given a 10 point penalty. An additional penalty of 15 points is invoked if these pawns are also blocked. Pawns within 2 squares of the king are given a 10 point bonus. Passed pawns are given a bonus for increasing rank which is a function of stage of the game and of whether the opponent blocks or attacks one or more squares in front of the pawn or if the opponents king is in the square of the pawn. This bonus ranges from about 15 points for a pawn on the second rank up to about 300 points for a passed pawn on the 7th rank which can't be stopped from queening.
KNIGHTS
 The material value of a knight is 330 points. The main heuristic for knights is a bonus for proximity to the centre. This varies from 0 points in the corners to 30 points in the centre. Knights are also given a bonus for being within 2 squares of each enemy piece. This bonus is a function of the stage of the game, equalling 4 points in the end game. A penalty of 1 point per square is given for distance from either king. A bonus of up to 8 points (depends on stage) is given for knights which can't be driven away by enemy pawns.
BISHOPS
The material value of a bishop is 330 points. Bishops are given a bonus as material falls off the board equalling 10 points in the end game. Bishops get a bonus for mobility and Xray mobility thru pieces but not pawns. This bonus ranges from -4 points for a totally blocked bishop up to 18 points for a bishop attacking 12 or more squares. Xray attacks on an enemy R,Q,K or any undefended piece are given an 8 point bonus. Bishops are given a bonus of 14 points if they lie on the edge of the board up to 22 points if the lie in the centre. A bishop is given a bonus of up to 5 points for each attack to a square adjacent to the enemy king.
ROOKS
The material value of a rook is 520 points. Rook mobility is handled similiarly to bishops with a bonus of 0 points if blocked up to 20 points if attacking 12 squares or more. A bonus of 8 points for Xray attacks is handled as it is for bishops. Rooks are given a bonus of 10 points for occupying a file with no friendly pawns and a bonus of 4 points if no enemy pawns lie on that file. After the opening Rooks are penalized slightly depending on "taxicab" distance to the enemy king.
QUEENS
The material value of a queen is 980 points. The only heuristic for a queen is that after the opening it is penalized slightly for "taxicab" distance to the enemy king.
KINGS
Kings are given a penalty for proximity to the centre in the opening and a bonus for proximity to the centre in the endgame. The penalty is about 24 points for being in the centre in the opening with a bonus of about 36 points for being in the centre in the endgame. Kings are penalized for lying on an open or half-open file or if the adjacent file closest to the corner is open or half-open. This penalty is up to 23 points in the opening and goes to zero in the end game. The King is penalized up to 8 points if there are no pawns immediately adjacent. A penalty is invoked depending on the number of "safe" checks available by the opponent. This penalty ranges from 6 points for one such check to 50 points for 4 or more. Depending on game stage, Kings are given up to 10 points for castling and a penalty of up to 40 points for moving before castling.
SPECIAL
If more than one piece is "hung" (attacked and not defended or attacked by an enemy piece of lower value) an extra penalty of 10 points is invoked for that side and the search may be extended one ply. Pinned or trapped pieces are treated similarly. A special mating routine is used if one side has only a king and the other has mating material.