steffan wrote:
I use the terms "green" and "red" as that reminds me who's turn it is to move. "good" and "evil" sound more fun though
Also, consider "angel" and "demon".
----
Some actual code:
Code: Select all
Color GetGoodColor(void) const {return good;}
Color GetEvilColor(void) const {return evil;}
Sq GetKingSq(const Color color) const {return ksbc[color];}
Sq GetGoodKingSq(void) const {return GetKingSq(good);}
Sq GetEvilKingSq(void) const {return GetKingSq(evil);}
bool IsGKIC(void) const {return ColorAttacksSq(evil, GetGoodKingSq());}
bool IsEKIC(void) const {return ColorAttacksSq(good, GetEvilKingSq());}
Code: Select all
void Pos::Execute(PPD &ppd, const Move move)
{
ppd.PutPPDmove(move);
const bool notnull = move.IsNotNull();
const Sq frsq = move.GetFrSq(), tosq = move.GetToSq();
const Man frman = move.GetFrMan(), toman = move.GetToMan();
const Mc mc = move.GetMc();
*(FENScalars *) &ppd = *this;
ppd.PutPPDaphs(aphs); ppd.PutPPDpmbb(pmbb); ppd.PutPPDfmbb(fmbb); ppd.PutPPDinch(inch);
if (notnull)
{
switch (mc)
{
case McReg:
if (IsManNotVacant(toman)) DelMan(tosq, evil, toman);
MoveMan(frsq, tosq, good, frman);
break;
case McEPC:
DelMan((Sq) (tosq + CvColorToForwardDelta[evil]), evil, SynthMP[evil]);
MoveMan(frsq, tosq, good, frman);
break;
case McCKS: case McCQS:
{
const Castling castling = CvColorMcToCastling[good][mc];
MoveMan(frsq, tosq, good, frman);
MoveMan(
CvCastlingToRookHomeSq[castling], CvCastlingToRookAwaySq[castling],
good, SynthMR[good]);
};
break;
case McPPN: case McPPB: case McPPR: case McPPQ:
if (IsManNotVacant(toman)) DelMan(tosq, evil, toman);
DelMan(frsq, good, frman); AddMan(tosq, good, CvColorMcToMan[good][mc]);
break;
default:
BadSwitch("Pos::Execute");
break;
};
};
good = OtherColor(good); evil = OtherColor(evil);
if (notnull && (cabs != 0))
{
const ui newcabs = cabs & ~(CastlingCancellation[frsq] | CastlingCancellation[tosq]);
if (cabs != newcabs) {ApplyHashDeltaCastling(cabs, newcabs); cabs = newcabs;};
};
if (IsSqNotNil(epsq)) {ApplyHashDeltaEnPassant(epsq); epsq = SqNil;};
if (notnull && IsManPawn(frman) && ((tosq ^ frsq) == (FileLen * 2)) &&
(BB::HorzAdjSqBB[tosq] & locbm[CvManToOtherMan[frman]]).IsNotReset())
{
epsq = (Sq) ((frsq + tosq) >> 1); ApplyHashDeltaEnPassant(epsq);
};
if (notnull && (IsManPawn(frman) || IsManNotVacant(toman))) hmvc = 0; else hmvc++;
if (IsColorWhite(good)) fmvn++;
if (notnull) RegenPinBitboards();
inch = IsGKIC();
}
void Pos::Retract(const PPD &ppd)
{
const Move move = ppd.GetPPDmove();
if (cabs != ppd.GetFScabs()) ApplyHashDeltaCastling(cabs, ppd.GetFScabs());
if (IsSqNotNil(epsq)) ApplyHashDeltaEnPassant(epsq);
if (IsSqNotNil(ppd.GetFSepsq())) ApplyHashDeltaEnPassant(ppd.GetFSepsq());
*(FENScalars *) this = ppd;
pmbb = ppd.GetPPDpmbb(); fmbb = ppd.GetPPDfmbb(); inch = ppd.GetPPDinch();
if (move.IsNotNull())
{
const Sq frsq = move.GetFrSq(), tosq = move.GetToSq();
const Man frman = move.GetFrMan(), toman = move.GetToMan();
const Mc mc = move.GetMc();
switch (mc)
{
case McReg:
MoveMan(tosq, frsq, good, frman);
if (IsManNotVacant(toman)) AddMan(tosq, evil, toman);
break;
case McEPC:
MoveMan(tosq, frsq, good, frman);
AddMan((Sq) (tosq + CvColorToForwardDelta[evil]), evil, SynthMP[evil]);
break;
case McCKS: case McCQS:
{
const Castling castling = CvColorMcToCastling[good][mc];
MoveMan(
CvCastlingToRookAwaySq[castling], CvCastlingToRookHomeSq[castling],
good, SynthMR[good]);
MoveMan(tosq, frsq, good, frman);
};
break;
case McPPN: case McPPB: case McPPR: case McPPQ:
DelMan(tosq, good, CvColorMcToMan[good][mc]); AddMan(frsq, good, frman);
if (IsManNotVacant(toman)) AddMan(tosq, evil, toman);
break;
default:
BadSwitch("Pos::Retract");
break;
};
};
}