%%
%% This is file `xskak-keys.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% xskak.dtx  (with options: `xskak-keys')
%% 
%% xskak: a package to parse and print chess games
%% Copyright 2006-2015 Ulrike Fischer (chess@nililand.de)
%% -------------------------------------------
%% 
%% This file can be redistributed and/or modified under the terms of
%% the LaTeX Project Public License distributed from CTAN archives in
%% the directory macros/latex/base/lppl.txt; either version 1 of the
%% License, or (at your option) any later version.
%% 
%% For error reports see documentation.
\ProvidesFile{xskak-keys.sty}[2019/06/23 version v1.5 key definitions for xskak.sty]

%%%%%%%%%%%%%%%%%%%%%
%%%% Keys
%%%%%%%%%%%%%%%%%%%%%
%% \newchessgame: fam: new
\define@key[UFXS]{new}{id}[\xskak@val@defaultid]{\xdef\xskak@val@gameid{#1}}

\define@key[UFXS]{new}{movenr}{\xdef\xskak@val@movenr{#1}}

\define@key[UFXS]{new}{player}{\xdef\xskak@val@player{#1}}

\define@key[UFXS]{new}{moveid}[\xskak@val@defaultmovenr\xskak@val@defaultplayer]{%
 \edef\@tempa{#1}%
 \xskak@split@moveid{\@tempa}%
 \global\let\xskak@val@movenr\xskak@temp@movenr
 \global\let\xskak@val@player\xskak@temp@player}

\define@key[UFXS]{new}{newvar}[\xskak@val@gameid]{%
 \xdef\xskak@val@refgameid{#1}%
 \xdef\xskak@val@movenr{\csname Xskak#1lastmovenr\endcsname}%
 \xdef\xskak@val@player{\csname Xskak#1lastplayer\endcsname}}%

\define@key[UFXS]{new}{reftag}{%
 \xdef\xskak@val@currenttag{#1}}

\define@key[UFXS]{new}{refid}{%
 \ifcsname xskak@tag@#1@refid\endcsname
  \UFXS@new@id{\csname xskak@tag@#1@refid\endcsname}%
 \else
   \PackageError{xskak}{Unknown tag #1}{}%
 \fi}

\define@key[UFXS]{new}{refpastmovenr}{%
 \ifcsname xskak@tag@#1@refid\endcsname
  \UFXS@new@movenr{\csname xskak@tag@#1@refpastmovenr\endcsname}%
 \else
   \PackageError{xskak}{Unknown tag #1}{}%
 \fi}

\define@key[UFXS]{new}{refnextmovenr}{%
 \ifcsname xskak@tag@#1@refid\endcsname
  \UFXS@new@movenr{\csname xskak@tag@#1@refnextmovenr\endcsname}%
 \else
   \PackageError{xskak}{Unknown tag #1}{}%
 \fi}

\define@key[UFXS]{new}{refpastplayer}{%
 \ifcsname xskak@tag@#1@refid\endcsname
  \UFXS@new@movenr{\csname xskak@tag@#1@refpastmovenr\endcsname}%
 \else
   \PackageError{xskak}{Unknown tag #1}{}%
 \fi}

\define@key[UFXS]{new}{refnextplayer}{%
 \ifcsname xskak@tag@#1@refid\endcsname
  \UFXS@new@player{\csname xskak@tag@#1@refnextplayer\endcsname}%
 \else
   \PackageError{xskak}{Unknown tag #1}{}%
 \fi}

\define@key[UFXS]{new}{refpastmoveid}{%
  \ifcsname xskak@tag@#1@refid\endcsname
   \UFXS@new@moveid{%
    \csname xskak@tag@#1@refpastmovenr\endcsname
    \csname xskak@tag@#1@refpastplayer\endcsname}%
  \else
   \PackageError{xskak}{Unknown tag #1}{}%
 \fi}

\define@key[UFXS]{new}{refnextmoveid}{%
 \ifcsname xskak@tag@#1@refid\endcsname
   \PackageError{xskak}{Unknown tag #1}{}%
 \fi
 \UFXS@new@moveid{%
  \csname xskak@tag@#1@refnextmovenr\endcsname
  \csname xskak@tag@#1@refnextplayer\endcsname}}

\define@key[UFXS]{new}{refpast}{%
 \ifcsname xskak@tag@#1@refid\endcsname
   \PackageError{xskak}{Unknown tag #1}{}%
 \fi
 \UFXS@new@refpastmoveid{#1}%
 \UFXS@new@refid{#1}}

\define@key[UFXS]{new}{refnext}{%
 \ifcsname xskak@tag@#1@refid\endcsname
  \UFXS@new@refnextmoveid{#1}%
  \UFXS@new@refid{#1}%
 \else
   \PackageError{xskak}{Unknown tag #1}{}%
 \fi}

%% \xskakset: fam set
\define@key[UFXS]{set}{id}[\xskak@val@defaultid]{\UFXS@new@id{#1}}

\define@key[UFXS]{set}{movenr}{\UFXS@new@moveid{#1}}

\define@key[UFXS]{set}{player}{\UFXS@new@player{#1}}

\define@key[UFXS]{set}{moveid}[\xskak@val@defaultmovenr\xskak@val@defaultplayer]{%
 \UFXS@new@moveid{#1}}%

\define@key[UFXS]{set}{stepmoveid}[1]{%
  \count@=#1\relax
   \ifthenelse{\the\count@>0}
     {\whiledo{\the\count@>0}%
       {\xskak@do@getnextmoveid{\xskak@val@movenr}{\xskak@val@player}%
        \advance\count@ by -1%
        \global\let\xskak@val@movenr\xskak@temp@movenr
        \global\let\xskak@val@player\xskak@temp@player}%
     }%
     {\ifthenelse{\the\count@=0}%
       {}%
       {\whiledo{\the\count@<0}%
        {\xskak@do@getpreviousmoveid{\xskak@val@movenr}{\xskak@val@player}%
         \advance\count@ by 1%
         \global\let\xskak@val@movenr\xskak@temp@movenr
         \global\let\xskak@val@player\xskak@temp@player}%
         \ifthenelse{\the\count@<1}%
          {\PackageWarning{xskak}{Move number below 1!}{}}%
          {}}}}

\define@key[UFXS]{set}{lastmoveid}[\xskak@val@gameid]{%
  \ifcsname Xskak#1initfen\endcsname
   \xdef\xskak@val@gameid{#1}%
  \else\PackageError{xskak}{Game with the id #1 doesn't exist.}{}%
  \fi
  \xdef\xskak@val@movenr{\csname Xskak\xskak@val@gameid lastmovenr\endcsname}%
  \xdef\xskak@val@player{\csname Xskak\xskak@val@gameid lastplayer\endcsname}}%

\define@key[UFXS]{set}{defaultmoveid}{%
 \edef\@tempa{#1}\xskak@split@moveid{\@tempa}%
 %\xdef\xskak@val@movedefaultid{#1}%
 \xdef\xskak@val@defaultmovenr{\xskak@temp@movenr}%
 \xdef\xskak@val@defaultplayer{\xskak@temp@player}}

\define@key[UFXS]{set}{defaultmovenr}{%
 \xdef\xskak@val@defaultmovenr{#1}}

\define@key[UFXS]{set}{defaultplayer}{%
 \xdef\xskak@val@defaultplayer{#1}}

\define@key[UFXS]{set}{defaultid}{\gdef\xskak@val@defaultid{#1}}

\define@key[UFXS]{set}{defaultfen}{\gdef\xskak@val@defaultfen{#1}}

\define@key[UFXS]{set}{tag}{%
 \ifcsname xskak@tag@#1@refid\endcsname
   \PackageWarning{xskak}{Overwrite tag name #1}{}%
 \fi
 \expandafter\xdef
  \csname xskak@tag@#1@refid\endcsname{\xskak@val@gameid}%
 \ifnum\the\c@move=0
   \PackageWarning{xskak}{You haven't started a game yet. I won't set a tag!}{}%
 \else
  \expandafter\xdef
   \csname xskak@tag@#1@refnextmovenr\endcsname{\the\c@move}%
  \expandafter\xdef
   \csname xskak@tag@#1@refnextplayer\endcsname{\WhiteToMove{w}{b}}%
  \expandafter\xdef
   \csname xskak@tag@#1@refpastplayer\endcsname{\WhiteToMove{b}{w}}%
  \expandafter\xdef
   \csname xskak@tag@#1@refnextmoveid\endcsname{\the\c@move\WhiteToMove{w}{b}}%
  \WhiteToMove
   {\expandafter\xdef
    \csname xskak@tag@#1@refpastmovenr\endcsname{\the\numexpr\the\c@move-1\relax}}
   {\expandafter\xdef
    \csname xskak@tag@#1@refpastmovenr\endcsname{\the\c@move}}
  \expandafter\xdef
   \csname xskak@tag@#1@refpastmoveid\endcsname{%
   \csname xskak@tag@#1@refpastmovenr\endcsname
   \csname xskak@tag@#1@refpastplayer\endcsname}%
 \fi
  }

\define@key[UFXS]{set}{reftag}{%
 \UFXS@new@reftag{#1}}

\define@key[UFXS]{set}{refid}{%
 \UFXS@new@refid{#1}}

\define@key[UFXS]{set}{refpastmovenr}{%
 \UFXS@new@refpastmovenr{#1}}

\define@key[UFXS]{set}{refnextmovenr}{%
 \UFXS@new@refnextmovenr{#1}}

\define@key[UFXS]{set}{refpastplayer}{%
  \UFXS@new@refpastplayer{#1}}

\define@key[UFXS]{set}{refnextplayer}{%
  \UFXS@new@refnextplayer{#1}}

\define@key[UFXS]{set}{refpastmoveid}{%
   \UFXS@new@refpastmoveid{#1}}

\define@key[UFXS]{set}{refnextmoveid}{%
  \UFXS@new@refnextmoveid{#1}}

\define@key[UFXS]{set}{refpast}{%
  \UFXS@new@refpast{#1}}

\define@key[UFXS]{set}{refnext}{%
  \UFXS@new@refnext{#1}}

\define@key[UFXS]{set}{style}{%
 \ifcsname xskak@style@#1@1@item\endcsname
  \def\xskak@val@stylename{#1}%
  \def\mainlinestyle{%
   \xskak@use@varstyle{\xskak@val@curlevel}%
   \xskak@do@splitlevel{\xskak@val@curlevel}%
   \ifnum\xskak@temp@levelnumber=0\relax
   \else
    \csname xskak@style@#1@\xskak@temp@levelnumber @xfont\endcsname
   \fi
   \csname xskak@style@#1@\xskak@val@curlevel @font\endcsname}%
  \let\variationstyle\mainlinestyle
 \else
  \PackageError{xskak}{Style #1 doesn't exist!}{}
 \fi}

\define@key[UFXS]{set}{gstyle}{%
 \ifcsname xskak@style@#1@1@item\endcsname
  \xdef\xskak@val@stylename{#1}%
  \gdef\mainlinestyle{%
   \xskak@use@varstyle{\xskak@val@curlevel}%
   \xskak@do@splitlevel{\xskak@val@curlevel}%
   \ifnum\xskak@temp@levelnumber=0\relax
   \else
    \csname xskak@style@#1@\xskak@temp@levelnumber @xfont\endcsname
   \fi
   \csname xskak@style@#1@\xskak@val@curlevel @font\endcsname}%
  \global\let\variationstyle\mainlinestyle
 \else
  \PackageError{xskak}{Style #1 doesn't exist!}{}
 \fi}

\define@key[UFXS]{set}{level}{%
 \edef\xskak@val@curlevel{#1}}%

\define@key[UFXS]{set}{glevel}{%
 \xdef\xskak@val@curlevel{#1}}%

\define@key[UFXS]{set}{invar}[]{%
 \ifxskakpdfmatch
  \xskak@do@splitlevel{\xskak@val@curlevel}%
  \ifnum\xskak@temp@levelnumber=0\relax
   \PackageWarning{xskak}{key invar ignored}{}%
  \else
   \edef\xskak@val@curlevel{%
          \xskak@temp@levelprefix
          \the\numexpr\xskak@temp@levelnumber+1\relax
          \xskak@temp@levelpostfix}%
  \fi
 \else
 %% no pdfmatch. Will give an error if the level is not a number
   \edef\xskak@val@curlevel{%
          \the\numexpr\xskak@val@curlevel+1\relax}%
 \fi}

\define@key[UFXS]{set}{ginvar}[]{%
 \ifxskakpdfmatch
  \xskak@do@splitlevel{\xskak@val@curlevel}%
  \ifnum\xskak@temp@levelnumber=0\relax
   \PackageWarning{xskak}{key ginvar ignored}{}%
  \else
   \xdef\xskak@val@curlevel{%
          \xskak@temp@levelprefix
          \the\numexpr\xskak@temp@levelnumber+1\relax
          \xskak@temp@levelpostfix}%
  \fi
 \else
 %% no pdfmatch. Will give an error if the level is not a number
   \xdef\xskak@val@curlevel{%
          \the\numexpr\xskak@val@curlevel+1\relax}%
 \fi}

\define@key[UFXS]{set}{outvar}[]{%
 \ifxskakpdfmatch
  \xskak@do@splitlevel{\xskak@val@curlevel}%
   \ifnum\xskak@temp@levelnumber=0\relax
    \PackageWarning{xskak}{key outvar ignored}{}%
   \else
     \ifnum\xskak@temp@levelnumber=1\relax
      \PackageWarning{xskak}{Level has already  value 1}{}%
     \else
       \edef\xskak@val@curlevel{%
          \xskak@temp@levelprefix
          \the\numexpr\xskak@temp@levelnumber-1\relax
          \xskak@temp@levelpostfix}%
     \fi
  \fi
 \else
   \ifnum\xskak@val@curlevel=1\relax
     \PackageWarning{xskak}{Level has already  value 1}{}%
   \else
     \edef\xskak@val@curlevel{%
          \the\numexpr\xskak@val@curlevel-1}%
   \fi
 \fi}

\define@key[UFXS]{set}{goutvar}[]{%
 \ifxskakpdfmatch
  \xskak@do@splitlevel{\xskak@val@curlevel}%
   \ifnum\xskak@temp@levelnumber=0\relax
    \PackageWarning{xskak}{key goutvar ignored}{}%
   \else
     \ifnum\xskak@temp@levelnumber=1\relax
      \PackageWarning{xskak}{Level has already  value 1}{}%
     \else
       \xdef\xskak@val@curlevel{%
          \xskak@temp@levelprefix
          \the\numexpr\xskak@temp@levelnumber-1\relax
          \xskak@temp@levelpostfix}%
     \fi
  \fi
 \else
   \ifnum\xskak@val@curlevel=1\relax
     \PackageWarning{xskak}{Level has already  value 1}{}%
   \else
     \xdef\xskak@val@curlevel{%
          \the\numexpr\xskak@val@curlevel-1}%
   \fi
 \fi}

%% \resumechessgame: fam res
\define@key[UFXS]{res}{id}{\UFXS@new@id{#1}}

\define@key[UFXS]{res}{movenr}{\def\xskak@temp@movenr{#1}}

\define@key[UFXS]{res}{player}{\def\xskak@temp@player{#1}}

\define@key[UFXS]{res}{moveid}{\edef\@tempa{#1}\xskak@split@moveid{\@tempa}}

\define@key[UFXS]{res}{newvar}[\xskak@val@gameid]{%
 \xdef\xskak@val@refgameid{#1}%
 \xdef\xskak@val@gameid{#1}%
 \def\xskak@temp@movenr{\csname Xskak\xskak@val@gameid lastmovenr\endcsname}%
 \def\xskak@temp@player{\csname Xskak\xskak@val@gameid lastplayer\endcsname}}%

\define@key[UFXS]{res}{reftag}{%
 \UFXS@new@reftag{#1}}

\define@key[UFXS]{res}{refid}{%
 \UFXS@new@refid{#1}}

\define@key[UFXS]{res}{refpastmovenr}{%
 \UFXS@new@refpastmovenr{#1}}

\define@key[UFXS]{res}{refnextmovenr}{%
 \UFXS@new@refnextmovenr{#1}}

\define@key[UFXS]{res}{refpastplayer}{%
  \UFXS@new@refpastplayer{#1}}

\define@key[UFXS]{res}{refnextplayer}{%
  \UFXS@new@refnextplayer{#1}}

\define@key[UFXS]{res}{refpastmoveid}{%
   \UFXS@new@refpastmoveid{#1}}

\define@key[UFXS]{res}{refnextmoveid}{%
  \UFXS@new@refnextmoveid{#1}}

\define@key[UFXS]{res}{refpast}{%
  \UFXS@new@refpast{#1}}

\define@key[UFXS]{res}{refnext}{%
  \UFXS@new@refnext{#1}}

%% pgn-keys are defined during definition.

%%% xskakexportgames
\define@key[UFXS]{export}{file}{\edef\xskak@val@exportfile{#1.xsk}}
\define@key[UFXS]{export}{games}{\edef\xskak@val@exportgames{#1}}

%%% xskakloop
\define@key[UFXS]{loop}{id}{\UFXS@new@id{#1}}

\define@key[UFXS]{loop}{reftag}{%
 \UFXS@new@reftag{#1}}

\define@key[UFXS]{loop}{refid}{%
 \UFXS@new@refid{#1}}

\define@key[UFXS]{loop}{initmoveid}{%
 \xskak@split@moveid{#1}%
 \global\let\xskak@val@movenr\xskak@temp@movenr
 \global\let\xskak@val@player\xskak@temp@player
 }
\define@key[UFXS]{loop}{initmovenr}{%
 \xdef\xskak@val@movenr{#1}}

\define@key[UFXS]{loop}{initplayer}{%
 \xdef\xskak@val@player{#1}}

\define@key[UFXS]{loop}{stopmoveid}{%
 \xskak@split@moveid{#1}%
 \global\let\xskak@val@stopmovenr\xskak@temp@movenr
 \global\let\xskak@val@stopplayer\xskak@temp@player
 }
\define@key[UFXS]{loop}{stopmovenr}{%
 \xdef\xskak@val@stopmovenr{#1}}

\define@key[UFXS]{loop}{stopplayer}{%
 \xdef\xskak@val@stopplayer{#1}}

\define@key[UFXS]{loop}{step}{\xdef\xskak@val@loopstep{#1}}

\define@boolkey[UFXS]{loop}{showlast}[true]{}

%%
%% style items.

%% keys
\define@key[UFXS]{styleitem}{whiteopen}{%
 \expandafter\gdef\csname\xskak@temp@name whiteopen\endcsname{#1}}
\define@key[UFXS]{styleitem}{blackopen}{%
 \expandafter\gdef\csname\xskak@temp@name blackopen\endcsname{#1}}
\define@key[UFXS]{styleitem}{opencommands}{%
 \expandafter\gdef\csname\xskak@temp@name opencommands\endcsname{#1}}
\define@key[UFXS]{styleitem}{closecommands}{%
 \expandafter\gdef\csname\xskak@temp@name closecommands\endcsname{#1}}
\define@key[UFXS]{styleitem}{beforenumber}{%
 \expandafter\gdef\csname\xskak@temp@name beforenumber\endcsname{#1}}
\define@key[UFXS]{styleitem}{beforewhite}{%
 \expandafter\gdef\csname\xskak@temp@name beforewhite\endcsname{#1}}
\define@key[UFXS]{styleitem}{afterwhite}{%
 \expandafter\gdef\csname\xskak@temp@name afterwhite\endcsname{#1}}
\define@key[UFXS]{styleitem}{beforeblack}{%
 \expandafter\gdef\csname\xskak@temp@name beforeblack\endcsname{#1}}
\define@key[UFXS]{styleitem}{afterblack}{%
 \expandafter\gdef\csname\xskak@temp@name afterblack\endcsname{#1}}
\define@key[UFXS]{styleitem}{beforecomment}{%
 \expandafter\gdef\csname\xskak@temp@name xskak@beforecomment\endcsname{#1}}
\define@key[UFXS]{styleitem}{beforeNAG}{%
 \expandafter\gdef\csname\xskak@temp@name xskak@beforeNAG\endcsname{#1}}

\define@key[UFXS]{styleiteminit}{template}{% from #1 to current style. Make sure to have set temp@name correctly!
 \xskak@do@copystyleitem{xskak@styleitem@#1@}{\xskak@temp@name}}

%% style

\define@key[UFXS]{style}{level}[1]{%
  \def\xskak@val@curlevel{#1}}

\define@key[UFXS]{style}{font}{%
 \expandafter\gdef\csname\xskak@temp@name\xskak@val@curlevel @font\endcsname{#1}}

\define@key[UFXS]{style}{styleitem}{%
 \ifcsname xskak@styleitem@#1@whiteopen\endcsname
  \expandafter\xdef
   \csname\xskak@temp@name\xskak@val@curlevel @item\endcsname{#1}%
 \else
  \PackageError{xskak}{style item #1 doesn't exist!}{}%
 \fi}

\define@key[UFXS]{style}{xfont}{%
 \xskak@do@splitlevel{\xskak@val@curlevel}%
 \ifnum\xskak@temp@levelnumber=0\relax
  \PackageWarning{xskak}{key xfont ignored (no number found)}{}%
 \else
  \expandafter\gdef\csname\xskak@temp@name\xskak@temp@levelnumber @xfont\endcsname{#1}%
 \fi}

%% printing
%% style and level for all printing commands

\define@key[UFXS]{print}{style}{%
 \UFXS@set@style{#1}}

\define@key[UFXS]{print}{gstyle}{%
 \UFXS@set@gstyle{#1}}

\define@key[UFXS]{print}{level}{%
 \edef\xskak@val@curlevel{#1}}%

\define@key[UFXS]{print}{glevel}{%
 \xdef\xskak@val@curlevel{#1}}%

\define@key[UFXS]{print}{invar}[]{%
  \UFXS@set@invar{#1}}

\define@key[UFXS]{print}{outvar}[]{%
 \UFXS@set@outvar{#1}}

%% keys only for \printchessgame
\define@key[UFXS]{xprint}{id}{\def\xskak@val@gameid{#1}}
\define@key[UFXS]{xprint}{initmoveid}{%
 \xskak@split@moveid{#1}%
 \let\xskak@val@movenr\xskak@temp@movenr
 \let\xskak@val@player\xskak@temp@player
 }
\define@key[UFXS]{xprint}{initmovenr}{%
 \def\xskak@val@movenr{#1}}

\define@key[UFXS]{xprint}{initplayer}{%
 \def\xskak@val@player{#1}}

\define@key[UFXS]{xprint}{stopmoveid}{%
 \xskak@split@moveid{#1}%
 \let\xskak@val@stopmovenr\xskak@temp@movenr
 \let\xskak@val@stopplayer\xskak@temp@player
 }
\define@key[UFXS]{xprint}{stopmovenr}{%
 \def\xskak@val@stopmovenr{#1}}

\define@key[UFXS]{xprint}{stopplayer}{%
 \def\xskak@val@stopplayer{#1}}

\define@key[UFXS]{xprint}{reftag}{%
 \UFXS@new@reftag{#1}}

\define@key[UFXS]{xprint}{refid}{%
 \ifcsname xskak@tag@#1@refid\endcsname
  \UFXS@print@id{\csname xskak@tag@#1@refid\endcsname}%
 \else
   \PackageError{xskak}{Unknown tag #1}{}%
 \fi}

%% new keys for chessboard. Move to chessboard.sty??
%% empty keys to avoid errors:

\define@key[UFCB]{locfill}{tag}{}%
\define@key[UFCB]{locfill}{ref}{}%
\define@key[UFCB]{locfill}{defaultid}{}%
\define@key[UFCB]{locfill}{defaultmoveid}{}%
\define@key[UFCB]{locfill}{defaultfen}{}%

%% real keys (should also be defined in fam glofill):
\define@key[UFCB]{locfill}{id}[\xskak@val@defaultid]{%
 \ifcsname Xskak#1initfen\endcsname
   \edef\xskak@val@gameid{#1}%
 \else
  \PackageError{xskak}{Game with the id #1 doesn't exist.}{}%
 \fi}%

\define@key[UFCB]{glofill}{id}[\xskak@val@defaultid]{%
    \board@do@l@addto@macro\board@val@savedkeylist{,id=#1}}%

\define@key[UFCB]{locfill}{moveid}{%
 \edef\@tempa{#1}\xskak@split@moveid{\@tempa}%
 \let\xskak@val@movenr\xskak@temp@movenr
 \let\xskak@val@player\xskak@temp@player}%

\define@key[UFCB]{glofill}{moveid}{%
    \board@do@l@addto@macro\board@val@savedkeylist{,moveid=#1}}%

\define@key[UFCB]{locfill}{stepmoveid}[1]{%
  \count@=#1\relax
   \ifthenelse{\the\count@>0}
     {\whiledo{\the\count@>0}%
       {\xskak@do@getnextmoveid{\xskak@val@movenr}{\xskak@val@player}%
        \advance\count@ by -1%
        \let\xskak@val@movenr\xskak@temp@movenr
        \let\xskak@val@player\xskak@temp@player}%
     }%
     {\ifthenelse{\the\count@=0}%
       {}%
       {\whiledo{\the\count@<0}%
        {\xskak@do@getpreviousmoveid{\xskak@val@movenr}{\xskak@val@player}%
         \advance\count@ by 1%
         \let\xskak@val@movenr\xskak@temp@movenr
         \let\xskak@val@player\xskak@temp@player}%
         \ifthenelse{\the\count@<1}%
          {\PackageWarning{xskak}{Move number below 1!}{}}%
          {}}}}

\define@key[UFCB]{glofill}{stepmoveid}{%
    \board@do@l@addto@macro\board@val@savedkeylist{,stepmoveid=#1}}%

\define@key[UFCB]{locfill}{player}{\def\xskak@val@player{#1}}%

\define@key[UFCB]{glofill}{player}{%
    \board@do@l@addto@macro\board@val@savedkeylist{,player=#1}}%

\define@key[UFCB]{locfill}{movenr}{\def\xskak@val@movenr{#1}}%

\define@key[UFCB]{glofill}{movenr}{%
    \board@do@l@addto@macro\board@val@savedkeylist{,movenr=#1}}%

\define@key[UFCB]{locfill}{newvar}[\xskak@val@refgameid]{%
 \UFCB@locfill@setfen{%
  \csname Xskak.#1.%
    \csname Xskak#1lastmovenr\endcsname.%
    \csname Xskak#1lastplayer\endcsname.%
    pastfen\endcsname}%
 }%

\define@key[UFCB]{glofill}{newvar}{%
    \board@do@l@addto@macro\board@val@savedkeylist{,newvar=#1}}%

\define@key[UFCB]{locfill}{reftag}{%
 \edef\xskak@val@currenttag{#1}}

\define@key[UFCB]{glofill}{reftag}{%
    \board@do@l@addto@macro\board@val@savedkeylist{,reftag=#1}}%

\define@key[UFCB]{locfill}{lastmoveid}[\xskak@val@gameid]{%
 \ifcsname Xskak#1initfen\endcsname
  \edef\xskak@val@gameid{#1}%
 \else
  \PackageError{xskak}{Game with the id #1 doesn't exist.}{}%
 \fi
 \edef\xskak@val@movenr{\csname Xskak#1lastmovenr\endcsname}%
 \edef\xskak@val@player{\csname Xskak#1lastplayer\endcsname}%
 }%

\define@key[UFCB]{glofill}{lastmoveid}{%
    \board@do@l@addto@macro\board@val@savedkeylist{,lastmoveid=#1}}%

\define@key[UFCB]{locfill}{refid}{%
 \ifcsname xskak@tag@#1@refid\endcsname
  \UFCB@locfill@id{\csname xskak@tag@#1@refid\endcsname}%
 \else
   \PackageError{xskak}{Unknown tag #1}{}%
 \fi}

\define@key[UFCB]{glofill}{refid}{%
    \board@do@l@addto@macro\board@val@savedkeylist{,refid=#1}}%

\define@key[UFCB]{locfill}{refpastmovenr}{%
 \ifcsname xskak@tag@#1@refid\endcsname
  \UFCB@locfill@movenr{\csname xskak@tag@#1@refpastmovenr\endcsname}%
 \else
   \PackageError{xskak}{Unknown tag #1}{}%
 \fi}

\define@key[UFCB]{glofill}{refpastmovenr}{%
    \board@do@l@addto@macro\board@val@savedkeylist{,refpastmovenr=#1}}%

\define@key[UFCB]{locfill}{refnextmovenr}{%
 \ifcsname xskak@tag@#1@refid\endcsname
   \PackageError{xskak}{Unknown tag #1}{}%
 \fi
 \UFCB@locfill@movenr{\csname xskak@tag@#1@refnextmovenr\endcsname}}

\define@key[UFCB]{glofill}{refnextmovenr}{%
    \board@do@l@addto@macro\board@val@savedkeylist{,refnextmovenr=#1}}%

\define@key[UFCB]{locfill}{refpastplayer}{%
 \ifcsname xskak@tag@#1@refid\endcsname
  \UFCB@locfill@player{\csname xskak@tag@#1@refpastplayer\endcsname}%
 \else
   \PackageError{xskak}{Unknown tag #1}{}%
 \fi}

\define@key[UFCB]{glofill}{refpastplayer}{%
    \board@do@l@addto@macro\board@val@savedkeylist{,refpastplayer=#1}}%

\define@key[UFCB]{locfill}{refnextplayer}{%
 \ifcsname xskak@tag@#1@refid\endcsname
  \UFCB@locfill@player{\csname xskak@tag@#1@refnextplayer\endcsname}%
 \else
   \PackageError{xskak}{Unknown tag #1}{}%
 \fi}

\define@key[UFCB]{glofill}{refnextplayer}{%
    \board@do@l@addto@macro\board@val@savedkeylist{,refnextplayer=#1}}%

\define@key[UFCB]{locfill}{refpastmoveid}{%
 \ifcsname xskak@tag@#1@refid\endcsname
  \UFCB@locfill@moveid{\csname xskak@tag@#1@refpastmoveid\endcsname}%
 \else
   \PackageError{xskak}{Unknown tag #1}{}%
 \fi}

\define@key[UFCB]{glofill}{refpastmoveid}{%
    \board@do@l@addto@macro\board@val@savedkeylist{,refpastmoveid=#1}}%

\define@key[UFCB]{locfill}{refnextmoveid}{%
 \ifcsname xskak@tag@#1@refid\endcsname
  \UFCB@locfill@moveid{\csname xskak@tag@#1@refnextmoveid\endcsname}%
 \else
   \PackageError{xskak}{Unknown tag #1}{}%
 \fi}

\define@key[UFCB]{glofill}{refnextmoveid}{%
    \board@do@l@addto@macro\board@val@savedkeylist{,refnextmoveid=#1}}%

\define@key[UFCB]{locfill}{refpast}{%
 \ifcsname xskak@tag@#1@refid\endcsname
  \UFCB@locfill@movenr{\csname xskak@tag@#1@refpastmovenr\endcsname}%
  \UFCB@locfill@id{\csname xskak@tag@#1@refid\endcsname}%
 \else
   \PackageError{xskak}{Unknown tag #1}{}%
 \fi}

\define@key[UFCB]{glofill}{refpast}{%
    \board@do@l@addto@macro\board@val@savedkeylist{,refpast=#1}}%

\define@key[UFCB]{locfill}{refnext}{%
 \ifcsname xskak@tag@#1@refid\endcsname
  \UFCB@locfill@movenr{\csname xskak@tag@#1@refnextmovenr\endcsname}%
  \UFCB@locfill@id{\csname xskak@tag@#1@refid\endcsname}%
 \else
   \PackageError{xskak}{Unknown tag #1}{}%
 \fi}

\define@key[UFCB]{glofill}{refnext}{%
    \board@do@l@addto@macro\board@val@savedkeylist{,refnext=#1}}%

\define@key[UFCB]{locfill}{refpast}{%
 \ifcsname xskak@tag@#1@refid\endcsname
  \UFCB@locfill@movenr{\csname xskak@tag@#1@refpastmovenr\endcsname}%
  \UFCB@locfill@id{\csname xskak@tag@#1@refid\endcsname}%
 \else
   \PackageError{xskak}{Unknown tag #1}{}%
 \fi}

\define@key[UFCB]{glofill}{refpast}{%
    \board@do@l@addto@macro\board@val@savedkeylist{,refpast=#1}}%

\define@key[UFCB]{locfill}{reffen}{%
 \ifcsname xskak@tag@#1@refid\endcsname
  \UFCB@locfill@addfen{%
  \csname
   Xskak.%
   \csname xskak@tag@#1@refid\endcsname.%
   \csname xskak@tag@#1@refnextmovenr\endcsname.%
   \csname xskak@tag@#1@refnextplayer\endcsname.%
   pastfen%
  \endcsname}
 \else
   \PackageError{xskak}{Unknown tag #1}{}%
 \fi}

\define@key[UFCB]{glofill}{reffen}{%
    \board@do@l@addto@macro\board@val@savedkeylist{,reffen=#1}}%

%% currently not described. Perhaps delete. Perhaps change name to adapt to ref-keys?
\define@key[UFCB]{locfill}{setgame}[\xskak@val@gameid]{%
 \ifcsname Xskak#1initfen\endcsname
  \edef\xskak@val@gameid{#1}%
 \else
  \PackageError{xskak}{Game with the id #1 doesn't exist.}{}%
 \fi
 \edef\board@temp@curfen{\csname Xskak#1lastfen\endcsname}%
 \board@do@setsinglekeys*[UFCB]{locfill}{language=english, setfen=\board@temp@curfen, language=\board@val@savelang}}%

\define@key[UFCB]{glofill}{setgame}[\xskak@val@gameid]{%
    \board@do@l@addto@macro\board@val@savedkeylist{,showgame=#1}}%

%% currently not described. Perhaps delete. Perhaps change name to adapt to ref-keys?
\define@key[UFCB]{locfill}{addgame}[\xskak@val@gameid]{%
 \ifcsname Xskak#1initfen\endcsname
   \edef\xskak@val@gameid{#1}%
 \else\PackageError{xskak}{Game with the id #1 doesn't exist.}{}%
 \fi
 \edef\board@temp@curfen{\csname Xskak#1lastfen\endcsname}%
 \board@do@setsinglekeys*[UFCB]{locfill}{language=english, addfen=\board@temp@curfen, language=\board@val@savelang}}%

\define@key[UFCB]{glofill}{addgame}[\xskak@val@gameid]{%
    \board@do@l@addto@macro\board@val@savedkeylist{,showgame=#1}}%

\endinput
%%
%% End of file `xskak-keys.sty'.
