Tic tac toe

Fermé
stephanblaw Messages postés 8 Date d'inscription vendredi 21 décembre 2012 Statut Membre Dernière intervention 12 mars 2013 - 18 janv. 2013 à 12:34
Bonjour,
je suis entraîne de programmer le jeu du morpion en pascal , j'ai fais un petit effort (débutant ) mais après quelques procédure je me suis coincé et voila mon petit code ,
si quelqu'un pouvais m'aider a continuer svp et merci d'avance
program tictactoe ;
uses crt;
type
ini_mat = array[1..3,1..3] of char;
var
v:ini_mat;
w:string[2];
m,b1:char;
t,p,s1,s2:1..3;
o1,o2,o3,o,u:boolean;
nom1,nom2:string;

procedure ini;
var
i,j :integer;
BEGIN
for i:=1 to 3 do
for j:=1 to 3 do
v[i,j]:='.';
m:='.';
END;
procedure affiche(a:string);
var
i,j,k,l : integer;
n :char;

BEGIN
clrscr;
n:='A';
writeln('1':9,'2':6,'3':6);
for i:=1 to 3 do
BEGIN
writeln;
write(n:3,'I':3);
n:=succ(n);
for j:=1 to 3 do
write(v[i,j]:3,'I':3);
writeln;write(' ':5); for k:=1 to 19 do write('-');
END;
for l:=1 to 3 do writeln;
writeln(a);
END;
function lecture :boolean;
VAR t,s,q:integer;
y,n,r:boolean;
BEGIN
readln(w);
s:=ord(w[1]);
q:=ord(w[2]);
n:=(( (s<=67) and (s>=65) ) or ( (s<=51) and (s>=49) ));
r:=(( (s<=67) and (q>=65) ) or ( (q<=51) and (q>=49) ));
if (n and r) then y := true
else y:= false;

lecture:=y;

END;
function calcul:boolean;
VAR a,b,c:integer;
d,t1:boolean;
BEGIN
for c:=1 to 2 do
case w[c] of
'1' : b:=1;
'2' : b:=2;
'3' : b:=3;
'A' : a:=1;
'B' : a:=2;
'C' : a:=3;
END;
if v[a,b]='.' then BEGIN v[a,b]:=m; t1:=true; END
else t1:=false;
calcul:=t1;
END;
function calcul_ordi:boolean;
VAR a,b,c:integer;
d,t1:boolean;
BEGIN
randomize;
a:=random(3);b:=random(3);
if v[a+1,b+1]='.' then BEGIN v[a+1,b+1]:=m; t1:=true; END
else t1:=false;
calcul_ordi:=t1;

