Within used packages xskak and chessboard and an initialized game, how can I determine the count of white and black pieces of a given \newgame and how I can output the actual position of these pieces on the corresponding chessboard? I know that there is an argument of \getpieceslist for \chessboard, but how I can summarize with the help of TeX commands the pieces for white and black and how I can output these lists with the help of figure?

  • 1
    Welcome to TeX.sx! Usually, we don't put a greeting/signature or a "thank you" in our posts. While this might seem strange at first, it is not a sign of lack of politeness, but rather part of our trying to keep everything very concise. Upvoting is the preferred way here to say "thank you" to users who helped you.
    – Werner
    Feb 2 '12 at 20:39
  • 3
    It would be helpful if you provided an example file using the packages xskak and chessboard: then experienced TeX users who don't know about those slightly uncommon packages can try this MWE and dissect it/hack. Feb 3 '12 at 2:21

The option (not the command) getpiecelists give comma separated lists of positions. You must parse this list e.g. with \@for to count them:



 \@for\templist:=\cblistr \do {\stepcounter{countrook}}

Number of black rooks: \thecountrook. They are at the positions \cblistr.

Edit: You can try this to get the various counts (I also change the command so that \cblist... now it defined also for pieces which are not on the board):


 \edef\board@temp@curlist{% changed 3.2.2012 to parse all pieces.
  \do {%
   \expandafter\xdef\csname cblist\board@temp@piecechar\endcsname{}% 3.2.2012 global
   \expandafter\xdef\csname cblistnum\board@temp@piecechar\endcsname{0}% 3.2.2012 new
   \expandafter\def\csname board@temp@\board@temp@piecechar @comma\endcsname{}}%
 \xdef\cblistnumempty{}% 3.2.2012
  {\value{cnt@board@file}<\numexpr \board@val@maxfilenum+1\relax}%
   {\value{cnt@board@rank}<\numexpr \board@val@maxranknum+1\relax}%
       board@val@f\the\c@cnt@board@file r\the\c@cnt@board@rank @piecechar\endcsname}%
    \csname cblist\board@temp@piecechar\endcsname}%
    \csname board@temp@\board@temp@piecechar @comma\endcsname}%
   \expandafter\xdef\csname cblist\board@temp@piecechar \endcsname{%
   \expandafter\xdef\csname cblistnum\board@temp@piecechar\endcsname{\the\numexpr \csname cblistnum\board@temp@piecechar\endcsname +1}% 3.2.2012
     \csname board@temp@\board@temp@piecechar @comma\endcsname


White king: \cblistnumK

White rooks: \cblistnumR

White pieces: \the\numexpr \cblistnumK + \cblistnumQ +\cblistnumR
+\cblistnumB + \cblistnumN + \cblistnumP\relax

empty fields: \cblistnumempty

  • Thanks for your answer. This gave me a clear idea, how can I do this. Is it possible to incorporate this command into the package "chessboard" so that one can output the count of pieces for a chess problem diagram like the pattern "(white count + black count)"? What is the best way to put this pattern directly below the board with left alignment on the border independent of the existence of labels? Feb 3 '12 at 13:13
  • @Dr.HeikoVoss Welcome to TeX.SX. The format of this site is not compatible to discuss follow-up questions in a series of answers fashion. You are more than welcome to ask a new question or you can simply comment to the answer that you are interested in such that the original answer can be augmented
    – percusse
    Feb 3 '12 at 13:20
  • @Dr.HeikoVoss It looks like you accidentally created another account (11403 vs. 11420). I flagged this answer, so a mod will come along and probably merge your accounts.
    – doncherry
    Feb 3 '12 at 14:09
  • @Dr.HeikoVoss I merged the accounts. It would be good if you would register on the site to be able to use all features. Further, I converted the follow-up question to a comment, as the space below is for actual answers.
    – Stefan Kottwitz
    Feb 3 '12 at 14:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.