Added upstream from http://ftp.icm.edu.pl/pub/loglan/
[loglan.git] / examples / jeu / othello.log
1   program othello;\r
2 \r
3   UNIT NEWPAGE : procedure;\r
4    begin\r
5      write( chr(27), "[2J")\r
6    end newpage;\r
7 \r
8    UNIT gotoxy : procedure (row, column : integer);\r
9         var c, d, e, f : char,\r
10             i, j : integer;\r
11    begin\r
12      i := row div 10;\r
13      j := row mod 10;\r
14      c := chr (48+i);\r
15      d := chr (48+j);\r
16      i := column div 10;\r
17      j := column mod 10;\r
18      e := chr (48+i);\r
19      f := chr (48+j);\r
20      write (chr(27), "[", c, d, ";", e, f, "H");\r
21    end gotoxy;\r
22 \r
23   unit Normal : procedure;\r
24   begin\r
25     write( chr(27), "[0m")\r
26   end Normal;\r
27 \r
28   UNIT INCHAR : IIuwgraph function : integer;\r
29    begin\r
30      do\r
31        i := inkey;\r
32        if i <> 0 then exit fi;\r
33      od;\r
34      result := i;\r
35    end inchar;\r
36 \r
37   unit pause:procedure(input seconde:integer);\r
38   var temps:integer;\r
39   begin\r
40   for temps:=1 to (9000*seconde) do od;\r
41   end pause;\r
42 \r
43   unit grille:class;\r
44   var g:arrayof arrayof integer;\r
45   var i:integer;\r
46   begin\r
47    array g dim (1:8);\r
48    for i:=1 to 8\r
49     do\r
50      array g(i) dim (1:8);\r
51     od;\r
52   end grille;\r
53 \r
54   unit initialisegrille : procedure(inout gr: arrayof arrayof integer);\r
55   var i,j:integer;\r
56   begin\r
57   (* creation de la grille *)\r
58    array gr dim (1:8);\r
59    for i:=1 to 8\r
60     do\r
61      array gr(i) dim (1:8);\r
62     od;\r
63   (* initialisation de la grille *)\r
64   (* 0 case vide *)\r
65   (* 1 case avec pion noir *)\r
66   (* 2 case avec pion blanc *)\r
67    for i:=1 to 8\r
68     do\r
69      for j:=1 to 8\r
70       do\r
71        gr(i,j):=0;\r
72       od;\r
73     od;\r
74 (*  for j:=1 to 8 do gr(8,j):=0 od;*)\r
75    gr(4,4):=1;\r
76    gr(5,5):=1;\r
77    gr(4,5):=2;\r
78    gr(5,4):=2;\r
79   end initialisegrille;\r
80 \r
81 unit affichecadre:procedure;\r
82 begin\r
83 call newpage;\r
84 call gotoxy(2,2);\r
85 writeln("    1    2    3    4    5    6    7    8   ");\r
86 writeln("  ÚÄÄÄÄÂÄÄÄÄÂÄÄÄÄÂÄÄÄÄÂÄÄÄÄÂÄÄÄÄÂÄÄÄÄÂÄÄÄÄ¿");\r
87 writeln("1 ³    ³    ³    ³    ³    ³    ³    ³    ³");\r
88 writeln("  ÃÄÄÄÄÅÄÄÄÄÅÄÄÄÄÅÄÄÄÄÅÄÄÄÄÅÄÄÄÄÅÄÄÄÄÅÄÄÄÄ´");\r
89 writeln("2 ³    ³    ³    ³    ³    ³    ³    ³    ³");\r
90 writeln("  ÃÄÄÄÄÅÄÄÄÄÅÄÄÄÄÅÄÄÄÄÅÄÄÄÄÅÄÄÄÄÅÄÄÄÄÅÄÄÄÄ´");\r
91 writeln("3 ³    ³    ³    ³    ³    ³    ³    ³    ³");\r
92 writeln("  ÃÄÄÄÄÅÄÄÄÄÅÄÄÄÄÅÄÄÄÄÅÄÄÄÄÅÄÄÄÄÅÄÄÄÄÅÄÄÄÄ´");\r
93 writeln("4 ³    ³    ³    ³    ³    ³    ³    ³    ³");\r
94 writeln("  ÃÄÄÄÄÅÄÄÄÄÅÄÄÄÄÅÄÄÄÄÅÄÄÄÄÅÄÄÄÄÅÄÄÄÄÅÄÄÄÄ´");\r
95 writeln("5 ³    ³    ³    ³    ³    ³    ³    ³    ³");\r
96 writeln("  ÃÄÄÄÄÅÄÄÄÄÅÄÄÄÄÅÄÄÄÄÅÄÄÄÄÅÄÄÄÄÅÄÄÄÄÅÄÄÄÄ´");\r
97 writeln("6 ³    ³    ³    ³    ³    ³    ³    ³    ³");\r
98 writeln("  ÃÄÄÄÄÅÄÄÄÄÅÄÄÄÄÅÄÄÄÄÅÄÄÄÄÅÄÄÄÄÅÄÄÄÄÅÄÄÄÄ´");\r
99 writeln("7 ³    ³    ³    ³    ³    ³    ³    ³    ³");\r
100 writeln("  ÃÄÄÄÄÅÄÄÄÄÅÄÄÄÄÅÄÄÄÄÅÄÄÄÄÅÄÄÄÄÅÄÄÄÄÅÄÄÄÄ´");\r
101 writeln("8 ³    ³    ³    ³    ³    ³    ³    ³    ³");\r
102 writeln("  ÀÄÄÄÄÁÄÄÄÄÁÄÄÄÄÁÄÄÄÄÁÄÄÄÄÁÄÄÄÄÁÄÄÄÄÁÄÄÄÄÙ");\r
103 call gotoxy(22,1);\r
104 if souris then\r
105 writeln("ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ ");\r
106 writeln("³ D\82placement : Souris  ³  Valider : Bouton 1   ³    Quitter : Bouton 3   ³ ");\r
107 writeln("ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ ");\r
108 else\r
109 writeln("ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ ");\r
110 writeln("³ D\82placement : Fl\8aches  ³  Valider : RETURN     ³     Quitter : ECHAP    ³ ");\r
111 writeln("ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ ");\r
112 fi;\r
113 \r
114 end affichecadre;\r
115 \r
116   unit affichegrille : procedure(input gr: arrayof arrayof integer);\r
117   (* 0 case vide *)\r
118   (* 1 case avec pion noir *)\r
119   (* 2 case avec pion blanc *)\r
120   var i,j,v,w:integer;\r
121   begin\r
122   v:=4;\r
123    for i:=1 to 8\r
124     do\r
125     w:=5;\r
126      for j:=1 to 8\r
127       do\r
128        if (gr(i,j)=1) then call gotoxy(v,w);write(chr(27),"[33m");\r
129                            writeln("x ");write(chr(27),"[36m");fi;\r
130        if (gr(i,j)=2) then call gotoxy(v,w);write(chr(27),"[32m");\r
131                            writeln("o ");write(chr(27),"[36m");fi;\r
132        w:=w+5;\r
133       od;\r
134       v:=v+2;\r
135     od;\r
136   call gotoxy(v,1);\r
137   end affichegrille;\r
138 \r
139 unit deplace:procedure;\r
140 var touche,bidon:integer;\r
141 begin\r
142     call gotoxy(xx,yy);\r
143     do\r
144       touche := inchar;\r
145       case touche\r
146            when 50 : if xx<18 then xx:=xx+2;ii:=ii+1 fi;  (*Touche 2*)\r
147            when 52 : if yy>5 then yy:=yy-5;jj:=jj-1 fi;   (*Touche 4*)\r
148            when 54 : if yy<37 then yy:=yy+5;jj:=jj+1 fi;  (*Touche 6*)\r
149            when 56 : if xx>4 then xx:=xx-2;ii:=ii-1 fi;   (*Touche 8*)\r
150            when 13 : exit;                                (*Touche RC*)\r
151            when 27 : arreter:=true;exit;                  (*Touche ECHAP*)\r
152       esac;\r
153       call gotoxy(xx,yy);\r
154     od;\r
155  end deplace;\r
156 \r
157  unit direction:procedure(ligne,colonne:integer;\r
158                            deplacementcolonne,deplacementligne:integer;\r
159                            couleur,invcouleur:integer;\r
160                            tab:arrayof arrayof integer;\r
161                            output nbpion:integer);\r
162   var retourne:boolean;\r
163   begin\r
164    nbpion:=0;\r
165    retourne:=true;\r
166       do\r
167        colonne:=colonne+deplacementcolonne;\r
168        ligne:=ligne+deplacementligne;\r
169        if (colonne=0) or (colonne=9) or (ligne=0) or (ligne=9) then\r
170         (* debordement du tableau *)\r
171         retourne:=false;\r
172         exit;\r
173        fi;\r
174 \r
175        if (tab(ligne,colonne)=invcouleur) then\r
176         (* case de couleur inverse *)\r
177         nbpion:=nbpion+1;\r
178        fi;\r
179 \r
180        if (tab(ligne,colonne))=0 then\r
181         (* case vide*)\r
182         retourne:=false;\r
183         exit;\r
184        fi;\r
185 \r
186        if (tab(ligne,colonne)=couleur) then\r
187         (* case de meme couleur *)\r
188         exit;\r
189        fi;\r
190       od;\r
191 \r
192       if not(retourne) then nbpion:=0;fi;\r
193   end direction;\r
194 \r
195 unit retourne_pion:procedure(ligne,colonne:integer;\r
196                            deplacementcolonne,deplacementligne:integer;\r
197                            couleur,invcouleur:integer;\r
198                            inout tab:arrayof arrayof integer);\r
199   begin\r
200       do\r
201        colonne:=colonne+deplacementcolonne;\r
202        ligne:=ligne+deplacementligne;\r
203 \r
204        if (tab(ligne,colonne)=couleur) then\r
205         (* case de meme couleur *)\r
206         exit;\r
207        fi;\r
208 \r
209        if (tab(ligne,colonne)=invcouleur) then\r
210         (* case de couleur inverse *)\r
211         (* on inverse la couleur *)\r
212         tab(ligne,colonne):=couleur;\r
213        fi;\r
214       od;\r
215   end retourne_pion;\r
216 \r
217   unit nb_de_pion_a_poser:procedure(input couleur:integer;\r
218                                             input tab:arrayof arrayof integer;\r
219                                             input on_somme_prio:boolean;\r
220                                             output nb_pion_a_poser,som_prio:integer);\r
221   var i,j,nb:integer;\r
222   var on_retourne_pion:boolean;\r
223   begin\r
224    nb_pion_a_poser:=0;\r
225    on_retourne_pion:=false;\r
226    for i:=1 to 8\r
227     do\r
228      for j:=1 to 8\r
229       do\r
230        if tab(i,j)=0 then\r
231 call peut_on_poser_pion(i,j,couleur,tab,on_retourne_pion,on_somme_prio,nb,som_prio);\r
232         if nb<>0 then nb_pion_a_poser:=nb_pion_a_poser+1;fi;\r
233         fi;\r
234       od;\r
235     od;\r
236   end nb_de_pion_a_poser;\r
237 \r
238   unit peut_on_poser_pion:procedure(input ligne,colonne:integer;\r
239                                     input couleur:integer;\r
240                                     input tab:arrayof arrayof integer;\r
241                                     input on_retourne_pion,on_somme_prio:boolean;\r
242                                     output pionretourne,som_prio:integer);\r
243   var nord,sud,ouest,est:boolean;\r
244   var nord_ouest,nord_est,sud_ouest,sud_est:boolean;\r
245   var nbpion,invcouleur,i,j:integer;\r
246   var deplacementcolonne,deplacementligne:integer;\r
247   var prio : integer;\r
248   begin\r
249     prio:=0;\r
250     if (couleur=1) then invcouleur:=2 else invcouleur:=1;fi;\r
251     nord:=true;\r
252     sud:=true;\r
253     ouest:=true;\r
254     est:=true;\r
255     nord_ouest:=true;\r
256     nord_est:=true;\r
257     sud_ouest:=true;\r
258     sud_est:=true;\r
259     if (ligne<=2) then nord:=false;nord_ouest:=false;nord_est:=false;fi;\r
260     if (ligne>=7) then sud:=false;sud_ouest:=false;sud_est:=false;fi;\r
261     if (colonne>=7) then est:=false;sud_est:=false;nord_est:=false;fi;\r
262     if (colonne<=2) then ouest:=false;sud_ouest:=false;nord_ouest:=false;fi;\r
263     pionretourne:=0;\r
264       (* faire chaque direction *)\r
265       if (nord) then deplacementcolonne:=0;\r
266                      deplacementligne:=-1;\r
267                      call direction(ligne,colonne,\r
268                                     deplacementcolonne,deplacementligne,\r
269                                     couleur,invcouleur,tab,nbpion);\r
270                      pionretourne:=pionretourne+nbpion;\r
271                      if (nbpion<>0) and (on_retourne_pion) then\r
272                            call retourne_pion(ligne,colonne,\r
273                            deplacementcolonne,deplacementligne,\r
274                            couleur,invcouleur,tab);\r
275                            tab(ligne,colonne):=couleur;\r
276                      fi;\r
277                      if (nbpion<>0) and (on_somme_prio) then\r
278                            call prio_pion_retourne(ligne,colonne,\r
279                            deplacementcolonne,deplacementligne,\r
280                            couleur,invcouleur,tab,gr_p,prio);\r
281                            som_prio:=som_prio+prio;\r
282                      fi;\r
283                    fi;\r
284 \r
285        if (sud) then deplacementcolonne:=0;\r
286                      deplacementligne:=1;\r
287                      call direction(ligne,colonne,\r
288                                     deplacementcolonne,deplacementligne,\r
289                                     couleur,invcouleur,tab,nbpion);\r
290                      pionretourne:=pionretourne+nbpion;\r
291                      if (nbpion<>0) and (on_retourne_pion) then\r
292                            call retourne_pion(ligne,colonne,\r
293                            deplacementcolonne,deplacementligne,\r
294                            couleur,invcouleur,tab);\r
295                            tab(ligne,colonne):=couleur;\r
296                      fi;\r
297                      if (nbpion<>0) and (on_somme_prio) then\r
298                            call prio_pion_retourne(ligne,colonne,\r
299                            deplacementcolonne,deplacementligne,\r
300                            couleur,invcouleur,tab,gr_p,prio);\r
301                            som_prio:=som_prio+prio;\r
302                      fi;\r
303                    fi;\r
304 \r
305       if (ouest) then deplacementcolonne:=-1;\r
306                      deplacementligne:=0;\r
307                      call direction(ligne,colonne,\r
308                                     deplacementcolonne,deplacementligne,\r
309                                     couleur,invcouleur,tab,nbpion);\r
310                      pionretourne:=pionretourne+nbpion;\r
311                      if (nbpion<>0) and (on_retourne_pion) then\r
312                            call retourne_pion(ligne,colonne,\r
313                            deplacementcolonne,deplacementligne,\r
314                            couleur,invcouleur,tab);\r
315                            tab(ligne,colonne):=couleur;\r
316                      fi;\r
317                      if (nbpion<>0) and (on_somme_prio) then\r
318                            call prio_pion_retourne(ligne,colonne,\r
319                            deplacementcolonne,deplacementligne,\r
320                            couleur,invcouleur,tab,gr_p,prio);\r
321                            som_prio:=som_prio+prio;\r
322                      fi;\r
323                    fi;\r
324 \r
325        if (est) then deplacementcolonne:=1;\r
326                      deplacementligne:=0;\r
327                      call direction(ligne,colonne,\r
328                                     deplacementcolonne,deplacementligne,\r
329                                     couleur,invcouleur,tab,nbpion);\r
330                      pionretourne:=pionretourne+nbpion;\r
331                      if (nbpion<>0) and (on_retourne_pion) then\r
332                            call retourne_pion(ligne,colonne,\r
333                            deplacementcolonne,deplacementligne,\r
334                            couleur,invcouleur,tab);\r
335                            tab(ligne,colonne):=couleur;\r
336                      fi;\r
337                      if (nbpion<>0) and (on_somme_prio) then\r
338                            call prio_pion_retourne(ligne,colonne,\r
339                            deplacementcolonne,deplacementligne,\r
340                            couleur,invcouleur,tab,gr_p,prio);\r
341                            som_prio:=som_prio+prio;\r
342                      fi;\r
343                    fi;\r
344 \r
345       if (nord_ouest) then deplacementcolonne:=-1;\r
346                      deplacementligne:=-1;\r
347                      call direction(ligne,colonne,\r
348                                     deplacementcolonne,deplacementligne,\r
349                                     couleur,invcouleur,tab,nbpion);\r
350                      pionretourne:=pionretourne+nbpion;\r
351                      if (nbpion<>0) and (on_retourne_pion) then\r
352                            call retourne_pion(ligne,colonne,\r
353                            deplacementcolonne,deplacementligne,\r
354                            couleur,invcouleur,tab);\r
355                            tab(ligne,colonne):=couleur;\r
356                      fi;\r
357                      if (nbpion<>0) and (on_somme_prio) then\r
358                            call prio_pion_retourne(ligne,colonne,\r
359                            deplacementcolonne,deplacementligne,\r
360                            couleur,invcouleur,tab,gr_p,prio);\r
361                            som_prio:=som_prio+prio;\r
362                      fi;\r
363                    fi;\r
364 \r
365        if (sud_ouest) then deplacementcolonne:=-1;\r
366                      deplacementligne:=1;\r
367                      call direction(ligne,colonne,\r
368                                     deplacementcolonne,deplacementligne,\r
369                                     couleur,invcouleur,tab,nbpion);\r
370                      pionretourne:=pionretourne+nbpion;\r
371                      if (nbpion<>0) and (on_retourne_pion) then\r
372                            call retourne_pion(ligne,colonne,\r
373                            deplacementcolonne,deplacementligne,\r
374                            couleur,invcouleur,tab);\r
375                            tab(ligne,colonne):=couleur;\r
376                      fi;\r
377                      if (nbpion<>0) and (on_somme_prio) then\r
378                            call prio_pion_retourne(ligne,colonne,\r
379                            deplacementcolonne,deplacementligne,\r
380                            couleur,invcouleur,tab,gr_p,prio);\r
381                            som_prio:=som_prio+prio;\r
382                      fi;\r
383                    fi;\r
384 \r
385       if (nord_est) then deplacementcolonne:=1;\r
386                      deplacementligne:=-1;\r
387                      call direction(ligne,colonne,\r
388                                     deplacementcolonne,deplacementligne,\r
389                                     couleur,invcouleur,tab,nbpion);\r
390                      pionretourne:=pionretourne+nbpion;\r
391                      if (nbpion<>0) and (on_retourne_pion) then\r
392                            call retourne_pion(ligne,colonne,\r
393                            deplacementcolonne,deplacementligne,\r
394                            couleur,invcouleur,tab);\r
395                            tab(ligne,colonne):=couleur;\r
396                      fi;\r
397                      if (nbpion<>0) and (on_somme_prio) then\r
398                            call prio_pion_retourne(ligne,colonne,\r
399                            deplacementcolonne,deplacementligne,\r
400                            couleur,invcouleur,tab,gr_p,prio);\r
401                            som_prio:=som_prio+prio;\r
402                      fi;\r
403                    fi;\r
404 \r
405        if (sud_est) then deplacementcolonne:=1;\r
406                      deplacementligne:=1;\r
407                      call direction(ligne,colonne,\r
408                                     deplacementcolonne,deplacementligne,\r
409                                     couleur,invcouleur,tab,nbpion);\r
410                      pionretourne:=pionretourne+nbpion;\r
411                      if (nbpion<>0) and (on_retourne_pion) then\r
412                            call retourne_pion(ligne,colonne,\r
413                            deplacementcolonne,deplacementligne,\r
414                            couleur,invcouleur,tab);\r
415                            tab(ligne,colonne):=couleur;\r
416                      fi;\r
417                      if (nbpion<>0) and (on_somme_prio) then\r
418                            call prio_pion_retourne(ligne,colonne,\r
419                            deplacementcolonne,deplacementligne,\r
420                            couleur,invcouleur,tab,gr_p,prio);\r
421                            som_prio:=som_prio+prio;\r
422                      fi;\r
423                    fi;\r
424   end peut_on_poser_pion;\r
425 \r
426 unit joueur_humain : coroutine;\r
427 var i,j,x,y:integer;\r
428 begin\r
429  return;\r
430  do\r
431  call gotoxy(21,1);\r
432  if (rep='2')  then\r
433          if (pion=1) then\r
434          write("Joueur 1 : ");write(chr(27),"[33m");\r
435          writeln("Noir  x  ");write(chr(27),"[36m")\r
436          else\r
437          write("Joueur 2 : ");write(chr(27),"[32m");\r
438          writeln("Blanc o  ");write(chr(27),"[36m");\r
439          fi\r
440 else\r
441          if (rep='o') or (rep='O') then\r
442          write("Joueur : ");write(chr(27),"[33m");\r
443          writeln("Noir  x  ");write(chr(27),"[36m")\r
444          else\r
445          write("Joueur : ");write(chr(27),"[32m");\r
446          writeln("Blanc o  ");write(chr(27),"[36m");\r
447          fi;\r
448  fi;\r
449  call deplace;\r
450  lig:=ii;\r
451  col:=jj;\r
452  detach;\r
453  od;\r
454 end joueur_humain;\r
455 \r
456 unit depace_souris : procedure;\r
457    var x,y:integer;\r
458 begin\r
459 \r
460   pref mouse block;\r
461 \r
462   var o8,dx,dy,gk,h,v,p,b:integer,\r
463       l,r,c:boolean;\r
464   begin\r
465      o8 := 8;\r
466      b:=0;\r
467      call defcursor(1,11,12);\r
468      call showcursor;\r
469      call status(h,v,l,r,c);\r
470      do\r
471        call getpress(b,h,v,p,l,r,c);\r
472        if c\r
473        then\r
474          exit\r
475        fi;\r
476        if l\r
477        then\r
478          dx:=h / o8; dy := v / o8;\r
479          call gotoxy(dy+1,dx+1);\r
480          call SetPosition(h,v);\r
481          if ((dx+1>=4) and (dx+1<=42) and (dy+1>=3) and (dy+1<=18)) then\r
482           if (dx+1<>8) and (dx+1<>13) and(dx+1<>18) and(dx+1<>23)\r
483              and (dx+1<>28) and (dx+1<>33) and (dx+1<>38) then exit;\r
484           fi;\r
485          fi;\r
486        fi;\r
487        if r\r
488        then\r
489          call getpress(1,h,v,p,l,r,c);\r
490          dx :=h div o8;\r
491          dy :=v div o8;\r
492          call gotoxy(dy,dx);\r
493          arreter:=true;\r
494          call SetPosition(h,v); exit;\r
495        fi;\r
496      od;\r
497     x:=dx+1;\r
498     y:=dy+1;\r
499 \r
500     if (x>=4) and (x<=7) then x:=1; fi;\r
501     if (x>=9) and (x<=12) then x:=2; fi;\r
502     if (x>=14) and (x<=17) then x:=3; fi;\r
503     if (x>=19) and (x<=22) then x:=4; fi;\r
504     if (x>=24) and (x<=27) then x:=5; fi;\r
505     if (x>=29) and (x<=32) then x:=6; fi;\r
506     if (x>=34) and (x<=37) then x:=7; fi;\r
507     if (x>=39) and (x<=42) then x:=8; fi;\r
508     jj:=x;\r
509 \r
510     if (y>=3) and (y<=4) then y:=1; fi;\r
511     if (y>=5) and (y<=6) then y:=2; fi;\r
512     if (y>=7) and (y<=8) then y:=3; fi;\r
513     if (y>=9) and (y<=10) then y:=4; fi;\r
514     if (y>=11) and (y<=12) then y:=5; fi;\r
515     if (y>=13) and (y<=14) then y:=6; fi;\r
516     if (y>=15) and (y<=16) then y:=7; fi;\r
517     if (y>=17) and (y<=18) then y:=8; fi;\r
518     ii:=y;\r
519 \r
520   end (* mouse *)\r
521 \r
522 end depace_souris;\r
523 \r
524 \r
525 \r
526 \r
527 \r
528 unit joueur_humain_souris : coroutine;\r
529 var i,j,x,y:integer;\r
530 begin\r
531  return;\r
532  do\r
533  call gotoxy(21,1);\r
534  if (rep='2')  then\r
535          if (pion=1) then\r
536          write("Joueur 1 : ");write(chr(27),"[33m");\r
537          writeln("Noir  x  ");write(chr(27),"[36m")\r
538          else\r
539          write("Joueur 2 : ");write(chr(27),"[32m");\r
540          writeln("Blanc o  ");write(chr(27),"[36m");\r
541          fi\r
542 else\r
543          if (rep='o') or (rep='O') then\r
544          write("Joueur : ");write(chr(27),"[33m");\r
545          writeln("Noir  x  ");write(chr(27),"[36m")\r
546          else\r
547          write("Joueur : ");write(chr(27),"[32m");\r
548          writeln("Blanc o  ");write(chr(27),"[36m");\r
549          fi;\r
550  fi;\r
551 \r
552 \r
553   call depace_souris;\r
554 \r
555  lig:=ii;\r
556  col:=jj;\r
557  detach;\r
558  od;\r
559 end joueur_humain_souris;\r
560 \r
561 \r
562 unit copie_tableau:procedure(input t1:arrayof arrayof integer;\r
563                              inout t2:arrayof arrayof integer);\r
564 var i,j:integer;\r
565 begin\r
566 \r
567    for i:=1 to 8\r
568     do\r
569      for j:=1 to 8\r
570       do\r
571        t2(i,j):=t1(i,j);\r
572       od;\r
573     od;\r
574 end copie_tableau;\r
575 \r
576 \r
577 unit prio_pion_retourne:procedure(ligne,colonne:integer;\r
578                            deplacementcolonne,deplacementligne:integer;\r
579                            couleur,invcouleur:integer;\r
580                            tab,gr_prio:arrayof arrayof integer;\r
581                            output som_prio : integer);\r
582   begin\r
583       som_prio:=0;\r
584       do\r
585        colonne:=colonne+deplacementcolonne;\r
586        ligne:=ligne+deplacementligne;\r
587 \r
588        if (tab(ligne,colonne)=couleur) then\r
589         (* case de meme couleur *)\r
590         exit;\r
591        fi;\r
592 \r
593        if (tab(ligne,colonne)=invcouleur) then\r
594         (* case de couleur inverse *)\r
595         (* on somme la priorite du pion qu'on peut retourner *)\r
596         som_prio:=som_prio+gr_prio(ligne,colonne);\r
597        fi;\r
598       od;\r
599   end prio_pion_retourne;\r
600 \r
601 unit cherche_pion_a_poser:procedure(input couleur:integer;\r
602                                     input tab:arrayof arrayof integer;\r
603                                     inout coup:arrayof arrayof integer;\r
604                                     inout nb_coup:integer);\r
605   var i,j,k,l,nb:integer;\r
606   var on_retourne_pion:boolean;\r
607   var som_prio:integer;\r
608   var tab_2:arrayof arrayof integer;\r
609   var invcouleur,max,som_adverse:integer;\r
610   begin\r
611    array tab_2 dim (1:8);\r
612    for i:=1 to 8\r
613     do\r
614      array tab_2(i) dim (1:8);\r
615     od;\r
616    if (couleur=1) then invcouleur:=2 else invcouleur:=1;fi;\r
617    on_retourne_pion:=false;\r
618    nb_coup:=0;\r
619    for i:=1 to 8\r
620     do\r
621      for j:=1 to 8\r
622       do\r
623        if tab(i,j)=0 then\r
624         call copie_tableau(tab,tab_2);\r
625 \r
626         (* simule notre coup *)\r
627         call peut_on_poser_pion(i,j,couleur,tab_2,on_retourne_pion,true,nb,som_prio);\r
628         if nb<>0 then nb_coup:=nb_coup+1;\r
629                       coup(nb_coup,1):=i; (* ligne *)\r
630                       coup(nb_coup,2):=j; (* colonne *)\r
631                       coup(nb_coup,3):=nb; (* pions retourn\82s *)\r
632                       coup(nb_coup,4):=gr_p(i,j); (* priorit\82 du pion pos\82 *)\r
633                       coup(nb_coup,5):=som_prio;  (* priorit\82 pions retourn\82s *)\r
634         (* pose et retourne*)\r
635 \r
636         call peut_on_poser_pion(i,j,couleur,tab_2,true,false,nb,som_prio);\r
637         (* simule le coup adverse *)\r
638                       max:=-1000;\r
639                       for k:=1 to 8\r
640                        do\r
641                        for l:=1 to 8\r
642                          do\r
643                          if tab_2(k,l)=0 then\r
644 call peut_on_poser_pion(k,l,invcouleur,tab_2,false,true,nb,som_prio);\r
645                           if nb<>0 then\r
646                            som_adverse:=2*nb+7*gr_p(k,l)+som_prio;\r
647                            if max<som_adverse then max:=som_adverse;fi;\r
648                           fi;\r
649                          fi;\r
650                          od;\r
651                        od;\r
652                       coup(nb_coup,6):=max;\r
653 \r
654         fi;\r
655         fi;\r
656       od;\r
657     od;\r
658 kill(tab_2);\r
659   end cherche_pion_a_poser;\r
660 \r
661 unit remp_gr_prio:procedure(output gr_prio:arrayof arrayof integer);\r
662 var i,j:integer;\r
663 begin\r
664 array gr_prio dim (1:8);\r
665    for i:=1 to 8\r
666     do\r
667      array gr_prio(i) dim (1:8);\r
668     od;\r
669 gr_prio(1,1):=20;\r
670 gr_prio(1,8):=20;\r
671 gr_prio(8,1):=20;\r
672 gr_prio(8,8):=20;\r
673 gr_prio(1,3):=14;\r
674 gr_prio(1,6):=14;\r
675 gr_prio(8,3):=14;\r
676 gr_prio(8,6):=14;\r
677 gr_prio(3,1):=14;\r
678 gr_prio(6,1):=14;\r
679 gr_prio(3,8):=14;\r
680 gr_prio(6,8):=14;\r
681 gr_prio(1,4):=12;\r
682 gr_prio(1,5):=12;\r
683 gr_prio(8,4):=12;\r
684 gr_prio(8,5):=12;\r
685 gr_prio(4,1):=12;\r
686 gr_prio(5,1):=12;\r
687 gr_prio(4,8):=12;\r
688 gr_prio(5,8):=12;\r
689 gr_prio(1,2):=9;\r
690 gr_prio(1,7):=9;\r
691 gr_prio(8,2):=9;\r
692 gr_prio(8,7):=9;\r
693 gr_prio(2,1):=9;\r
694 gr_prio(7,1):=9;\r
695 gr_prio(2,8):=9;\r
696 gr_prio(7,8):=9;\r
697 gr_prio(3,3):=6;\r
698 gr_prio(3,6):=6;\r
699 gr_prio(6,3):=6;\r
700 gr_prio(6,6):=6;\r
701 gr_prio(3,4):=4;\r
702 gr_prio(3,5):=4;\r
703 gr_prio(6,4):=4;\r
704 gr_prio(6,5):=4;\r
705 gr_prio(4,3):=4;\r
706 gr_prio(5,3):=4;\r
707 gr_prio(4,6):=4;\r
708 gr_prio(5,6):=4;\r
709 gr_prio(2,3):=2;\r
710 gr_prio(2,4):=2;\r
711 gr_prio(2,5):=2;\r
712 gr_prio(2,6):=2;\r
713 gr_prio(7,3):=2;\r
714 gr_prio(7,4):=2;\r
715 gr_prio(7,5):=2;\r
716 gr_prio(7,6):=2;\r
717 gr_prio(3,2):=2;\r
718 gr_prio(4,2):=2;\r
719 gr_prio(5,2):=2;\r
720 gr_prio(6,2):=2;\r
721 gr_prio(3,7):=2;\r
722 gr_prio(4,7):=2;\r
723 gr_prio(5,7):=2;\r
724 gr_prio(6,7):=2;\r
725 gr_prio(2,2):=1;\r
726 gr_prio(2,7):=1;\r
727 gr_prio(7,2):=1;\r
728 gr_prio(7,7):=1;\r
729 gr_prio(4,4):=2;\r
730 gr_prio(4,5):=2;\r
731 gr_prio(5,4):=2;\r
732 gr_prio(5,5):=2;\r
733 end remp_gr_prio;\r
734 \r
735 unit modifie_gr_prio : procedure(rep2 : char);\r
736 begin\r
737 \r
738 (* changement des priorites *)\r
739 (* on le coin haut-gauche *)\r
740 if rep2='1' or rep2='2' or rep2='3' or rep2='4' then\r
741 gr_p(1,2):=16;\r
742 gr_p(2,1):=16;\r
743 gr_p(8,1):=15;\r
744 gr_p(1,3):=15;\r
745 gr_p(2,2):=15;\r
746 gr_p(4,1):=13;\r
747 gr_p(1,4):=13;\r
748 gr_p(2,3):=13;\r
749 gr_p(3,2):=13;\r
750 fi;\r
751 \r
752 (* on le coin haut-droit *)\r
753 if rep2='2' or rep2='3' or rep2='4' then\r
754 gr_p(1,7):=16;\r
755 gr_p(2,8):=16;\r
756 gr_p(3,8):=15;\r
757 gr_p(1,6):=15;\r
758 gr_p(2,7):=15;\r
759 gr_p(4,8):=13;\r
760 gr_p(1,5):=13;\r
761 gr_p(2,6):=13;\r
762 gr_p(3,7):=13;\r
763 fi;\r
764 \r
765 (* on le coin bas-droit *)\r
766 if rep2='3' or rep2='4' then\r
767 gr_p(8,7):=16;\r
768 gr_p(7,8):=16;\r
769 gr_p(6,8):=15;\r
770 gr_p(8,6):=15;\r
771 gr_p(7,7):=15;\r
772 gr_p(5,8):=13;\r
773 gr_p(8,5):=13;\r
774 gr_p(7,6):=13;\r
775 gr_p(6,7):=13;\r
776 fi;\r
777 \r
778 (* on le coin bas-gauche *)\r
779 if rep2='4' then\r
780 gr_p(7,1):=16;\r
781 gr_p(8,2):=16;\r
782 gr_p(8,3):=15;\r
783 gr_p(7,2):=15;\r
784 gr_p(6,1):=15;\r
785 gr_p(8,4):=13;\r
786 gr_p(7,3):=13;\r
787 gr_p(6,2):=13;\r
788 gr_p(5,1):=13;\r
789 fi;\r
790 \r
791 end modifie_gr_prio;\r
792 \r
793 \r
794 unit joueur_machine : coroutine;\r
795 var i,j,nb_point,nb_coup,max_pion_retourne,pion :integer;\r
796 var coup : arrayof arrayof integer;\r
797 begin\r
798 array coup dim (1:60);\r
799 for i:=1 to 60\r
800  do\r
801   array coup(i) dim (1:7);\r
802  od;\r
803 return;\r
804 do\r
805 call gotoxy(21,1);\r
806 if (rep='n') or (rep='N') then\r
807 write("Machine : ");write(chr(27),"[33m");\r
808 writeln("Noir  x");write(chr(27),"[36m")\r
809 else\r
810 write("Machine : ");write(chr(27),"[32m");\r
811 writeln("Blanc o");write(chr(27),"[36m");\r
812 fi;\r
813 \r
814 nb_point:=0;\r
815 (* recherche des cases ou l'on peut jouer *)\r
816 if (rep='o') or (rep='O') then pion:=2 else pion:=1 fi;\r
817 call cherche_pion_a_poser(pion,plateau,coup,nb_coup);\r
818 \r
819 (*faire la somme des priorit\82*)\r
820 for i:=1 to nb_coup do\r
821  coup(i,7):=coup(i,3)*2+coup(i,4)*5+coup(i,5)-coup(i,6);\r
822                     od;\r
823 (* choix de la meilleure case *)\r
824 max_pion_retourne:=-1000;\r
825 for i:= 1 to nb_coup\r
826  do\r
827   if coup(i,7)>max_pion_retourne then max_pion_retourne:=coup(i,7);\r
828                                       lig:=coup(i,1);\r
829                                       col:=coup(i,2);\r
830   fi;\r
831  od;\r
832 ii:=lig;\r
833 jj:=col;\r
834 (* changement des priorites *)\r
835 (* on le coin haut-gauche *)\r
836 if lig=1 and col=1 then\r
837 gr_p(1,2):=16;\r
838 gr_p(2,1):=16;\r
839 gr_p(8,1):=15;\r
840 gr_p(1,3):=15;\r
841 gr_p(2,2):=15;\r
842 gr_p(4,1):=13;\r
843 gr_p(1,4):=13;\r
844 gr_p(2,3):=13;\r
845 gr_p(3,2):=13;\r
846 fi;\r
847 \r
848 (* on le coin haut-droit *)\r
849 if lig=1 and col=8 then\r
850 gr_p(1,7):=16;\r
851 gr_p(2,8):=16;\r
852 gr_p(3,8):=15;\r
853 gr_p(1,6):=15;\r
854 gr_p(2,7):=15;\r
855 gr_p(4,8):=13;\r
856 gr_p(1,5):=13;\r
857 gr_p(2,6):=13;\r
858 gr_p(3,7):=13;\r
859 fi;\r
860 \r
861 (* on le coin bas-droit *)\r
862 if lig=8 and col=8 then\r
863 gr_p(8,7):=16;\r
864 gr_p(7,8):=16;\r
865 gr_p(6,8):=15;\r
866 gr_p(8,6):=15;\r
867 gr_p(7,7):=15;\r
868 gr_p(5,8):=13;\r
869 gr_p(8,5):=13;\r
870 gr_p(7,6):=13;\r
871 gr_p(6,7):=13;\r
872 fi;\r
873 \r
874 (* on le coin bas-gauche *)\r
875 if lig=8 and col=1 then\r
876 gr_p(7,1):=16;\r
877 gr_p(8,2):=16;\r
878 gr_p(8,3):=15;\r
879 gr_p(7,2):=15;\r
880 gr_p(6,1):=15;\r
881 gr_p(8,4):=13;\r
882 gr_p(7,3):=13;\r
883 gr_p(6,2):=13;\r
884 gr_p(5,1):=13;\r
885 fi;\r
886 \r
887 \r
888 xx:=lig*2+2;\r
889 yy:=col*5;\r
890 call gotoxy(xx,yy);\r
891 detach;\r
892 od;\r
893 end joueur_machine;\r
894 \r
895 unit compte_pion:procedure(input tab:arrayof arrayof integer;\r
896                            output nb_pion_blanc,nb_pion_noir:integer);\r
897 var i,j:integer;\r
898   begin\r
899    nb_pion_blanc:=0;\r
900    nb_pion_noir:=0;\r
901    for i:=1 to 8\r
902      do\r
903      for j:=1 to 8\r
904       do\r
905        if (tab(i,j)=1) then nb_pion_noir:=nb_pion_noir+1;fi;\r
906        if (tab(i,j)=2) then nb_pion_blanc:=nb_pion_blanc+1;fi;\r
907       od;\r
908     od;\r
909 end compte_pion;\r
910 \r
911 unit aff_nb_pion:procedure;\r
912 begin\r
913  call gotoxy(3,55);\r
914  writeln("ÚÄÄÄÄÄÄÄ¿");\r
915  call gotoxy(4,55);\r
916  writeln("³ SCORE ³");\r
917  call gotoxy(5,55);\r
918  writeln("ÀÄÄÄÄÄÄÄÙ");\r
919  call gotoxy(6,46);\r
920  write("Nombre de pions ");write(chr(27),"[33m");\r
921  write("noir  ");write(chr(27),"[36m");write(": ");\r
922  write(chr(27),"[33m");write(nb_pion_noir);write(chr(27),"[36m");\r
923  call gotoxy(8,46);\r
924  write("Nombre de pions ");write(chr(27),"[32m");\r
925  write("blanc ");write(chr(27),"[36m");write(": ");\r
926  write(chr(27),"[32m");write(nb_pion_blanc);write(chr(27),"[36m");\r
927  call gotoxy(xx,yy);\r
928 end aff_nb_pion;\r
929 \r
930 \r
931 (***********************************************************************)\r
932 (************************ Programme Principal **************************)\r
933 (***********************************************************************)\r
934 \r
935 var plateau,gr_p:arrayof arrayof integer;\r
936 var nb,nb_case_vide:integer;\r
937 var joueur1,joueur2:joueur_humain;\r
938 var joueur1_s,joueur2_s:joueur_humain_souris;\r
939 var joueur3:joueur_machine;\r
940 var col,lig,i,xx,yy,ii,jj:integer;\r
941 var pion,nb_pion_blanc,nb_pion_noir:integer;\r
942 var nb_noir_poser,nb_blanc_poser:integer;\r
943 var sec1,sec2:integer;\r
944 var arreter:boolean;\r
945 var bidon,rep,rep2:char;\r
946 var som_prio:integer;\r
947 var souris:boolean;\r
948 \r
949 begin\r
950  call newpage;\r
951  write(chr(27),"[31m");\r
952  call gotoxy(10,19);\r
953  writeln("ÚÄÄÄÄ¿ ÄÄÂÄÄ ³    ³ ÚÄÄÄÄ ³     ³     ÚÄÄÄÄ¿ ");\r
954  call gotoxy(11,19);\r
955  writeln("³    ³   ³   ÃÄÄÄÄ´ ÃÄÄ   ³     ³     ³    ³ ");\r
956  call gotoxy(12,19);\r
957  writeln("ÀÄÄÄÄÙ   ³   ³    ³ ÀÄÄÄÄ ÀÄÄÄÄ ÀÄÄÄÄ ÀÄÄÄÄÙ ");\r
958  call gotoxy(17,33);\r
959  write(chr(27),"[36m");\r
960  writeln("Presented by");\r
961  call gotoxy(22,11);\r
962  write(chr(27),"[32m");\r
963  writeln("Defeuillet Patrick - Gosset V\82ronique - Dupin Christophe");\r
964  call pause(2);\r
965  do\r
966  write(chr(27),"[36m");\r
967  arreter:=false;\r
968  ii:=1;\r
969  jj:=1;\r
970  xx:=4;\r
971  yy:=5;\r
972  rep := ' ';\r
973  while (rep <> 'o') and (rep <> 'n') and (rep <> 'O') and (rep <> 'N')\r
974  do\r
975   call newpage;\r
976  call gotoxy(8,1);\r
977  writeln("                   Avez_vous une souris (O ou N) ? ");\r
978  writeln;\r
979  write("                            Votre choix : ");\r
980  readln(rep);\r
981  od;\r
982 if (rep='o') or (rep='O') then souris:=true;\r
983 else souris:=false;\r
984 fi;\r
985  while (rep <> '1') and (rep <> '2')\r
986  do\r
987  call newpage;\r
988  call gotoxy(3,20);\r
989  writeln("ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ ");\r
990  call gotoxy(4,20);\r
991  writeln("³    PREPARATION DU JEU    ³ ");\r
992  call gotoxy(5,20);\r
993  writeln("ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ ");\r
994  call gotoxy(8,1);\r
995  writeln("               1 - UN   joueur");\r
996  writeln("               2 - DEUX joueurs ");\r
997  writeln;\r
998  write("                            Votre choix : ");\r
999  readln(rep);\r
1000  od;\r
1001  rep2:=' ';\r
1002  while rep2<>'0' and rep2<>'1' and rep2<>'2' and rep2<>'3' and rep2<>'4'\r
1003  do\r
1004   call gotoxy(13,1);\r
1005   writeln("          Les noirs commencent avec combien de coin(s) (0 \85 4) ? ");\r
1006   writeln;\r
1007   write("                            Votre choix : ");\r
1008   readln(rep2);\r
1009  od;\r
1010   call initialisegrille(plateau);\r
1011   if rep2='0' then nb_case_vide:=60;fi;\r
1012   if rep2='1' then nb_case_vide:=59;plateau(1,1):=1;fi;\r
1013   if rep2='2' then nb_case_vide:=58;plateau(1,1):=1;plateau(1,8):=1;fi;\r
1014   if rep2='3' then nb_case_vide:=57;plateau(1,1):=1;plateau(1,8):=1;\r
1015                    plateau(8,1):=1;fi;\r
1016   if rep2='4' then nb_case_vide:=56;plateau(1,1):=1;plateau(1,8):=1;\r
1017                    plateau(8,1):=1;plateau(8,8):=1;fi;\r
1018  if rep = '1' then while (rep <> 'O') and (rep <> 'N') and (rep <> 'o') and (rep <> 'n')\r
1019                  do\r
1020                  call gotoxy(18,1);\r
1021                  writeln("               Voulez_vous commencer (O ou N) ?");\r
1022                  writeln;\r
1023                  write("                             Votre choix :  ");\r
1024                  readln(rep);\r
1025                  od;\r
1026                  if (rep = 'O') or (rep='o') then\r
1027                  if souris then\r
1028                   joueur1_s := new joueur_humain_souris\r
1029                  else\r
1030                   joueur1 := new joueur_humain;\r
1031                  fi;\r
1032                  joueur3 := new joueur_machine;\r
1033                  else\r
1034                  joueur3 := new joueur_machine;\r
1035                  if souris then\r
1036                   joueur2_s := new joueur_humain_souris\r
1037                  else\r
1038                   joueur2 := new joueur_humain;\r
1039                  fi;\r
1040                  fi;\r
1041  else\r
1042   if souris then\r
1043       joueur1_s := new joueur_humain_souris;\r
1044       joueur2_s := new joueur_humain_souris;\r
1045   else\r
1046       joueur1 := new joueur_humain;\r
1047       joueur2 := new joueur_humain;\r
1048   fi;\r
1049  fi;\r
1050 \r
1051 \r
1052  call remp_gr_prio(gr_p);\r
1053  if ((rep2<>'0') and (rep='n' or rep='N')) then\r
1054   call modifie_gr_prio(rep2);\r
1055  fi;\r
1056  call affichecadre;\r
1057  call affichegrille(plateau);\r
1058  call compte_pion(plateau,nb_pion_blanc,nb_pion_noir);\r
1059  call aff_nb_pion;\r
1060 \r
1061 do\r
1062   call nb_de_pion_a_poser(1,plateau,false,nb_noir_poser,som_prio);\r
1063   if nb_noir_poser=0 then if nb_case_vide<>0 then\r
1064                           call gotoxy(10,46);\r
1065                           writeln("Les noirs ne peuvent pas jouer !");\r
1066                           call  gotoxy(xx,yy);\r
1067                           call pause(2);\r
1068                           call gotoxy(10,46);\r
1069                           writeln("                                ");\r
1070                           call gotoxy(xx,yy);fi;\r
1071   fi;\r
1072   if nb_noir_poser<>0 then\r
1073    do\r
1074     (* pion noir *)\r
1075     pion:=1;\r
1076     if (rep='2') or (rep = 'O') or (rep = 'o') then sec1:=1;\r
1077       if souris then attach(joueur1_s) else attach(joueur1);fi;\r
1078     fi;\r
1079     if (rep = 'N') or (rep = 'n') then sec1:=2;attach(joueur3);fi;\r
1080     if arreter then exit fi;\r
1081     if plateau(lig,col)=0 then\r
1082     call peut_on_poser_pion(lig,col,pion,plateau,true,false,nb,som_prio);\r
1083     if nb<>0 then nb_case_vide:=nb_case_vide-1;exit;fi;\r
1084     fi;\r
1085    od;\r
1086    if arreter then exit fi;\r
1087    write(chr(27),"[33m");\r
1088    call gotoxy(4+2*(ii-1),5+5*(jj-1));\r
1089    write("x");\r
1090    write(chr(27),"[36m");\r
1091    call pause(sec1);\r
1092    call affichegrille(plateau);\r
1093    call compte_pion(plateau,nb_pion_blanc,nb_pion_noir);\r
1094    if nb_pion_blanc=0 then exit;fi;\r
1095    call aff_nb_pion;\r
1096   fi;\r
1097 \r
1098   if (nb_blanc_poser=0) and (nb_noir_poser=0) then exit;fi;\r
1099   call nb_de_pion_a_poser(2,plateau,false,nb_blanc_poser,som_prio);\r
1100   if nb_blanc_poser=0 then if nb_case_vide<>0 then\r
1101                            call gotoxy(10,46);\r
1102                            writeln("Les blancs ne peuvent pas jouer !");\r
1103                            call  gotoxy(xx,yy);\r
1104                            call pause(2);\r
1105                            call gotoxy(10,46);\r
1106                            writeln("                                 ");\r
1107                            call  gotoxy(xx,yy);fi;\r
1108   fi;\r
1109   if nb_blanc_poser<>0 then\r
1110    do\r
1111     (* pion blanc *)\r
1112     pion:=2;\r
1113     if (rep='2') or (rep = 'N') or (rep = 'n') then sec2:=1;\r
1114        if souris then attach(joueur2_s) else attach(joueur2);fi;\r
1115     fi;\r
1116     if (rep = 'O') or (rep = 'o') then sec2:=2;attach(joueur3);fi;\r
1117     if arreter then exit fi;\r
1118     if plateau(lig,col)=0 then\r
1119     call peut_on_poser_pion(lig,col,pion,plateau,true,false,nb,som_prio);\r
1120     if nb<>0 then nb_case_vide:=nb_case_vide-1;exit;fi;\r
1121     fi;\r
1122    od;\r
1123    if arreter then exit fi;\r
1124    write(chr(27),"[32m");\r
1125    call gotoxy(4+2*(ii-1),5+5*(jj-1));\r
1126    write("o");\r
1127    write(chr(27),"[36m");\r
1128    call pause(sec2);\r
1129    call affichegrille(plateau);\r
1130    call compte_pion(plateau,nb_pion_blanc,nb_pion_noir);\r
1131    if nb_pion_noir=0 then exit;fi;\r
1132    call aff_nb_pion;\r
1133   fi;\r
1134 \r
1135   if (nb_blanc_poser=0) and (nb_noir_poser=0) then exit;fi;\r
1136   if nb_case_vide=0 then exit;fi;\r
1137  od;\r
1138 \r
1139 if not arreter then\r
1140 call aff_nb_pion;\r
1141 call gotoxy(13,54);\r
1142 writeln("FIN DE LA PARTIE");\r
1143 call compte_pion(plateau,nb_pion_blanc,nb_pion_noir);\r
1144 if nb_pion_blanc=nb_pion_noir then call gotoxy(16,46);\r
1145                                    writeln("        Match nul !");fi;\r
1146 if nb_pion_blanc<nb_pion_noir then\r
1147  call gotoxy(15,46);\r
1148  writeln("Les noirs gagnent la partie avec ");\r
1149  call gotoxy(16,46);\r
1150  writeln(nb_pion_noir," pions noirs contre ");\r
1151  call gotoxy(17,46);\r
1152  writeln(nb_pion_blanc," pions blancs.");\r
1153 fi;\r
1154 if nb_pion_blanc>nb_pion_noir then\r
1155  call gotoxy(15,46);\r
1156  writeln("Les blancs gagnent la partie avec ");\r
1157  call gotoxy(16,46);\r
1158  writeln(nb_pion_blanc," pions blancs contre ");\r
1159  call gotoxy(17,46);\r
1160  writeln(nb_pion_noir," pions noirs.");\r
1161 fi;\r
1162 \r
1163 (* destruction des coroutines *)\r
1164 if (rep = 'O') orif (rep = 'o') then\r
1165   kill (joueur1);\r
1166   kill (joueur3);\r
1167 fi;\r
1168 if (rep = 'N') orif (rep = 'n') then\r
1169   kill (joueur3);\r
1170   kill (joueur2);\r
1171 fi;\r
1172 if (rep ='2') then\r
1173   kill (joueur1);\r
1174   kill (joueur2);\r
1175 fi;\r
1176 \r
1177 call gotoxy(19,54);\r
1178 write(chr(27),"[33m");\r
1179 writeln("- Faites Retour - ");\r
1180 read(bidon);\r
1181 fi;\r
1182 call newpage;\r
1183 call normal;\r
1184 rep := ' ';\r
1185  while (rep <> 'o') and (rep <> 'n') and (rep <> 'O') and (rep <> 'N')\r
1186  do\r
1187   call newpage;\r
1188  call gotoxy(8,1);\r
1189  writeln("              Voulez_vous faire une autre partie (O ou N) ? ");\r
1190  writeln;\r
1191  write("                             Votre choix : ");\r
1192  readln(rep);\r
1193  od;\r
1194 if rep='n' or rep='N' then exit;fi;\r
1195 od;\r
1196 call newpage;\r
1197 write(chr(27),"[33m");\r
1198 call gotoxy(9,25);\r
1199 writeln("ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ ");\r
1200 call gotoxy(10,25);\r
1201 writeln("³                          ³ ");\r
1202 call gotoxy(11,25);\r
1203 writeln("³       P A     P A !      ³ ");\r
1204 call gotoxy(12,25);\r
1205 writeln("³                          ³ ");\r
1206 call gotoxy(13,25);\r
1207 writeln("ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ ");\r
1208 call pause(1);\r
1209 call normal;\r
1210 call newpage;\r
1211 end othello\1a