END;
function calcul_ulti:boolean;
VAR c1,c2,e1,e2,d1,d2 : integer;
p1,p2,p3,p4,p5,f,g,h,r1,r2,r3: boolean;
BEGIN
p1:=true;
p2:=true;
p3:=true;
p4:=true;
for c1:=1 to 3 do
BEGIN
p1:=true;
f:=(v[1,c1]=v[2,c1]);
g:=(v[1,c1]=v[3,c1]);
h:=(v[2,c1]=v[3,c1]);
if ((v[1,c1]='.') and (v[2,c1]='.')) or
((v[1,c1]='.') and (v[3,c1]='.')) or
((v[3,c1]='.') and (v[2,c1]='.')) or
((v[1,c1]<>'.') and (v[2,c1]<>'.') and (v[3,c1]<>'.'))
then p1:=false ;
if p1 then
BEGIN
for d1:=1 to 3 do
BEGIN
if not (((v[1,d1]='.') and (v[2,d1]='.')) or
((v[1,d1]='.') and (v[3,d1]='.')) or
((v[3,d1]='.') and (v[2,d1]='.')) or
((v[1,d1]<>'.') and (v[2,d1]<>'.') and (v[3,d1]<>'.')))
then BEGIN
r1:=(v[1,d1]=m) and (v[2,d1]=m);
r2:=(v[1,d1]=m) and (v[3,d1]=m);
r3:=(v[2,d1]=m) and (v[3,d1]=m);
if r1 then v[3,d1]:=m
else if r2 then v[2,d1]:=m
else if r3 then v[1,d1]:=m
else BEGIN r1:=false; r2:=false; r3:=false; END;
if r1 or r2 or r3 then break;
END;
END;
if (r1=false) and (r2=false) and (r3=false) then
BEGIN
if f then v[3,c1]:=m
else if g then v[2,c1]:=m
else if h then v[1,c1]:=m
else p1:=false;
END;
if f or (g or h) then break;
END;
END;
for c2:=1 to 3 do
BEGIN
if p1 then p2:=false else p2:=true;
f:=(v[c2,1]=v[c2,2]);
g:=(v[c2,1]=v[c2,3]);
h:=(v[c2,2]=v[c2,3]);
if ((v[c2,1]='.') and (v[c2,2]='.')) or
((v[c2,1]='.') and (v[c2,3]='.')) or
((v[c2,3]='.') and (v[c2,2]='.')) or
((v[c2,1]<>'.') and (v[c2,2]<>'.') and (v[c2,3]<>'.'))
then p2:=false ;
if p2 then
BEGIN
for d2:=1 to 3 do
BEGIN
if not (((v[1,d2]='.') and (v[2,d2]='.')) or
((v[1,d2]='.') and (v[3,d2]='.')) or
((v[3,d2]='.') and (v[2,d2]='.')) or
((v[1,d2]<>'.') and (v[2,d2]<>'.') and (v[3,d2]<>'.')))
then BEGIN
r1:=(v[d2,1]=m) and (v[d2,2]=m);
r2:=(v[d2,1]=m) and (v[d2,3]=m);
r3:=(v[d2,2]=m) and (v[d2,3]=m);
if r1 then v[d2,3]:=m
else if r2 then v[d2,2]:=m
else if r3 then v[d2,1]:=m
else BEGIN r1:=false; r2:=false; r3:=false; END;
if r1 or r2 or r3 then break;
END;
END;
if (r1=false) and (r2=false) and (r3=false) then
BEGIN
if f then v[c2,3]:=m
else if g then v[c2,2]:=m
else if h then v[c2,1]:=m
else p2:=false;
END;
if f or (g or h) then break;
END;
END;
if p1 or p2 then p3:=false else p3:=true;
if ((v[1,1]='.') and (v[2,2]='.')) or
((v[3,3]='.') and (v[2,2]='.')) or
((v[1,1]='.') and (v[3,3]='.')) or
((v[1,1]<>'.') and (v[2,2]<>'.') and (v[3,3]<>'.'))
then p3:=false ;
if p3 then
BEGIN
r1:=(v[1,1]=m) and (v[2,2]=m);
r2:=(v[1,1]=m) and (v[3,3]=m);
r3:=(v[2,2]=m) and (v[3,3]=m);
f:=(v[1,1]=v[2,2]);
g:=(v[1,1]=v[3,3]);
h:=(v[2,2]=v[3,3]);
if r1 then v[3,3]:=m
else if r2 then v[2,2]:=m
else if r3 then v[1,1]:=m
else if f then v[3,3]:=m
else if g then v[2,2]:=m
else if h then v[1,1]:=m
else p3:=false ;

END;

if (p1 or p2) or p3 then p4:=false else p4:=true;
if ((v[1,3]='.') and (v[3,1]='.')) or
((v[1,3]='.') and (v[2,2]='.')) or
((v[2,2]='.') and (v[3,1]='.')) or
((v[1,3]<>'.') and (v[3,1]<>'.') and (v[2,2]<>'.'))
then p4:=false;
if p4 then
BEGIN
r1:=(v[1,3]=m) and (v[2,2]=m);
r2:=(v[1,3]=m) and (v[3,1]=m);
r3:=(v[2,2]=m) and (v[3,1]=m);
f:=(v[1,3]=v[2,2]);
g:=(v[1,3]=v[3,1]);
h:=(v[2,2]=v[3,1]);
if r1 then v[3,1]:=m
else if r2 then v[2,2]:=m
else if r3 then v[1,3]:=m
else if f then v[3,1]:=m
else if g then v[2,2]:=m
else if h then v[1,3]:=m else p4:=false;
END;
p5:=(p1 or p2) or (p3 or p4);
calcul_ulti:=p5;
END;