home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 8
/
FreshFishVol8-CD1.bin
/
useful
/
game
/
think
/
uchess
/
src
/
eval.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-08-04
|
55KB
|
2,071 lines
#define WAY4PL64 1 // for K1PK code
//#define PRE4PL67 1 // go back to 4pl63/64 stuff
/*
* eval.c - C source for GNU CHESS
*
* Copyright (c) 1988,1989,1990 John Stanback
* Copyright (c) 1992 Free Software Foundation
*
* This file is part of GNU CHESS.
*
* GNU Chess is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* GNU Chess is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU Chess; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "gnuchess.h"
#include "ataks.h"
int __aligned EADD = 0;
int __aligned EGET = 0;
int __aligned PUTVAR = false;
#ifdef CACHE
struct etable __far __aligned etab[2][ETABLE];
#endif
int ScoreKBNK (short winner, short king1, short king2);
int ScoreKPK (short side,
short winner,
short loser,
short king1,
register short king2,
register short sq);
extern short __aligned PCRASH,PCENTER;
short __aligned QueenCheck[MAXDEPTH]; /* tom@izf.tno.nl */
int __aligned myneweval=1;
short int __aligned sscore[2];
/* Backward pawn bonus indexed by # of attackers on the square */
static const short __aligned BACKWARD[16] =
{-6, -10, -15, -21, -28, -28, -28, -28, -28, -28, -28, -28, -28, -28, -28, -28};
/* Bishop mobility bonus indexed by # reachable squares */
static const short __aligned BMBLTY[14] =
{-2, 0, 2, 4, 6, 8, 10, 12, 13, 14, 15, 16, 16, 16};
/* Rook mobility bonus indexed by # reachable squares */
static const short __aligned RMBLTY[15] =
{0, 2, 4, 6, 8, 10, 11, 12, 13, 14, 14, 14, 14, 14, 14};
/* Positional values for a dying king */
static const short __aligned DyingKing[64] =
{0, 8, 16, 24, 24, 16, 8, 0,
8, 32, 40, 48, 48, 40, 32, 8,
16, 40, 56, 64, 64, 56, 40, 16,
24, 48, 64, 72, 72, 64, 48, 24,
24, 48, 64, 72, 72, 64, 48, 24,
16, 40, 56, 64, 64, 56, 40, 16,
8, 32, 40, 48, 48, 40, 32, 8,
0, 8, 16, 24, 24, 16, 8, 0};
/* Isoloted pawn penalty by rank */
static const short __aligned ISOLANI[8] =
{-12, -16, -20, -24, -24, -20, -16, -12};
/* table for King Bishop Knight endings */
static const short __aligned KBNK[64] =
#ifdef PRE4PL67KBNK
{99, 90, 80, 70, 60, 50, 40, 40,
90, 80, 60, 50, 40, 30, 20, 40,
80, 60, 40, 30, 20, 10, 30, 50,
70, 50, 30, 10, 0, 20, 40, 60,
60, 40, 20, 0, 10, 30, 50, 70,
50, 30, 10, 20, 30, 40, 60, 80,
40, 20, 30, 40, 50, 60, 80, 90,
40, 40, 50, 60, 70, 80, 90, 99};
#else
{620, 560, 500, 440, 380, 320, 260, 240,
560, 520, 460, 400, 340, 280, 230, 260,
500, 460, 320, 280, 260, 220, 280, 320,
440, 400, 280, 200, 200, 260, 340, 380,
380, 340, 260, 200, 200, 280, 400, 440,
320, 280, 220, 260, 280, 320, 460, 500,
260, 230, 280, 340, 400, 460, 520, 560,
240, 260, 320, 380, 440, 500, 560, 620};
#endif
/* penalty for threats to king, indexed by number of such threats */
static const short __aligned KTHRT[36] =
{0, -8, -20, -36, -52, -68, -80, -80, -80, -80, -80, -80,
-80, -80, -80, -80, -80, -80, -80, -80, -80, -80, -80, -80,
-80, -80, -80, -80, -80, -80, -80, -80, -80, -80, -80, -80};
/* King positional bonus inopening stage */
static const short __aligned KingOpening[64] =
{0, 0, -4, -10, -10, -4, 0, 0,
-4, -4, -8, -12, -12, -8, -4, -4,
-12, -16, -20, -20, -20, -20, -16, -12,
-16, -20, -24, -24, -24, -24, -20, -16,
-16, -20, -24, -24, -24, -24, -20, -16,
-12, -16, -20, -20, -20, -20, -16, -12,
-4, -4, -8, -12, -12, -8, -4, -4,
0, 0, -4, -10, -10, -4, 0, 0};
/* King positional bonus in end stage */
static const short __aligned KingEnding[64] =
{0, 6, 12, 18, 18, 12, 6, 0,
6, 12, 18, 24, 24, 18, 12, 6,
12, 18, 24, 30, 30, 24, 18, 12,
18, 24, 30, 36, 36, 30, 24, 18,
18, 24, 30, 36, 36, 30, 24, 18,
12, 18, 24, 30, 30, 24, 18, 12,
6, 12, 18, 24, 24, 18, 12, 6,
0, 6, 12, 18, 18, 12, 6, 0};
/* Passed pawn positional bonus */
static const short __aligned PassedPawn0[8] =
{0, 60, 80, 120, 200, 360, 600, 800};
static const short __aligned PassedPawn1[8] =
{0, 30, 40, 60, 100, 180, 300, 800};
static const short __aligned PassedPawn2[8] =
{0, 15, 25, 35, 50, 90, 140, 800};
static const short __aligned PassedPawn3[8] =
{0, 5, 10, 15, 20, 30, 140, 800};
/* Knight positional bonus */
static const short __aligned pknight[64] =
{0, 4, 8, 10, 10, 8, 4, 0,
4, 8, 16, 20, 20, 16, 8, 4,
8, 16, 24, 28, 28, 24, 16, 8,
10, 20, 28, 32, 32, 28, 20, 10,
10, 20, 28, 32, 32, 28, 20, 10,
8, 16, 24, 28, 28, 24, 16, 8,
4, 8, 16, 20, 20, 16, 8, 4,
0, 4, 8, 10, 10, 8, 4, 0};
/* Bishop positional bonus */
static const short __aligned pbishop[64] =
{14, 14, 14, 14, 14, 14, 14, 14,
14, 22, 18, 18, 18, 18, 22, 14,
14, 18, 22, 22, 22, 22, 18, 14,
14, 18, 22, 22, 22, 22, 18, 14,
14, 18, 22, 22, 22, 22, 18, 14,
14, 18, 22, 22, 22, 22, 18, 14,
14, 22, 18, 18, 18, 18, 22, 14,
14, 14, 14, 14, 14, 14, 14, 14};
/* Pawn positional bonus */
static const short __aligned PawnAdvance[64] =
{0, 0, 0, 0, 0, 0, 0, 0,
4, 4, 4, 0, 0, 4, 4, 4,
6, 8, 2, 10, 10, 2, 8, 6,
6, 8, 12, 16, 16, 12, 8, 6,
8, 12, 16, 24, 24, 16, 12, 8,
12, 16, 24, 32, 32, 24, 16, 12,
12, 16, 24, 32, 32, 24, 16, 12,
0, 0, 0, 0, 0, 0, 0, 0};
#define AHOPEN (-250)
short __aligned Mwpawn[64];
short __aligned Mbpawn[64];
short __aligned Mknight[2][64];
short __aligned Mbishop[2][64];
static short __aligned Mking[2][64];
static short __aligned Kfield[2][64];
static short __aligned c1, c2, *atk1, *atk2, *PC1, *PC2;
static short __aligned atak[2][64];
short __aligned emtl[2];
static short __aligned PawnBonus, BishopBonus, RookBonus;
static short __aligned KNIGHTPOST, KNIGHTSTRONG, BISHOPSTRONG, KATAK;
static short __aligned PEDRNK2B, PWEAKH, PADVNCM, PADVNCI, PAWNSHIELD, PDOUBLED, PBLOK;
static short __aligned RHOPN, RHOPNX, KHOPN, KHOPNX, KSFTY;
static short __aligned ATAKD, HUNGP, HUNGX, KCASTLD, KMOVD, XRAY, PINVAL;
short __aligned pscore[2];
short __aligned tmtl;
#ifdef CACHE
inline void
PutInEETable (ARGSZ int side,int score)
/*
* Store the current eval position in the transposition table.
*/
{
register struct etable *ptbl;
ptbl = &etab[side][hashkey % (ETABLE)];
// if (ptbl->ehashbd == hashbd) return;
ptbl->ehashbd = hashbd;
ptbl->escore[white] = pscore[white];
ptbl->escore[black] = pscore[black];
ptbl->hung[white] = hung[white];
ptbl->hung[black] = hung[black];
ptbl->score = score;
#ifndef AMIGA
memcpy ( &(ptbl->sscore), svalue, sizeof (svalue));
#else
MoveMem128(svalue,&(ptbl->sscore));
/* MoveMem(svalue,&(ptbl->sscore),sizeof (svalue));*/
#endif
/* bcopy (&(ptbl->sscore), svalue, sizeof (svalue)); */
#if !defined CHESSTOOL && !defined XBOARD
EADD++;
#endif
return;
}
inline int
CheckEETable (ARGSZ int side)
/* Get an evaluation from the transposition table */
{
register struct etable *ptbl;
ptbl = &etab[side][hashkey % (ETABLE)];
if (hashbd == ptbl->ehashbd) return true;
return false;
}
inline int
ProbeEETable (short int side, short int *score)
/* Get an evaluation from the transposition table */
{
register struct etable *ptbl;
ptbl = &etab[side][hashkey % (ETABLE)];
if (hashbd == ptbl->ehashbd)
{
pscore[white] = ptbl->escore[white];
pscore[black] = ptbl->escore[black];
#ifndef AMIGA
memcpy (svalue, &(ptbl->sscore), sizeof (svalue));
#else
MoveMem128(&(ptbl->sscore),svalue);
/* MoveMem (&(ptbl->sscore),svalue, sizeof (svalue));*/
#endif
*score = ptbl->score;
hung[white] = ptbl->hung[white];
hung[black] = ptbl->hung[black];
#if !defined CHESSTOOL && !defined XBOARD
EGET++;
#endif
return true;
}
return false;
}
#endif
short dist_ (short, short, short, short);
short kpkwv_ (short, short, short, short, short, short);
#ifndef PRE4PL67
short
kpkwv_ (short pf, short pr, short wf, short wr, short bf, short br)
{
/*
* Don B