3 UNIT NEWPAGE : procedure;
\r
5 write( chr(27), "[2J")
\r
8 UNIT gotoxy : procedure (row, column : integer);
\r
9 var c, d, e, f : char,
\r
20 write (chr(27), "[", c, d, ";", e, f, "H");
\r
23 unit Normal : procedure;
\r
25 write( chr(27), "[0m")
\r
28 UNIT INCHAR : IIuwgraph function : integer;
\r
32 if i <> 0 then exit fi;
\r
37 unit pause:procedure(input seconde:integer);
\r
40 for temps:=1 to (9000*seconde) do od;
\r
44 var g:arrayof arrayof integer;
\r
50 array g(i) dim (1:8);
\r
54 unit initialisegrille : procedure(inout gr: arrayof arrayof integer);
\r
57 (* creation de la grille *)
\r
61 array gr(i) dim (1:8);
\r
63 (* initialisation de la grille *)
\r
65 (* 1 case avec pion noir *)
\r
66 (* 2 case avec pion blanc *)
\r
74 (* for j:=1 to 8 do gr(8,j):=0 od;*)
\r
79 end initialisegrille;
\r
81 unit affichecadre:procedure;
\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
105 writeln("ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ ");
\r
106 writeln("³ D
\82placement : Souris ³ Valider : Bouton 1 ³ Quitter : Bouton 3 ³ ");
\r
107 writeln("ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ ");
\r
109 writeln("ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ ");
\r
110 writeln("³ D
\82placement : Fl
\8aches ³ Valider : RETURN ³ Quitter : ECHAP ³ ");
\r
111 writeln("ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ ");
\r
116 unit affichegrille : procedure(input gr: arrayof arrayof integer);
\r
118 (* 1 case avec pion noir *)
\r
119 (* 2 case avec pion blanc *)
\r
120 var i,j,v,w:integer;
\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
139 unit deplace:procedure;
\r
140 var touche,bidon:integer;
\r
142 call gotoxy(xx,yy);
\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
153 call gotoxy(xx,yy);
\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
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
175 if (tab(ligne,colonne)=invcouleur) then
\r
176 (* case de couleur inverse *)
\r
180 if (tab(ligne,colonne))=0 then
\r
186 if (tab(ligne,colonne)=couleur) then
\r
187 (* case de meme couleur *)
\r
192 if not(retourne) then nbpion:=0;fi;
\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
201 colonne:=colonne+deplacementcolonne;
\r
202 ligne:=ligne+deplacementligne;
\r
204 if (tab(ligne,colonne)=couleur) then
\r
205 (* case de meme couleur *)
\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
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
224 nb_pion_a_poser:=0;
\r
225 on_retourne_pion:=false;
\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
236 end nb_de_pion_a_poser;
\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
250 if (couleur=1) then invcouleur:=2 else invcouleur:=1;fi;
\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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
424 end peut_on_poser_pion;
\r
426 unit joueur_humain : coroutine;
\r
427 var i,j,x,y:integer;
\r
434 write("Joueur 1 : ");write(chr(27),"[33m");
\r
435 writeln("Noir x ");write(chr(27),"[36m")
\r
437 write("Joueur 2 : ");write(chr(27),"[32m");
\r
438 writeln("Blanc o ");write(chr(27),"[36m");
\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
445 write("Joueur : ");write(chr(27),"[32m");
\r
446 writeln("Blanc o ");write(chr(27),"[36m");
\r
456 unit depace_souris : procedure;
\r
462 var o8,dx,dy,gk,h,v,p,b:integer,
\r
467 call defcursor(1,11,12);
\r
469 call status(h,v,l,r,c);
\r
471 call getpress(b,h,v,p,l,r,c);
\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
489 call getpress(1,h,v,p,l,r,c);
\r
492 call gotoxy(dy,dx);
\r
494 call SetPosition(h,v); exit;
\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
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
528 unit joueur_humain_souris : coroutine;
\r
529 var i,j,x,y:integer;
\r
536 write("Joueur 1 : ");write(chr(27),"[33m");
\r
537 writeln("Noir x ");write(chr(27),"[36m")
\r
539 write("Joueur 2 : ");write(chr(27),"[32m");
\r
540 writeln("Blanc o ");write(chr(27),"[36m");
\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
547 write("Joueur : ");write(chr(27),"[32m");
\r
548 writeln("Blanc o ");write(chr(27),"[36m");
\r
553 call depace_souris;
\r
559 end joueur_humain_souris;
\r
562 unit copie_tableau:procedure(input t1:arrayof arrayof integer;
\r
563 inout t2:arrayof arrayof integer);
\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
585 colonne:=colonne+deplacementcolonne;
\r
586 ligne:=ligne+deplacementligne;
\r
588 if (tab(ligne,colonne)=couleur) then
\r
589 (* case de meme couleur *)
\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
599 end prio_pion_retourne;
\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
611 array tab_2 dim (1:8);
\r
614 array tab_2(i) dim (1:8);
\r
616 if (couleur=1) then invcouleur:=2 else invcouleur:=1;fi;
\r
617 on_retourne_pion:=false;
\r
624 call copie_tableau(tab,tab_2);
\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
636 call peut_on_poser_pion(i,j,couleur,tab_2,true,false,nb,som_prio);
\r
637 (* simule le coup adverse *)
\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
646 som_adverse:=2*nb+7*gr_p(k,l)+som_prio;
\r
647 if max<som_adverse then max:=som_adverse;fi;
\r
652 coup(nb_coup,6):=max;
\r
659 end cherche_pion_a_poser;
\r
661 unit remp_gr_prio:procedure(output gr_prio:arrayof arrayof integer);
\r
664 array gr_prio dim (1:8);
\r
667 array gr_prio(i) dim (1:8);
\r
735 unit modifie_gr_prio : procedure(rep2 : char);
\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
752 (* on le coin haut-droit *)
\r
753 if rep2='2' or rep2='3' or rep2='4' then
\r
765 (* on le coin bas-droit *)
\r
766 if rep2='3' or rep2='4' then
\r
778 (* on le coin bas-gauche *)
\r
791 end modifie_gr_prio;
\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
798 array coup dim (1:60);
\r
801 array coup(i) dim (1:7);
\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
810 write("Machine : ");write(chr(27),"[32m");
\r
811 writeln("Blanc o");write(chr(27),"[36m");
\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
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
823 (* choix de la meilleure case *)
\r
824 max_pion_retourne:=-1000;
\r
825 for i:= 1 to nb_coup
\r
827 if coup(i,7)>max_pion_retourne then max_pion_retourne:=coup(i,7);
\r
834 (* changement des priorites *)
\r
835 (* on le coin haut-gauche *)
\r
836 if lig=1 and col=1 then
\r
848 (* on le coin haut-droit *)
\r
849 if lig=1 and col=8 then
\r
861 (* on le coin bas-droit *)
\r
862 if lig=8 and col=8 then
\r
874 (* on le coin bas-gauche *)
\r
875 if lig=8 and col=1 then
\r
890 call gotoxy(xx,yy);
\r
893 end joueur_machine;
\r
895 unit compte_pion:procedure(input tab:arrayof arrayof integer;
\r
896 output nb_pion_blanc,nb_pion_noir:integer);
\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
911 unit aff_nb_pion:procedure;
\r
914 writeln("ÚÄÄÄÄÄÄÄ¿");
\r
916 writeln("³ SCORE ³");
\r
918 writeln("ÀÄÄÄÄÄÄÄÙ");
\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
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
931 (***********************************************************************)
\r
932 (************************ Programme Principal **************************)
\r
933 (***********************************************************************)
\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
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
966 write(chr(27),"[36m");
\r
973 while (rep <> 'o') and (rep <> 'n') and (rep <> 'O') and (rep <> 'N')
\r
977 writeln(" Avez_vous une souris (O ou N) ? ");
\r
979 write(" Votre choix : ");
\r
982 if (rep='o') or (rep='O') then souris:=true;
\r
983 else souris:=false;
\r
985 while (rep <> '1') and (rep <> '2')
\r
989 writeln("ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ ");
\r
991 writeln("³ PREPARATION DU JEU ³ ");
\r
993 writeln("ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ ");
\r
995 writeln(" 1 - UN joueur");
\r
996 writeln(" 2 - DEUX joueurs ");
\r
998 write(" Votre choix : ");
\r
1002 while rep2<>'0' and rep2<>'1' and rep2<>'2' and rep2<>'3' and rep2<>'4'
\r
1004 call gotoxy(13,1);
\r
1005 writeln(" Les noirs commencent avec combien de coin(s) (0
\85 4) ? ");
\r
1007 write(" Votre choix : ");
\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
1020 call gotoxy(18,1);
\r
1021 writeln(" Voulez_vous commencer (O ou N) ?");
\r
1023 write(" Votre choix : ");
\r
1026 if (rep = 'O') or (rep='o') then
\r
1028 joueur1_s := new joueur_humain_souris
\r
1030 joueur1 := new joueur_humain;
\r
1032 joueur3 := new joueur_machine;
\r
1034 joueur3 := new joueur_machine;
\r
1036 joueur2_s := new joueur_humain_souris
\r
1038 joueur2 := new joueur_humain;
\r
1043 joueur1_s := new joueur_humain_souris;
\r
1044 joueur2_s := new joueur_humain_souris;
\r
1046 joueur1 := new joueur_humain;
\r
1047 joueur2 := new joueur_humain;
\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
1056 call affichecadre;
\r
1057 call affichegrille(plateau);
\r
1058 call compte_pion(plateau,nb_pion_blanc,nb_pion_noir);
\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
1068 call gotoxy(10,46);
\r
1070 call gotoxy(xx,yy);fi;
\r
1072 if nb_noir_poser<>0 then
\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
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
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
1090 write(chr(27),"[36m");
\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
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
1105 call gotoxy(10,46);
\r
1107 call gotoxy(xx,yy);fi;
\r
1109 if nb_blanc_poser<>0 then
\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
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
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
1127 write(chr(27),"[36m");
\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
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
1139 if not arreter then
\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
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
1163 (* destruction des coroutines *)
\r
1164 if (rep = 'O') orif (rep = 'o') then
\r
1168 if (rep = 'N') orif (rep = 'n') then
\r
1172 if (rep ='2') then
\r
1177 call gotoxy(19,54);
\r
1178 write(chr(27),"[33m");
\r
1179 writeln("- Faites Retour - ");
\r
1185 while (rep <> 'o') and (rep <> 'n') and (rep <> 'O') and (rep <> 'N')
\r
1189 writeln(" Voulez_vous faire une autre partie (O ou N) ? ");
\r
1191 write(" Votre choix : ");
\r
1194 if rep='n' or rep='N' then exit;fi;
\r
1197 write(chr(27),"[33m");
\r
1198 call gotoxy(9,25);
\r
1199 writeln("ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ ");
\r
1200 call gotoxy(10,25);
\r
1202 call gotoxy(11,25);
\r
1203 writeln("³ P A P A ! ³ ");
\r
1204 call gotoxy(12,25);
\r
1206 call gotoxy(13,25);
\r
1207 writeln("ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ ");
\r