File: chessgame

package info (click to toggle)
wims 2%3A4.29a%2Bdfsg1-3
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 185,704 kB
  • sloc: xml: 366,687; javascript: 120,570; ansic: 62,341; java: 62,170; sh: 7,744; perl: 3,937; yacc: 3,217; cpp: 1,915; lex: 1,805; makefile: 1,084; lisp: 914; pascal: 601; python: 520; php: 318; asm: 7
file content (204 lines) | stat: -rw-r--r-- 6,370 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
option:color=" " nogoodprint

!!option=noorder (plusieurs rponses dans n'importe quel ordre) non document car n'est peut-tre
!! pas trs utile : ne peut pas servir pour numrer les dplacements possibles d'une seule pice.
!!option=nogoodprint : does not give the good answer in the embed part

ans_lettre=a,b,c,d,e,f,g,h
!set ans_color=!getopt color in $(replyoption$i)
!default ans_color=[#CA906E,#F0EAB9,black]
ans_rep=!rows2lines $(reply$i)
ans_rep_cnt=!linecnt $ans_rep

ans_Rep$i=
ans_rep$i=
!for j=1 to $ans_rep_cnt
  z=!line $j of $ans_rep
  z=!replace internal - by , -, in $z
  d_y=$[($(z[1])-1)%8 +1]
  d_xx=$[($(z[1])-$d_y)/8+1]
  d_x=!item $d_xx of $ans_lettre
  a_y=$[($(z[3])-1)%8 +1]
  a_xx=$[($(z[3])-$a_y)/8+1]
  a_x=!item $a_xx of $ans_lettre
  zz=$(z[2])
  !default zz=-
  ans_rep$i=!append line $d_x$d_y$(zz)$a_x$a_y to $(ans_rep$i)
  ans_Rep$i=!append line $d_x$d_y,$a_x$a_y to $(ans_Rep$i)
!next
!set ans_rep$i=!lines2rows $(ans_rep$i)
!set ans_Rep$i=!lines2rows $(ans_Rep$i)
!set g_answer=!lines2rows $(replygood$i)
!set g_answer=!rows2lines $g_answer
!set ans_initial=!line 1 of $g_answer
!set ans_initial=!declosing $ans_initial
!set g_answer=!line 2 of $g_answer
!set g_answer=!declosing $g_answer
!!pas d'analyse de la rponse
!if $g_answer=$empty
  replygood$i=?analyze
!endif
score=0
tmp=!lines2rows $(ans_Rep$i)
tmp_order=!rows2lines $(ans_Rep$i)
tmp_order=!replace internal , by | in $tmp_order
tmp_order=!lines2items $tmp_order
tmp_order=!nospace $tmp_order
g_ans=!replace internal | by $\
$ in $g_answer
g_ans=!translate internal -+x# to ,,,,  in $g_ans
g_prom=!replace internal = by XX in $g_mv
!if XX isin $g_prom
  g_ans=!translate =[A-Z] to $ $ in $g_ans
!else
  !reset g_prom
!endif
g_ans=!translate [A-Z] to $ $ in $g_ans
g_ans_cnt=!linecnt $g_ans
!reset G_answer
on cherche la meilleure rponse
test=0
sol=1
!for l_ = 1 to $g_ans_cnt
  u=!line $l_ of $g_ans
  test$l_=0
  ans_cnt$l_=!itemcnt $(u[;1])
  !if noorder notwordof $(replyoption$i)
    !for p=1 to $(ans_cnt$l_)
      u_= $(u[$p;])
      !for s = 1 to 2
        v_ = $(u_[$s])
        !if $v_ issametext $(tmp[$p;$s])
        !advance test$l_
        !endif
      !next s
    !next p
  !else noorder
    uorder=!rows2lines $u
    uorder=!replace internal , by | in $uorder
    uorder=!lines2items $uorder
    uorder=!nospace $uorder
    inter=!listintersect $uorder and $tmp_order
    diff1=!listcomplement $uorder in $tmp_order
    diff2=!listcomplement $tmp_order in $uorder
    diff1_cnt=!itemcnt $diff1
    diff2_cnt=!itemcnt $diff2
    test$l_=!itemcnt $inter_cnt
    test$l_=$[2*$(test$l_)]
  !endif
  !if $(test$l_) > $test
    test=$(test$l_)
    sol=$l_
  !endif
!next l_

!!sol est la solution la plus proche d'une bonne solution
G_answer=!line $sol of $g_answer

!!!for p=1 to $(ans_cnt$sol)
!!  !for s=1 to 2
!!    uu=!text expand $(G_answer[$p;$s]) using 01
!!    uu=!words2items $uu
!!    u1=!positionof item $(uu[1]) in $ans_lettre
!!    Feed_g=!append item $(u1)_$(uu[2]) to $Feed_g
!!  !next
!!!next
!if noorder notwordof $(replyoption$i)
  score=$[$(test$sol)/(2*$(ans_cnt$sol))]
!else
  score=$[1-$test/$(ans_cnt$sol)]
!endif

!if $lang=fr
  !set name_init=Position initiale
  !set name_answer= Votre proposition de coup
  !set name_goodanswer=Solution
!else
  !set name_init=Initial position
  !set name_answer=Your proposed move
  !set name_goodanswer=The correct move
!endif

G_answer=!lines2rows $G_answer
!readproc slib/games/chessboard [$ans_initial],$ans_color,id=ini$i caption="$name_init"
ans_init=$slib_out
!readproc slib/games/chessmv [$ans_initial],[$(ans_Rep$i)]
!set r_final=$slib_out
!readproc slib/games/chessboard $(r_final[-1;1]),$ans_color,id=rep$i caption="$name_answer"
reply_$i=$slib_out
!if $g_answer !=$empty
  !readproc slib/games/chessmv [$ans_initial],[$G_answer]
  !set g_final=$slib_out
  !if nogoodprint notwordof $(replyoption$i) and $presentgood!=0
    !readproc slib/games/chessboard $(g_final[-1;1]),$ans_color,caption="$name_goodanswer"
    replyGood$i=<div class="chess_answer oef_indneutral">$slib_out</div>
  !endif
!endif

m_r=$(ans_rep$i)
reply__$i=$m_r
!reset m_reply$i
r_final_=$(r_final)
!for j=1 to $ans_rep_cnt
  m_reply$i=!append line $(m_r[$j;]),$(r_final_[$j;2]),$(r_final_[$j;1]) to $(m_reply$i)
!next
m_reply$i=!lines2rows $(m_reply$i)
m_reply$i=!singlespace $(m_reply$i)
m_reply$i=!words2items $(m_reply$i)
!if $g_answer=$empty
  !for j=1 to 2*$ans_rep_cnt
    reply_$i=!replace internal <td id="cell_rep$(i)_$(ans_Rep$i[$j])" by <td id="cell_rep$(i)_$(ans_Rep$i[$j])" class="oef_indneutral" in $(reply_$i)
  !next
  reply_$i=<div class="flex_box oef_indneutral"><div class="chess_initial">$ans_init</div>\
  <div class="chess_answer">$(reply_$i)</div></div>
  !exit
!endif

!if $score=1
  diareply$i=good
  !advance freegot
!else
  diareply$i=bad
!endif
!if $score=1
  reply_$i=<div class="flex_box"><div class="chess_initial oef_indneutral">$ans_init</div>\
  <div class="chess_answer">$(reply_$i)</div></div>
  reply_$i=!replace internal <table by <table class="oef_indneutral" in $(reply_$i)
!else
  reply_$i=<div class="flex_box"><div class="chess_initial oef_indneutral">$ans_init</div>\
    <div class="chess_answer oef_indneutral">$(reply_$i)</div>\
    $(replyGood$i)</div>
!endif

!for j=1 to 2*$ans_rep_cnt
  !if $(ans_Rep$i[$j]) isin $G_answer
    reply_$i=!replace internal <td id="cell_rep$(i)_$(ans_Rep$i[$j])" class=" by \
      <td id="cell_rep$(i)_$(ans_Rep$i[$j])" class="chess_answer oef_indgood$ $ in $(reply_$i)
  !else
    reply_$i=!replace internal <td id="cell_rep$(i)_$(ans_Rep$i[$j])" class=" by \
      <td id="cell_rep$(i)_$(ans_Rep$i[$j])" class="chess_answer oef_indbad$ $ in $(reply_$i)
  !endif
!next

!!!for j=1 to 2*$(ans_cnt$sol)
!!  reply_$i=!replace internal <td id="cell_rep$(i)_$(Feed_g[$j])" by \
!!    <td id="cell_rep$(i)_$(Feed_g[$j])" class="chess_answer oef_indbad" in $(reply_$i)
!!!next

g_reply_=$(g_final[;2])
g_reply__=

!for u=1 to $(ans_cnt$sol)
  c=!declosing $(g_reply_[$u])
  c_nt=!itemcnt $c
  !if $c_nt=2
    g_reply__=!append line $(G_answer[$u;1])x$(G_answer[$u;2]) to $g_reply__
  !else
    g_reply__=!append line $(G_answer[$u;1])-$(G_answer[$u;2]) to $g_reply__
  !endif
!next
g_reply__=!lines2rows $(g_reply__)

!!!if $score<1 and $presentgood!=0
!!  reply__$i=$(reply__$i); $ch_good1: <span class="tt">$g_reply__</span>.
!!!endif