📄 evaluate.cpp
字号:
PVTable[color][piececount][square] = posval;
}
}
}
RootValue = 0;
//双重攻击,应该加分
int tmp = 0;
int i = 0;
SQUARETYPE squar[12];
squar[0] = 0;
/*
在C++ Builder中枚举常量加一个常数,不能成为后一个常量。
只得采用整数间接来达到目的。
*/
for (asquare = 0; asquare <= 0x98; ((int)asquare)++)
if (((asquare>>4)<10) && ((asquare % 16)<9) && ((asquare | 0xff)>=0))
{
for ( colortemp = 0 ;colortemp <= 1; colortemp++)
{
if (colortemp==0)acolor=red;
if (colortemp==1)acolor=black;
}
for (piecetemp = 0; piecetemp <= 6; piecetemp++)
{
if (piecetemp==0)apiece=king;
if (piecetemp==1)
apiece=rook;
if (piecetemp==2)
apiece=gunner;
if (piecetemp==3)
apiece=knight;
if (piecetemp==4)
apiece=assist;
if(piecetemp==5)
apiece=bishop;
if (piecetemp==6)
apiece=pawn;
}
for (square = 0; square <= 0x98; (int) square++)
if (((square>>4)<10) && ((square % 16)<9) && ((square | 0xff)>=0))
if ((ChessBoard[asquare].piece == apiece) && (ChessBoard[asquare].color == acolor))
{
if (PieceAttacks(apiece, acolor, asquare, square))
tmp +=1;
squar[i] = square;
i +=1;
}
}
if (tmp >= 2)
{
{
if (colortemp==0)acolor=red;
if (colortemp==1)acolor=black;
}
{
if (piecetemp==0)
apiece=king;
if (piecetemp==1)
apiece=rook;
if (piecetemp==2)
apiece=gunner;
if (piecetemp==3)
apiece=knight;
if (piecetemp==4)
apiece=assist;
if(piecetemp==5)
apiece=bishop;
if (piecetemp==6)
apiece=pawn;
}
if (!Attacks((COLORTYPE)!acolor, asquare))
if (PieceValue[ChessBoard[squar[0]].piece] >= PieceValue[ChessBoard[squar[1]].piece])
PVTable[acolor][apiece][asquare] += PieceValue[ChessBoard[squar[0]].piece] / 10;
else PVTable[acolor][apiece][asquare] += PieceValue[ChessBoard[squar[1]].piece] / 10;
}
/*
在C++ Builder中枚举常量加一个常数,不能成为后一个常量。
只得采用整数间接来达到目的。
*/
//过载,应该减分
tmp = 0;
for (square = 0; square <= 0x98; (int)square++)
if (((square>>4)<10) && ((square % 16)<9) && ((square | 0xff)>=0))
{
{
for (colortemp = 0; colortemp <= 1; colortemp++ )
for (piecetemp = 0; piecetemp <= 6; piecetemp++)
for (asquare = 0; asquare <= 0x98; ((int)asquare)++)
if (((asquare>>4)<10) && ((asquare % 16)<9) && ((asquare | 0xff)>=0))
{
{
if (colortemp==0)acolor=red;
if (colortemp==1)acolor=black;
}
{
if (piecetemp==0)apiece=king;
if (piecetemp==1)
apiece=rook;
if (piecetemp==2)
apiece=gunner;
if (piecetemp==3)
apiece=knight;
if (piecetemp==4)
apiece=assist;
if(piecetemp==5)
apiece=bishop;
if (piecetemp==6)
apiece=pawn;
}
if (PieceAttacks(apiece, acolor, asquare, square))
tmp +=1;
}
}
if ((tmp % 2) == 0)
PVTable[ChessBoard[square].color][ChessBoard[square].piece][square] += PieceValue[ChessBoard[square].piece] / 10;
else PVTable[ChessBoard[square].color][ChessBoard[square].piece][square] -= PieceValue[ChessBoard[square].piece] / 10;
}
/*计算车、马、炮、王棋子的活动性*/
for (square = 0; square <= 0x98; square++)
if (((square>>4)<10) && ((square % 16)<9) && ((square | 0xff)>=0))
{
if (ChessBoard[square].piece == rook)
{
RookActive = -1;
sq = square;
do
{
sq += 0x10;
RookActive += 1;
sq = sq;
} while ((sq >> 4) <= 9 && ChessBoard[sq].piece == empty );
sq = square;
do
{
sq -= 0x10;
RookActive += 1;
sq = sq;
} while ((sq >> 4) <= 9 && ChessBoard[sq].piece == empty );
sq = square;
do
{
sq += 0x01;
RookActive += 1;
sq = sq;
} while ((sq % 16) <= 8 && ChessBoard[sq].piece == empty );
sq = square;
do
{
sq -= 0x01;
RookActive += 1;
sq = sq;
} while ((sq % 16) <= 8 && ChessBoard[sq].piece == empty );
}
if (ChessBoard[square].piece == gunner)
{
GunnerActive = -1;
sq = square;
do
{
sq += 0x10;
GunnerActive += 1;
sq = sq;
} while ((sq >> 4) <= 9 && ChessBoard[sq].piece == empty );
sq = square;
do
{
sq -= 0x10;
GunnerActive += 1;
sq = sq;
} while ((sq >> 4) <= 9 && ChessBoard[sq].piece == empty );
sq = square;
do
{
sq += 0x01;
GunnerActive += 1;
sq = sq;
} while ((sq % 16) <= 8 && ChessBoard[sq].piece == empty );
sq = square;
do
{
sq -= 0x01;
GunnerActive += 1;
sq = sq;
} while ((sq % 16) <= 8 && ChessBoard[sq].piece == empty );
}
if (ChessBoard[square].piece == knight)
{
KnightActive = 0;
sq = square;
sq += 0x10;
if (((sq >> 4) <= 9) && (ChessBoard[sq].piece == empty))
KnightActive += 2;
sq = square;
sq -= 0x10;
if (((sq >> 4) <= 9) && (ChessBoard[sq].piece == empty))
KnightActive += 2;
sq = square;
sq += 0x01;
if (((sq % 16) <= 8) && (ChessBoard[sq].piece == empty))
KnightActive += 2;
sq = square;
sq -= 0x01;
if (((sq % 16) <= 8) && (ChessBoard[sq].piece == empty))
KnightActive += 2;
}
if (ChessBoard[square].piece == king)
{
KingActive = 0;
sq = square;
sq += 0x10;
if (((sq >> 4) <= 9) && (ChessBoard[sq].piece == empty))
KingActive += 1;
sq = square;
sq -= 0x10;
if (((sq >> 4) <= 9) && (ChessBoard[sq].piece == empty))
KingActive += 1;
sq = square;
sq += 0x01;
if (((sq % 16) <= 8) && (ChessBoard[sq].piece == empty))
KingActive += 1;
sq = square;
sq -= 0x01;
if (((sq % 16) <= 8) && (ChessBoard[sq].piece == empty))
KingActive += 1;
}
}
/*单马或单兵时需要利用对方欠走才能取胜*/
OnlyKnOrPa = false;
int TotalPieceCount[2] = { 0, 0 };
for (sq = 0; sq < 0x99; sq++)
if (((sq>>4)<10) && ((sq % 16)<9) && ((sq | 0xff)>=0))
{
if ((ChessBoard[sq].piece == knight)||(ChessBoard[sq].piece == pawn))
{
TotalPieceCount[ChessBoard[sq].color]++;
}
}
if ((TotalPieceCount[red] + TotalPieceCount[black]) == 1)
OnlyKnOrPa = true;
else OnlyKnOrPa = false;
/*估算车、马、炮、王棋子活动性值*/
for (square = 0; square <= 0x98; square++)
if (((square>>4)<10) && ((square % 16)<9) && ((square | 0xff)>=0))
{
if ((ChessBoard[square].piece == rook) && (ChessBoard[square].color==red))
PVTable[red][rook][square] = RookActive / 19 * 10;
if ((ChessBoard[square].piece == rook) && (ChessBoard[square].color==black))
PVTable[black][rook][square] = RookActive / 19 * 10;
if ((ChessBoard[square].piece == gunner) && (ChessBoard[square].color==red))
PVTable[red][gunner][square] = GunnerActive / 19 * 10;
if ((ChessBoard[square].piece == gunner) && (ChessBoard[square].color==black))
PVTable[black][rook][square] = GunnerActive / 19 * 10;
if ((ChessBoard[square].piece == knight) && (ChessBoard[square].color==red))
PVTable[red][knight][square] = KnightActive / 8 * 10;
if ((ChessBoard[square].piece == knight) && (ChessBoard[square].color==black))
PVTable[black][knight][square] = KnightActive / 8 * 10;
if ((ChessBoard[square].piece == king) && (ChessBoard[square].color==red)&&
(KingActive == 2) && (OnlyKnOrPa))
PVTable[red][king][square] -= 0x200;
if ((ChessBoard[square].piece == king) && (ChessBoard[square].color==black)&&
(KingActive == 2) && (OnlyKnOrPa))
PVTable[black][king][square] -= -0x200;
}
/*逐个计算棋子(车、马、炮、兵)的位置值,保存在棋子值表中*/
for (sq = 0; sq <= 0x98; sq++)
if (((sq>>4)<10) && ((sq % 16)<9) && ((sq | 0xff)>=0))
{
if ((ChessBoard[sq].piece == pawn) && (ChessBoard[sq].color == red))
PVTable[red][pawn][sq] += pawnposvalu[sq >> 4][sq % 16] / 10;
}
for (sq = 0; sq <= 0x98; sq ++)
if (((sq>>4)<10) && ((sq % 16)<9) && ((sq | 0xff)>=0))
{
if ((ChessBoard[sq].piece == pawn) && (ChessBoard[sq].color == black))
PVTable[black][pawn][sq] += pawnposvalu[9 - (sq >> 4)][sq % 16] / 10;
}
for (sq = 0; sq <= 0x98; sq++)
if (((sq>>4)<10) && ((sq % 16)<9) && ((sq | 0xff)>=0))
{
if ((ChessBoard[sq].piece == gunner) && (ChessBoard[sq].color == red))
PVTable[red][gunner][sq] += gunposvalu[sq >> 4][sq % 16] / 10;
}
for (sq = 0; sq <= 0x98; sq ++)
if (((sq>>4)<10) && ((sq % 16)<9) && ((sq | 0xff)>=0))
{
if ((ChessBoard[sq].piece == gunner) && (ChessBoard[sq].color == black))
PVTable[black][gunner][sq] += gunposvalu[9 - (sq >> 4)][sq % 16] / 10;
}
for (sq = 0; sq <= 0x98; sq ++)
if (((sq>>4)<10) && ((sq % 16)<9) && ((sq | 0xff)>=0))
{
if ((ChessBoard[sq].piece == knight) && (ChessBoard[sq].color == red))
PVTable[red][knight][sq] += knightposvalu[sq >> 4][sq % 16] / 10;
}
for (sq = 0; sq <= 0x98; sq ++)
if (((sq>>4)<10) && ((sq % 16)<9) && ((sq | 0xff)>=0))
{
if ((ChessBoard[sq].piece == knight) && (ChessBoard[sq].color == black))
PVTable[black][knight][sq] += knightposvalu[9 - (sq >> 4)][sq % 16] / 10;
}
for (sq = 0; sq <= 0x98; sq++)
if (((sq>>4)<10) && ((sq % 16)<9) && ((sq | 0xff)>=0))
{
if ((ChessBoard[sq].piece == rook) && (ChessBoard[sq].color == red))
PVTable[red][rook][sq] += rookposvalu[sq >> 4][sq % 16] / 10;
}
for (sq = 0; sq <= 0x98; sq++)
if (((sq>>4)<10) && ((sq % 16)<9) && ((sq | 0xff)>=0))
{
if ((ChessBoard[sq].piece == rook) && (ChessBoard[sq].color == black))
PVTable[black][rook][sq] += rookposvalu[9 - (sq >> 4)][sq % 16] / 10;
}
for (square = 0; square <= 0x98; square++) /* 计算根值 */
if (((square>>4)<10) && ((square % 16)<9) && ((square | 0xff)>=0))
if (ChessBoard[square].piece != empty)
if (ChessBoard[square].color == Player)
RootValue +=
PiecePosVal(ChessBoard[square].piece, Player, square);
else
RootValue -=
PiecePosVal(ChessBoard[square].piece, Opponent, square);
}
/****************************************************************************/
int value;
/*
* 移动棋子的静态评估
*/
int StatEvalu(MOVETYPE *move)
{
value = 0;
if (move->content != empty) /* 正常移动 */
{
value += PiecePosVal(move->content, Opponent, move->newpos1);
/* 在子力落后的情况下进行子力交换应给予罚分 */
if (abs(MainEvaluat) >= 0x100)
if (move->content != pawn)
if ((ProgramColor == Opponent) == (MainEvaluat >= 0))
value -= EXCHANGEVALUE;
}
return (value + PiecePosVal(move->movpiece, Player, move->newpos1)-
PiecePosVal(move->movpiece, Player, move->oldpos));
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -