What world have I been in - castling notation?

Discussion of anything and everything relating to chess playing software and machines.

Moderators: hgm, Rebel, chrisw

User avatar
reflectionofpower
Posts: 1612
Joined: Fri Mar 01, 2013 5:28 pm
Location: USA

Re: What world have I been in - castling notation?

Post by reflectionofpower »

bob wrote:
syzygy wrote:
Norm Pollock wrote:PGN-Standards:
http://www.saremba.de/chessgml/standard ... mplete.htm


8.2.3.3: Basic SAN move construction

...

SAN kingside castling is indicated by the sequence "O-O"; queenside castling is indicated by the sequence "O-O-O". Note that the upper case letter "O" is used, not the digit zero. The use of a zero character is not only incompatible with traditional text practices, but it can also confuse parsing algorithms which also have to understand about move numbers and game termination markers.
It's not as if parsers can get away with ignore the "o-o" and (FIDE-suggested) "0-0" notations...
Also note that the use of the letter "O" is consistent with the practice of having all chess move symbols start with a letter; also, it follows the convention that all non-pwn move symbols start with an upper case letter.
Assuming FIDE was already clear about castling being 0-0 at the time this was written up, it is at least unfortunate that FIDE's choice was ignored.
I'd bet PGN pre-dates any fide spec. How can you tell if a hand-written score sheet uses 0's or O's or o's?
That's what I was thinking too. Imagine being in a FIDE sanctioned tournament and someone uses O instead of the official 0 and then you are disqualified from the $100,000 prize. :shock:
"Without change, something sleeps inside us, and seldom awakens. The sleeper must awaken." (Dune - 1984)

Lonnie
syzygy
Posts: 5569
Joined: Tue Feb 28, 2012 11:56 pm

Re: What world have I been in - castling notation?

Post by syzygy »

reflectionofpower wrote:
bob wrote:
syzygy wrote:Assuming FIDE was already clear about castling being 0-0 at the time this was written up, it is at least unfortunate that FIDE's choice was ignored.
I'd bet PGN pre-dates any fide spec. How can you tell if a hand-written score sheet uses 0's or O's or o's?
That's what I was thinking too. Imagine being in a FIDE sanctioned tournament and someone uses O instead of the official 0 and then you are disqualified from the $100,000 prize. :shock:
Clearly any sensible interpretation of the FIDE rules allows both o-o and O-O in addition to 0-0.

My point is that SAN specifically does NOT allow o-o and (FIDE-suggested) 0-0. It even goes through pains explaining why not.
User avatar
sje
Posts: 4675
Joined: Mon Mar 13, 2006 7:43 pm

FIDE? Ha ha ha

Post by sje »

At the time that the SAN specification was developed, many different sources of information concerning chess notation were consulted, and of course the FIDE Laws were included.

The FIDE information about notation was incomplete, inconsistent, and ambiguous back then, and it still is today.

In some places, the FIDE Laws use zero with castling and in others they use the uppercase letter ""O". Also, there was plenty of variance in move notion in texts published under the FIDE imprimatur. There were a half dozen different ways of recording en passant moves. One of FIDE's problems is they made a misguided attempt to please everyone when what they really needed was a tyrant who would provide a unique move/notation mapping.

If you're really interested, then you can dig through the FIDE Laws and look for the castling references: http://www.fide.com/fide/handbook.html? ... ew=article

Those were the rules in effect twenty years ago; there have been some changes in just the past couple of months. But even so, the FIDE Laws are incomplete and still do not cover the case of when both file letter and rank number of the origin square are needed to disambiguate some moves.

Believe me, I've been through all of this many times. There are good reasons why SAN is the way it is.

--------

Oscar's SAN generator code:

Code: Select all

