xskak & chessboard & count of pieces

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?

-
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
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. – Bruno Le Floch 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:

\documentclass{article}
\usepackage{xskak,chessboard}
\begin{document}
\newchessgame
\chessboard[getpiecelists]%

\newcounter{countrook}
\setcounter{countrook}{0}

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

Number of black rooks: \thecountrook. They are at the positions \cblistr.
\end{document}


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

\documentclass{article}
\usepackage{xskak,chessboard}

\makeatletter
\renewcommand\board@do@getpiecelists{%
\setcounter{cnt@board@file}{\board@val@minfilenum}%
\setcounter{cnt@board@rank}{\board@val@minranknum}%
\edef\board@temp@curlist{% changed 3.2.2012 to parse all pieces.
\board@skak@piececharlist}
\@for\board@temp@piecechar:=\board@temp@curlist
\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\cblistempty{}%
\xdef\cblistnumempty{}% 3.2.2012
\def\board@temp@empty@comma{}%
\whiledo
{\value{cnt@board@file}<\numexpr \board@val@maxfilenum+1\relax}%
{\whiledo
{\value{cnt@board@rank}<\numexpr \board@val@maxranknum+1\relax}%
{\edef\board@temp@piecechar{%
\csname
board@val@f\the\c@cnt@board@file r\the\c@cnt@board@rank @piecechar\endcsname}%
\edef\board@temp@curlist{%
\csname cblist\board@temp@piecechar\endcsname}%
\edef\board@temp@comma{%
\csname board@temp@\board@temp@piecechar @comma\endcsname}%
\expandafter\xdef\csname cblist\board@temp@piecechar \endcsname{%
\board@temp@curlist
\board@temp@comma
\alph{cnt@board@file}\the\c@cnt@board@rank}%
\expandafter\xdef\csname cblistnum\board@temp@piecechar\endcsname{\the\numexpr \csname cblistnum\board@temp@piecechar\endcsname +1}% 3.2.2012
\expandafter\def
\csname board@temp@\board@temp@piecechar @comma\endcsname
{,}%
\stepcounter{cnt@board@rank}}%
\setcounter{cnt@board@rank}{\board@val@minranknum}%
\stepcounter{cnt@board@file}}}
\makeatother
\begin{document}

\newchessgame
\chessboard[setpieces={Ke1,Ra1,Ra3,Ra5},getpiecelists,marginleft=false]

White king: \cblistnumK

White rooks: \cblistnumR

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

empty fields: \cblistnumempty

\end{document}

-
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? – Dr. Heiko Voss 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