xc=!eval $xx_size*($click_x-$border)/$inssize+$x_size1
yc=!eval $yy_size*(-$click_y+$border)/$inssize+$x_size2

!if $status=waiting
  !if ($opar1<2) and ($abandon=0)
    pt=0
    !for i=1 to $n
      u=$(abscisse$i)
      v=$(ordonnee$i)
      d=$[(abs((($xc) - ($u))^2 + (($yc) - ($v))^2))^(1/2)]
      !if $d < $incert
        pt=$i
      !endif
    !next i
    !if $pt=0
      error=pas_de_point
    !else
      !if $etp=0
        ar=$pt
        ptabs=$(abscisse$pt)
        ptord=$(ordonnee$pt)
        etp=1
      !else
        ar=$ar,$pt
!!      L'arte a dj t dessine ?
        I=!item 1 of $ar
        J=$pt
        L=!line $I of $GCM
        u=!item $J of $L
        L=!line $J of $GCM
        v=!item $I of $L
!!      w=prsence d'une arte entre i et j ou de i vers j
        !if $gor=0
          !if ($u=1) or ($v=1)
            w=1
          !else
            w=0
          !endif
        !else
          w=$u
        !endif
        essai=$w
        !if $opar1=0
          !if $w = 0
            GC=!exec pari M=[$GC]; M[$I,$J]=1; print(M)
            GCM=!translate internal ; to $\
$ in $GC
          !else
            error=arete_existe_deja
          !endif
        !else
          !if $w=1
            !if $gor=0
              GC=!exec pari M=[$GC]; M[$I,$J]=0; M[$J,$I]=0; print(M)
            !else
              GC=!exec pari M=[$GC]; M[$I,$J]=0; print(M)
            !endif
            GCM=!translate internal ; to $\
$ in $GC
          !else
            error=arete_n_existe_pas
          !endif
        !endif
        etp=0
      !endif
    !endif
!!  Prparation du trac des artes
    dessin_aretes=$empty
    !for i=1 to $n
      !for j=1 to $n
        L=!line $i of $GCM
        u=!item $j of $L
        !if $u=1
          param=$empty
          x1=$(abscisse$i)
          y1=$(ordonnee$i)
          x2=$(abscisse$j)
          y2=$(ordonnee$j)
          !if $gor=1
            x=$[$x1+$k*($x2-$x1)]
            y=$[$y1+$k*($y2-$y1)]
            param=arrow $x1, $y1, $x, $y, $kf, $color2
          !endif
          param=$param\
          line $x1, $y1, $x2, $y2, $color2
          dessin_aretes=$dessin_aretes\
          $param
        !endif
      !next j
    !next i
    !if $etp=1
      dessin_aretes=$dessin_aretes\
      disk $ptabs,$ptord, 6, $color3
    !endif
  !else
!!  Analyse de la rponse

    !if $gor=0
      GC=!exec pari {A=[$GC];\
      A=matrix($n,$n,i,j,max(A[i,j],A[j,i]));\
      print(A)}
      GCM=!translate internal ; to $\
$ in $GC
      GCM=!trim $GCM
    !endif
    !if $gor=0
      !for i=1 to $n
        x=0
        !for j=1 to $n
          L=!line $i of $GCM
          u=!item $j of $L
          !if $u=1
            !advance x
          !endif
        !next j
        degC=!replace item number $i by $x in $degC
      !next i
    z=!exec pari [$deg]==[$degC]
    !else
      !for i=1 to $n
        x=0
        y=0
        !for j=1 to $n
          L=!line $i of $GCM
          u=!item $j of $L
          L=!line $j of $GCM
          v=!item $i of $L
          !if $u=1
            !advance x
          !endif
          !if $v=1
            !advance y
          !endif
        !next j
        degsC=!replace item number $i by $x in $degsC
        degeC=!replace item number $i by $y in $degeC
      !next i
      x=!exec pari [$dege]==[$degeC]
      y=!exec pari [$degs]==[$degsC]
      !if ($x=1) and ($y=1)
        z=1
      !else
        z=0
      !endif
    !endif
    !if $z=1
      module_score=10
    !else
      module_score=0
!!    On trouve un sommet aui n'a pas le bon degr
      !if $gor=0
        arete=$empty
        sommet=0
        !for i=1 to $n
          v=!item $i of $degC
          w=!item $i of $deg
          !if ($sommet=0) and $v<>$w
            sommet=$i
            pb1=$v
            pb2=$w
          !endif
        !next i
      !else
        !if $x=0
          arete=entrant 
          sommet=0
          !for i=1 to $n
            v=!item $i of $degeC
            w=!item $i of $dege
            !if ($sommet=0) and $v<>$w
              sommet=$i
              pb1=$v
              pb2=$w
            !endif
          !next i
        !else
          arete=sortant 
          sommet=0
          !for i=1 to $n
            v=!item $i of $degsC
            w=!item $i of $degs
            !if ($sommet=0) and $v<>$w
              sommet=$i
              pb1=$v
              pb2=$w
            !endif
          !next i
        !endif
      !endif
!!    Trac d'un graphe correct
      dessin_correct=$dessin_sommets
      !for i=1 to $n
        !for j=1 to $n
          L=!line $i of $GM
          u=!item $j of $L
          !if $u=1
            param=$empty
            x1=$(abscisse$i)
            y1=$(ordonnee$i)
            x2=$(abscisse$j)
            y2=$(ordonnee$j)
            !if $gor=1
              x=$[$x1+$k*($x2-$x1)]
              y=$[$y1+$k*($y2-$y1)]
              param=arrow $x1, $y1, $x, $y, $kf, $color2
            !endif
            param=$param\
            line $x1, $y1, $x2, $y2, $color2
            dessin_correct=$dessin_correct\
            $param
          !endif
        !next j
      !next i
    !endif
    status=done
  !endif
!endif

xc=0
yc=0
click_x=0
click_y=0