static void SanRecLoadFromMove(SanRec * const sanrecptr, const Move move)
{
  // This routine loads the given SAN record using the given move.

  char *chptr = sanrecptr->chvec;
  const Mc mc = GetMc(move);
  const Man frman = GetFrMan(move);
  const Man toman = GetToMan(move);
  const Sq frsq = GetFrSq(move);
  const Sq tosq = GetToSq(move);

  SanRecReset(sanrecptr);
  
  // Process according to the move's special case
  
  switch (mc)
  {
    case McReg:  // Regular move; no special case
      if (IsManPawn(frman))
      {
        *chptr++ = MapSqToFileChar(frsq);
        if (IsManNotVacant(toman))
        {
          *chptr++ = 'x';
          *chptr++ = MapSqToFileChar(tosq);
        };
        *chptr++ = MapSqToRankChar(tosq);
      }
      else
      {
        *chptr++ = MapManToPieceChar(frman);
        if (TestMf(move, MfAndf))
          *chptr++ = MapSqToFileChar(frsq);
        if (TestMf(move, MfAndr))
          *chptr++ = MapSqToRankChar(frsq);
        if (IsManNotVacant(toman))
          *chptr++ = 'x';
        *chptr++ = MapSqToFileChar(tosq);
        *chptr++ = MapSqToRankChar(tosq);
      };
      break;

    case McEPC:  // En passant capture
      *chptr++ = MapSqToFileChar(frsq);
      *chptr++ = 'x';
      *chptr++ = MapSqToFileChar(tosq);
      *chptr++ = MapSqToRankChar(tosq);
     break;

    case McCQS:  // Castles queenside
      *chptr++ = 'O';
      *chptr++ = '-';
      *chptr++ = 'O';
      *chptr++ = '-';
      *chptr++ = 'O';
      break;

    case McCKS:  // Castles kingside
      *chptr++ = 'O';
      *chptr++ = '-';
      *chptr++ = 'O';
      break;

    case McPPN:  // Pawn promotes to knight
    case McPPB:  // Pawn promotes to bishop
    case McPPR:  // Pawn promotes to rook
    case McPPQ:  // Pawn promotes to queen
      *chptr++ = MapSqToFileChar(frsq);
      if (IsManNotVacant(toman))
      {
        *chptr++ = 'x';
        *chptr++ = MapSqToFileChar(tosq);
      };
      *chptr++ = MapSqToRankChar(tosq);
      *chptr++ = '=';
      *chptr++ = MapMcToPieceChar(mc);
      break;

    default:
      break;
  };

  // Check and checkmate
  
  if (TestMf(move, MfChck))
  {
    if (TestMf(move, MfMate))
      *chptr++ = '#';
    else
      *chptr++ = '+';
  };

  *chptr++ = '\0';
}
Oscar's disambiguation code:

Code: Select all

