沙发
fxzxg [专家分:430] 发布于 2005-12-17 16:36:00
var
p:array[-1..5,-1..5] of boolean;
q:array[-1..5,-1..5] of char;
i,j,x,r,m,l,o:integer;
n:char;
a,b,c,d:array[1..24]of integer;
procedure print;
forward;
procedure du;
var
i,j,k,m:integer;
label 1,2;
begin
k:=0;
writeln(' What do you want ? (1,2,3,4,5,6,7,8,9) ');
1:k:=0;
read(m);
for i:=1 to 3 do
for j:=1 to 3 do
begin
k:=k+1;
if k=m then goto 2;
end;
2: if (m<1) or (m>9) or (p[i,j]=false) then begin writeln('Please input again');goto 1; end;
p[i,j]:=false;
q[i,j]:='o';
x:=1;
print;
end;
procedure computer;
var
y:boolean;
i,j,k,m,n:integer;
begin
o:=o+1;
writeln(' Computer is :');
k:=0;j:=0;i:=0;m:=0;n:=0;
for i:=1 to 3 do
for j:=1 to 3 do
begin
k:=0;
if p[i,j] then
for m:=1 to 12 do
begin
y:=true;
for n:=1 to 2 do
begin
k:=k+1;
if q[i+a[k],j+b[k]]<>'x' then y:=false;
end;
if y then begin p[i,j]:=false;q[i,j]:='x';x:=2;print;exit;end;
end;
end;
k:=0;i:=0;j:=0;m:=0;n:=0;
for i:=1 to 3 do
for j:=1 to 3 do
begin
k:=0;
if p[i,j] then
for m:=1 to 12 do
begin
y:= true;
for n:=1 to 2 do
begin
k:=k+1;
if q[i+a[k],j+b[k]]<>'o' then y:=false;
end;
if y then begin p[i,j]:=false;q[i,j]:='x';x:=2;print;exit; end;
end;
end;
if o=2 then begin
if (q[2,2]='x') and ((q[1,1]='o') and (q[3,3]='o')) or ((q[1,3]='o') and (q[3,1]='o'))
then begin p[1,2]:=false;q[1,2]:='x';x:=2;print;exit;end;
if (q[2,2]='o') and (q[3,3]='o') then begin p[1,3]:=false;q[1,3]:='x';x:=2;print;exit;end;
if (q[1,1]='o') and (q[3,2]='o') then begin p[3,1]:=false;q[3,1]:='x';x:=2;print;exit;end;
if (q[1,1]='o') and (q[2,3]='o') then begin p[1,3]:=false;q[1,3]:='x';x:=2;print;exit;end;
if (q[1,3]='o') and (q[2,1]='o') then begin p[1,1]:=false;q[1,1]:='x';x:=2;print;exit;end;
if (q[1,3]='o') and (q[3,2]='o') then begin p[3,3]:=false;q[3,3]:='x';x:=2;print;exit;end;
if (q[3,1]='o') and (q[1,2]='o') then begin p[1,1]:=false;q[1,1]:='x';x:=2;print;exit;end;
if (q[3,1]='o') and (q[2,3]='o') then begin p[3,3]:=false;q[3,3]:='x';x:=2;print;exit;end;
if (q[3,3]='o') and (q[2,1]='o') then begin p[3,1]:=false;q[3,1]:='x';x:=2;print;exit;end;
if (q[3,3]='o') and (q[1,2]='o') then begin p[1,3]:=false;q[1,3]:='x';x:=2;print;exit;end;
end;
if p[2,2] then begin p[2,2]:=false;q[2,2]:='x';x:=2;print;exit;end else
if p[1,1] then begin p[1,1]:=false;q[1,1]:='x';x:=2;print;exit;end;
if p[1,3] then begin p[1,3]:=false;q[1,3]:='x';x:=2;print;exit;end;
if p[3,1] then begin p[3,1]:=false;q[3,1]:='x';x:=2;print;exit;end;
if p[3,3] then begin p[3,3]:=false;q[3,3]:='x';x:=2;print;exit;end;
for i:=1 to 3 do
for j:=1 to 3 do
if p[i,j] then
for m:=1 to 8 do
if q[i+c[m],j+d[m]]='x' then begin p[i,j]:=false;q[i,j]:='x';x:=2;print;exit;end;
i:=0;j:=0;
for i:=1 to 3 do
for j:=1 to 3 do
if p[i,j] then begin p[i,j]:=false;q[i,j]:='x';x:=2;print;exit;end;
end;
procedure print;
var
g,h,d,f:boolean;
i,j,k,l,m:integer;
begin
r:=r+1;
for i:=1 to 3 do
begin
for j:=1 to 3 do
if p[i,j]=false then write(q[i,j]:2) else write('-':2);
writeln;
writeln;
end;
for l:=1 to 3 do
begin
g:=true;
d:=true;
h:=true;
f:=true;
for m:=1 to 3 do
begin
if q[l,m]<>'o' then g:=false;
if q[m,l]<>'o' then d:=false;
if q[l,m]<>'x' then h:=false;
if q[m,l]<>'x' then f:=false;
end;
if h then begin writeln('Computer is winer !');halt end;
if f then begin writeln('Computer is winer !');halt end;
if g then begin writeln('You are winer !');halt end;
if d then begin writeln('You are winer !');halt end;
end;
if (q[1,1]='x')and (q[2,2]='x') and (q[3,3]='x') then begin writeln ('Computer is winer !');halt end;
if (q[1,3]='x')and (q[2,2]='x') and (q[3,1]='x') then begin writeln ('Computer is winer !');halt end;
if (q[1,1]='o')and (q[2,2]='o') and (q[3,3]='o') then begin writeln ('You are winer !');halt end;
if (q[1,3]='o')and (q[2,2]='o') and (q[3,1]='o') then begin writeln ('You are winer !');halt end;
if r=9 then begin writeln('Nobody is winer');halt;end;
if x=1 then computer else du;
end;
begin
a[1]:=1;a[2]:=2;b[3]:=1;b[4]:=2;a[5]:=-1;a[6]:=-2;b[7]:=-1;b[8]:=-2;
a[9]:=1;b[9]:=1;a[10]:=2;b[10]:=2;a[11]:=1;b[11]:=-1;a[12]:=2;b[12]:=-2;
a[13]:=-1;b[13]:=1;a[14]:=-2;b[14]:=2;a[15]:=-1;b[15]:=-1;a[16]:=-2;b[16]:=-2;
a[17]:=-1;a[18]:=1;b[19]:=-1;b[20]:=1;a[21]:=-1;b[21]:=-1;a[22]:=1;b[22]:=1;
a[23]:=-1;b[23]:=1;a[24]:=1;b[24]:=-1;c[1]:=-1;c[2]:=1;d[3]:=-1;d[4]:=1;
c[5]:=-1;d[5]:=-1;c[6]:=-1;d[6]:=1;c[7]:=1;d[7]:=-1;c[8]:=1;d[8]:=1;
for m:=-1 to 5 do
for l:=-1 to 5 do
p[m,l]:=true;
writeln('Do you want play first ? (Y / N)');
read(n);
if (n='y') or (n='Y') then du else computer;
end.