Glaurung for the iPhone: Source code available

Discussion of chess software programming and technical issues.

Moderators: hgm, Harvey Williamson, bob

Forum rules
This textbox is used to restore diagrams posted with the [d] tag before the upgrade.
Post Reply
Tord Romstad
Posts: 1808
Joined: Wed Mar 08, 2006 8:19 pm
Location: Oslo, Norway

Glaurung for the iPhone: Source code available

Post by Tord Romstad » Sun Mar 01, 2009 1:39 pm

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

User avatar
sje
Posts: 4675
Joined: Mon Mar 13, 2006 6:43 pm

Re: Glaurung for the iPhone: Source code available

Post by sje » Sun Mar 01, 2009 2:07 pm

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".

gladius
Posts: 537
Joined: Tue Dec 12, 2006 9:10 am

Re: Glaurung for the iPhone: Source code available

Post by gladius » Mon Mar 02, 2009 9:21 pm

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 :).

User avatar
sje
Posts: 4675
Joined: Mon Mar 13, 2006 6:43 pm

Re: Glaurung for the iPhone: Source code available

Post by sje » Mon Mar 02, 2009 10:01 pm

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".

steffan
Posts: 28
Joined: Sat Mar 11, 2006 11:08 pm
Location: Midlands, England

Re: Glaurung for the iPhone: Source code available

Post by steffan » Mon Mar 02, 2009 11:10 pm

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

User avatar
sje
Posts: 4675
Joined: Mon Mar 13, 2006 6:43 pm

Re: Glaurung for the iPhone: Source code available

Post by sje » Tue Mar 03, 2009 12:58 am

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;
    };
  };
}

Post Reply