static void PositionNotateDisambiguation(const Position * const positionptr, const MoveSeg * const movesegptr)
{
  // This routine notates disambiguation of the moves in the given move segment for the given position.

  const Move * const baseptr = movesegptr->baseptr;
  const ui limit = movesegptr->count;
  ui index0;
  Sq tosq;
  Census census;
  ui landings[SqLen];

  CensusLoadFromBoard(&census, &positionptr->board);

  for &#40;tosq = SqA1; tosq <= SqH8; tosq++)
    landings&#91;tosq&#93; = 0;
  for &#40;index0 = 0; index0 < limit; index0++)
    landings&#91;GetToSq&#40;baseptr&#91;index0&#93;)&#93;++;

  for &#40;index0 = 0; index0 < limit; index0++)
  &#123;
    const Move move0 = baseptr&#91;index0&#93;;
    const Man frman0 = GetFrMan&#40;move0&#41;;
    const Sq tosq0 = GetToSq&#40;move0&#41;;

    if (&#40;landings&#91;tosq0&#93; > 1&#41; && IsManQRBN&#40;frman0&#41; && &#40;census.mancount&#91;frman0&#93; > 1&#41;)
    &#123;
      const Sq frsq0 = GetFrSq&#40;move0&#41;;
      const File frfile0 = MapSqToFile&#40;frsq0&#41;;
      const Rank frrank0 = MapSqToRank&#40;frsq0&#41;;
      ui index1;
      ui msc = 0, mfc = 0, mrc = 0;

      for &#40;index1 = 0; index1 < limit; index1++)
      &#123;
        const Move move1 = baseptr&#91;index1&#93;;
        const Sq frsq1 = GetFrSq&#40;move1&#41;;

        if (&#40;tosq0 == GetToSq&#40;move1&#41;) && &#40;frman0 == GetFrMan&#40;move1&#41;) && &#40;frsq0 != frsq1&#41;)
        &#123;
          msc++;
          if &#40;MapSqToFile&#40;frsq1&#41; == frfile0&#41;
            mfc++;
          if &#40;MapSqToRank&#40;frsq1&#41; == frrank0&#41;
            mrc++;
        &#125;;
      &#125;;

      if &#40;msc > 0&#41;
      &#123;
        if (&#40;mfc == 0&#41; || &#40;mrc > 0&#41;)
          SetMf&#40;movesegptr->baseptr&#91;index0&#93;, MfAndf&#41;;
        if &#40;mfc > 0&#41;
          SetMf&#40;movesegptr->baseptr&#91;index0&#93;, MfAndr&#41;;
      &#125;;
    &#125;;
  &#125;;
&#125;
User avatar
reflectionofpower
Posts: 1612
Joined: Fri Mar 01, 2013 5:28 pm
Location: USA

Re: FIDE? Ha ha ha

Post by reflectionofpower »

sje wrote:At the time that the SAN specification was developed, many different sources of information concerning chess notation were consulted, and of course the FIDE Laws were included.

The FIDE information about notation was incomplete, inconsistent, and ambiguous back then, and it still is today.

};
}[/code]
I believe you. FIDE is still incomplete,inconsistent. Kasparov would have made a much better representative.
"Without change, something sleeps inside us, and seldom awakens. The sleeper must awaken." (Dune - 1984)

Lonnie
syzygy
Posts: 5569
Joined: Tue Feb 28, 2012 11:56 pm

Re: FIDE? Ha ha ha

Post by syzygy »

sje wrote:If you're really interested, then you can dig through the FIDE Laws and look for the castling references: http://www.fide.com/fide/handbook.html? ... ew=article
They say 0-0 and 0-0-0.
Believe me, I've been through all of this many times. There are good reasons why SAN is the way it is.
But you do agree that a move parser cannot get away with refusing to accept o-o and 0-0, right?

OK, I just noticed:
Import format is somewhat more relaxed and it makes allowances for moves that do not conform exactly to the canonical format. However, these allowances may differ among different PGN reader programs.
User avatar
sje
Posts: 4675
Joined: Mon Mar 13, 2006 7:43 pm

Re: FIDE? Ha ha ha

Post by sje »

syzygy wrote:
sje wrote:If you're really interested, then you can dig through the FIDE Laws and look for the castling references: http://www.fide.com/fide/handbook.html? ... ew=article
They say 0-0 and 0-0-0.
Believe me, I've been through all of this many times. There are good reasons why SAN is the way it is.
But you do agree that a move parser cannot get away with refusing to accept o-o and 0-0, right?
You missed some of the FIDE castling references; try again.

A parser has no responsibility to accept anything other than what the standard says it should accept.
syzygy
Posts: 5569
Joined: Tue Feb 28, 2012 11:56 pm

Re: FIDE? Ha ha ha

Post by syzygy »

sje wrote:A parser has no responsibility to accept anything other than what the standard says it should accept.
Sure!

And so much for real-world usability.
bob
Posts: 20943
Joined: Mon Feb 27, 2006 7:30 pm
Location: Birmingham, AL

Re: What world have I been in - castling notation?

Post by bob »

syzygy wrote:
reflectionofpower wrote:
bob wrote:
syzygy wrote:Assuming FIDE was already clear about castling being 0-0 at the time this was written up, it is at least unfortunate that FIDE's choice was ignored.
I'd bet PGN pre-dates any fide spec. How can you tell if a hand-written score sheet uses 0's or O's or o's?
That's what I was thinking too. Imagine being in a FIDE sanctioned tournament and someone uses O instead of the official 0 and then you are disqualified from the $100,000 prize. :shock:
Clearly any sensible interpretation of the FIDE rules allows both o-o and O-O in addition to 0-0.

My point is that SAN specifically does NOT allow o-o and (FIDE-suggested) 0-0. It even goes through pains explaining why not.
There is two parts to this issue. The standard should be specific and precise. That's true for any specification as is taught in any software engineering course. Whether you choose to be draconian or relaxed when you actually parse moves is a completely separate issue.

My take is that people should follow the standard, but one should always realize that there are idiots that won't follow the standard and one should do whatever practical to make up for any deficiencies found, when possible, and then encourage the idiot to fix his stuff to actually comply with the standard.

Most seem to get the ranks, files and pieces right. But zero vs oh, and then en passant captures promotions are the next hurdle. And some can't even figure out where spaces are appropriate.
syzygy
Posts: 5569
Joined: Tue Feb 28, 2012 11:56 pm

Re: What world have I been in - castling notation?

Post by syzygy »

bob wrote:There is two parts to this issue. The standard should be specific and precise. That's true for any specification as is taught in any software engineering course.
The standard could precisely specify that a parser shall be able to deal with 0-0, o-o and O-O...
mvk
Posts: 589
Joined: Tue Jun 04, 2013 10:15 pm

Re: What world have I been in - castling notation?

Post by mvk »

reflectionofpower wrote:Imagine being in a FIDE sanctioned tournament and someone uses O instead of the official 0 and then you are disqualified from the $100,000 prize. :shock:
In that case you get the $1OO,OOO prize.
[Account deleted]