home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 October
/
usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso
/
games
/
volume11
/
reve
/
part06
/
rev_eval.c
< prev
next >
Wrap
C/C++ Source or Header
|
1990-11-15
|
8KB
|
226 lines
/* @(#)rev_eval.c 1.3 90/09/24
*
* Copyright (C) 1990 - Yves Gallot - all rights reserved.
*
* Permission is given to distribute these sources, as long as the
* introductory messages are not removed, and no monies are exchanged.
*
* You are forbidden from using Reve as is, or in a modified state, in
* any tournaments, without the permission of the authors.
*
* No responsibility is taken for any errors on inaccuracies inherent
* either to the comments or the code of this program, but if reported
* (see README file), then an attempt will be made to fix them.
*/
#include "reve.h"
extern int damier[NIVEAUMAX][64] ;
extern int tacouleur, macouleur ;
extern int mnb, profmax ;
extern int vp0, vo0 ;
extern long c1, c2, c3 ;
extern long edges[6561] ;
/* Evaluation function : give a note to a board = damier[ niv ].
* It computes 4 components :
* - Edge Stability, using Edge Stability Table pre-computed before
* - Current Mobility, in fact computed during alpha-beta pruning
* - X squares Values
* - Potential Mobility, looking at squares contacts
* And then Eval = c1 * ES + c2 * CM + c3 * XV + c4 * PM
* Eval is replaced by - Eval if Black is replaced by White. Eval is positif
* if macouleur ( my color ) has a good position and negatif if tacouleur
* position is good.
* If we are "near" the end of the game, then Eval is equal to final disc
* differential.
*/
long
evalue(niv)
int niv ;
{
register int *d, *p ;
register int i, x, y ;
register long note ;
register int vp, vo ;
register long tnote ;
d = damier[niv] ;
if (mnb > 60 - profmax)
{
note = 0 ;
for (p = &d[0]; p < &d[64]; p++)
if (*p == macouleur) note++ ;
else if (*p == tacouleur) note-- ;
return(note) ;
}
else
{
x = y = 0 ;
for (p = &d[0]; p < &d[64]; p++)
if (*p == macouleur) x++ ;
else if (*p == tacouleur) y++ ;
if (x == 0) return(-100000000) ;
if (y == 0) return( 100000000) ;
for (p = &d[0]; p < &d[64]; p++)
if ((*p == TPJ) || (*p == JPJ)) *p = FREE ;
i = 0 ;
for (p = &d[0]; p < &d[8]; p++)
{
i += i + i ;
if (*p == FREE) i++ ;
else if (*p == macouleur) i += 2 ;
}
note = edges[i] ;
i = 0 ;
for (p = &d[56]; p < &d[64]; p++)
{
i += i + i ;
if (*p == FREE) i++ ;
else if (*p == macouleur) i += 2 ;
}
note += edges[i] ;
i = 0 ;
for (p = &d[0]; p < &d[64]; p += 8)
{
i += i + i ;
if (*p == FREE) i++ ;
else if (*p == macouleur) i += 2 ;
}
note += edges[i] ;
i = 0 ;
for (p = &d[7]; p < &d[64]; p += 8)
{
i += i + i ;
if (*p == FREE) i++ ;
else if (*p == macouleur) i += 2 ;
}
note += edges[i] ;
if (d[0] == FREE)
{
if (d[9] == macouleur) note -= c3 ;
else if (d[9] == tacouleur) note += c3 ;
}
if (d[7] == FREE)
{
if (d[14] == macouleur) note -= c3 ;
else if (d[14] == tacouleur) note += c3 ;
}
if (d[56] == FREE)
{
if (d[49] == macouleur) note -= c3 ;
else if (d[49] == tacouleur) note += c3 ;
}
if (d[63] == FREE)
{
if (d[54] == macouleur) note -= c3 ;
else if (d[54] == tacouleur) note += c3 ;
}
tnote = c1 * note + c2 * (vp0 - vo0) / (vp0 + vo0 + 2) ;
vp = vo = 0 ;
for (x = 0; x < 8; x++)
for (y = 0; y < 8; y++)
{
i = (x << 3) + y ;
if (d[i] == tacouleur)
{
if ((x > 0) && (d[i - 8] == FREE)) vp++ ;
else if ((x < 7) && (d[i + 8] == FREE)) vp++ ;
else if ((y > 0) && (d[i - 1] == FREE)) vp++ ;
else if ((y < 7) && (d[i + 1] == FREE)) vp++ ;
else if ((x > 0) && (y > 0) && (d[i - 9] == FREE)) vp++ ;
else if ((x < 7) && (y > 0) && (d[i + 7] == FREE)) vp++ ;
else if ((x > 0) && (y < 7) && (d[i - 7] == FREE)) vp++ ;
else if ((x < 7) && (y < 7) && (d[i + 9] == FREE)) vp++ ;
}
if (d[i] == macouleur)
{
if ((x > 0) && (d[i - 8] == FREE)) vo++ ;
else if ((x < 7) && (d[i + 8] == FREE)) vo++ ;
else if ((y > 0) && (d[i - 1] == FREE)) vo++ ;
else if ((y < 7) && (d[i + 1] == FREE)) vo++ ;
else if ((x > 0) && (y > 0) && ( d[i - 9] == FREE)) vo++ ;
else if ((x < 7) && (y > 0) && ( d[i + 7] == FREE)) vo++ ;
else if ((x > 0) && (y < 7) && ( d[i - 7] == FREE)) vo++ ;
else if ((x < 7) && (y < 7) && ( d[i + 9] == FREE)) vo++ ;
}
}
note = ((long) 1000 * (vp - vo)) / (vp + vo + 2) ;
vp = vo = 0 ;
for (x = 0; x < 8; x++)
for (y = 0; y < 8; y++)
{
i = (x << 3) + y ;
if (d[i] == FREE)
{
if ((x > 0) && (d[i - 8] == tacouleur)) vp++ ;
else if ((x < 7) && (d[i + 8] == tacouleur)) vp++ ;
else if ((y > 0) && (d[i - 1] == tacouleur)) vp++ ;
else if ((y < 7) && (d[i + 1] == tacouleur)) vp++ ;
else if ((x > 0) && (y > 0) && (d[i - 9] == tacouleur)) vp++ ;
else if ((x < 7) && (y > 0) && (d[i + 7] == tacouleur)) vp++ ;
else if ((x > 0) && (y < 7) && (d[i - 7] == tacouleur)) vp++ ;
else if ((x < 7) && (y < 7) && (d[i + 9] == tacouleur)) vp++ ;
if ((x > 0) && (d[i - 8] == macouleur)) vo++ ;
else if ((x < 7) && (d[i + 8] == macouleur)) vo++ ;
else if ((y > 0) && (d[i - 1] == macouleur)) vo++ ;
else if ((y < 7) && (d[i + 1] == macouleur)) vo++ ;
else if ((x > 0) && (y > 0) && (d[i - 9] == macouleur)) vo++ ;
else if ((x < 7) && (y > 0) && (d[i + 7] == macouleur)) vo++ ;
else if ((x > 0) && (y < 7) && (d[i - 7] == macouleur)) vo++ ;
else if ((x < 7) && (y < 7) && (d[i + 9] == macouleur)) vo++ ;
}
}
note += ((long) 1000 * (vp - vo)) / (vp + vo + 2) ;
vp = vo = 0 ;
for (x = 0; x < 8; x++)
for (y = 0; y < 8; y++)
{
i = (x << 3) + y ;
if (d[i] == FREE)
{
if ((x > 0) && (d[i - 8] == tacouleur)) vp++ ;
if ((x < 7) && (d[i + 8] == tacouleur)) vp++ ;
if ((y > 0) && (d[i - 1] == tacouleur)) vp++ ;
if ((y < 7) && (d[i + 1] == tacouleur)) vp++ ;
if ((x > 0) && (y > 0) && (d[i - 9] == tacouleur)) vp++ ;
if ((x < 7) && (y > 0) && (d[i + 7] == tacouleur)) vp++ ;
if ((x > 0) && (y < 7) && (d[i - 7] == tacouleur)) vp++ ;
if ((x < 7) && (y < 7) && (d[i + 9] == tacouleur)) vp++ ;
if ((x > 0) && (d[i - 8] == macouleur)) vo++ ;
if ((x < 7) && (d[i + 8] == macouleur)) vo++ ;
if ((y > 0) && (d[i - 1] == macouleur)) vo++ ;
if ((y < 7) && (d[i + 1] == macouleur)) vo++ ;
if ((x > 0) && (y > 0) && (d[i - 9] == macouleur)) vo++ ;
if ((x < 7) && (y > 0) && (d[i + 7] == macouleur)) vo++ ;
if ((x > 0) && (y < 7) && (d[i - 7] == macouleur)) vo++ ;
if ((x < 7) && (y < 7) && (d[i + 9] == macouleur)) vo++ ;
}
}
note += ((long) 1000 * (vp - vo)) / (vp + vo + 2) ;
tnote += 99 * note ;
return(tnote) ;
}
}