Page 1 of 1

Glaurung for the iPhone: Source code available

Posted: Sun Mar 01, 2009 2:39 pm
by Tord Romstad
Hi all,

The source code for the iPhone/iPod Touch version of Glaurung has until now only been available on an on-demand basis; I have now finally uploaded it to my web site:

http://www.glaurungchess.com/iphone-src.tar.gz

This is the source code for version 1.0.1, which hasn't appeared on the App Store yet (I'm waiting for Apple to approve it). Abaia, the version for jailbroken devices, will be updated to 1.0.1 later today. Compared to the 1.0 version available from the App Store, the following changes have been made:
  • Numerous bug fixes and stability improvements. In particular, the app should no longer freeze at startup.
  • Figurine notation (optional).
  • Minor adjustments to board colors.
The engine source code is quite close to Glaurung 2.2, with a few minor bug fixes and customizations for the slow ARM CPU. The GUI source code is an awful mess.

Tord

Re: Glaurung for the iPhone: Source code available

Posted: Sun Mar 01, 2009 3:07 pm
by sje
Thank you for making the source available.

I note with interest your usage of the variable names "us" and "them" in the source for representing the active and passive colors. In my code, I've always used "actc" and "pasc" respectively. But now I've been inspired by Glaurung and just might change the identifiers to "good" and "evil".

Re: Glaurung for the iPhone: Source code available

Posted: Mon Mar 02, 2009 10:21 pm
by gladius
sje wrote:I note with interest your usage of the variable names "us" and "them" in the source for representing the active and passive colors. In my code, I've always used "actc" and "pasc" respectively. But now I've been inspired by Glaurung and just might change the identifiers to "good" and "evil".
I've always preferred the poker terms, "hero" and "villian" myself :).

Re: Glaurung for the iPhone: Source code available

Posted: Mon Mar 02, 2009 11:01 pm
by sje
gladius wrote:
sje wrote:I note with interest your usage of the variable names "us" and "them" in the source for representing the active and passive colors. In my code, I've always used "actc" and "pasc" respectively. But now I've been inspired by Glaurung and just might change the identifiers to "good" and "evil".
I've always preferred the poker terms, "hero" and "villian" myself :).
And from Dungeons and Dragons we have the alignment terms "lawful" and "chaotic".

Re: Glaurung for the iPhone: Source code available

Posted: Tue Mar 03, 2009 12:10 am
by steffan
sje wrote:Thank you for making the source available.

I note with interest your usage of the variable names "us" and "them" in the source for representing the active and passive colors. In my code, I've always used "actc" and "pasc" respectively. But now I've been inspired by Glaurung and just might change the identifiers to "good" and "evil".
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 :)

Cheers,
Steffan

Re: Glaurung for the iPhone: Source code available

Posted: Tue Mar 03, 2009 1:58 am
by sje
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;
    };
  };
}