%%%
% R\'eponses \`a relier
%%%
\setKVdefault[ClesRelie]{Solution=false,LargeurG=5cm,LargeurD=2cm,Stretch=1.5,Ecart=2cm,Couleur=black}%
\defKV[ClesRelie]{Graine=\PfCGraineAlea{#1}}%

\NewDocumentCommand\Relie{som}{%
  \useKVdefault[ClesRelie]%
  \setKV[ClesRelie]{#2}%
  \colorlet{PfCRelieCouleurTrace}{\useKV[ClesRelie]{Couleur}}%
  \setsepchar[*]{,*/}\reademptyitems%
  \readlist*\ListeRelie{#3}%
  \ignoreemptyitems%
  \IfBooleanTF{#1}{%
    \buildtabrelieauto%
    %\par
    \ifboolKV[ClesRelie]{Solution}{%
      \xintFor* ##1 in {\xintSeq {1}{\ListeRelielen}}\do{%
        \itemtomacro\PfCListeReponsesMelangees[##1]\PfCNumReponses%
        \itemtomacro\ListeRelie[\PfCNumReponses,1]\untest%
        % Le test est \untest\\
        \ifx\bla\untest\bla%
        \else
          \tikz[remember picture,overlay]{\draw[PfCRelieCouleurTrace] (RelieG-\PfCNumReponses) -- (RelieD-##1);}%
        \fi
      }%
    }{%
    }%
  }{%
    \buildtabrelie%
    \ifboolKV[ClesRelie]{Solution}{%
      \xintFor* ##1 in {\xintSeq {1}{\ListeRelielen}}\do{%
        \itemtomacro\ListeRelie[##1,1]\untest%
        \ifx\bla\untest\bla%
        \else%
          \tikz[remember picture,overlay]{\draw[PfCRelieCouleurTrace] (RelieG-##1) -- (RelieD-\ListeRelie[##1,3]);}%
        \fi
      }%
    }{%
    }%
  }%
}%

\newcommand\Relieold[2][]{%
  \useKVdefault[ClesRelie]%
  \setKV[ClesRelie]{#1}%
  \setsepchar[*]{,*/}\reademptyitems%
  \readlist*\ListeRelie{#2}%
  \ignoreemptyitems
  \buildtabrelie%
  \ifboolKV[ClesRelie]{Solution}{%
    \colorlet{PfCRelieCouleurTrace}{\useKV[ClesRelie]{Couleur}}%
    \xintFor* ##1 in {\xintSeq {1}{\ListeRelielen}}\do{%
      \itemtomacro\ListeRelie[##1,1]\untest
      \ifx\bla\untest\bla%
      \else
        \tikz[remember picture,overlay]{\draw[PfCRelieCouleurTrace] (RelieG-##1) -- (RelieD-\ListeRelie[##1,3]);}%
      \fi
    }%
  }{%
  }%
}%

\newcounter{NbRelie}%

\def\buildtabrelie{%
  \setcounter{NbRelie}{0}%
  \renewcommand{\arraystretch}{\useKV[ClesRelie]{Stretch}}%
  \begin{tabular}{p{\useKV[ClesRelie]{LargeurG}}cp{\useKV[ClesRelie]{Ecart}}>{\tikz[remember
    picture]{\node[name=RelieD-\theNbRelie,inner
    sep=0pt]{};\fill[] (RelieD-\theNbRelie) circle[radius=1.5pt]}}cp{\useKV[ClesRelie]{LargeurD}}}%
    \xintFor* ##1 in {\xintSeq {1}{\ListeRelielen}}\do{\ListeRelie[##1,1]\itemtomacro\ListeRelie[##1,1]\untest%
\ifx\bla\untest\bla%                                     
    \uppercase{&}\stepcounter{NbRelie}%
      \else
      \uppercase{&}\stepcounter{NbRelie}\tikz[remember
                   picture,overlay]{\node[name=RelieG-\theNbRelie,inner
                   sep=0pt]{};\fill[]
                   (RelieG-\theNbRelie) circle[radius=1.5pt];}
\fi&&&\ListeRelie[##1,2]\\}%
  \end{tabular}%
  \setcounter{NbRelie}{0}%
}%

\def\buildtabrelieauto{%
  \setcounter{NbRelie}{0}%
  \xdef\PfCFooListeNbQ{1}%
  \xintFor* ##1 in{\xintSeq{2}{\ListeRelielen}}\do{%
    \xdef\PfCFooListeNbQ{\PfCFooListeNbQ,##1}%
  }%
  \setsepchar{,}\ignoreemptyitems%
  \MelangeListe{\PfCFooListeNbQ}{\ListeRelielen}%
  \setsepchar{,}\ignoreemptyitems%
  \readlist*\PfCListeReponsesMelangees{\faa}%
  \renewcommand{\arraystretch}{\useKV[ClesRelie]{Stretch}}%
  \begin{tabular}{p{\useKV[ClesRelie]{LargeurG}}cp{\useKV[ClesRelie]{Ecart}}>{\tikz[remember
          picture]{\node[name=RelieD-\theNbRelie,inner
            sep=0pt]{};\fill[] (RelieD-\theNbRelie) circle[radius=1.5pt]}}cp{\useKV[ClesRelie]{LargeurD}}}%
    \xintFor* ##1 in {\xintSeq {1}{\ListeRelielen}}\do{
      \ListeRelie[##1,1]\itemtomacro\ListeRelie[##1,1]\untest%
      \ifx\bla\untest\bla%                                     
      \uppercase{&}\stepcounter{NbRelie}\tikz[remember
        picture,overlay]{\node[name=RelieG-\theNbRelie,inner
          sep=0pt]{};}
      \else
      \uppercase{&}\stepcounter{NbRelie}\tikz[remember
        picture,overlay]{\node[name=RelieG-\theNbRelie,inner
          sep=0pt]{};\fill[]
        (RelieG-\theNbRelie) circle[radius=1.5pt];}
      \fi&&&\itemtomacro\PfCListeReponsesMelangees[##1]\PfCNumReponses\ListeRelie[\PfCNumReponses,2]\\}%
  \end{tabular}%
  \setcounter{NbRelie}{0}%
}%