program danh_co;
uses crt;
type mang=array[1..75,1..23] of char;
var a,b,a1,b1,i,j,g,g1,u,u1:longint;
move,key:char;
free:mang;
procedure ve(free:mang;u,u1:longint;key:char);
var i,j:longint;
begin
if key='1'then begin
i:=9;
while i<=15 do
begin j:=9;
while j<=15 do
begin
if free[i,j]<>'|' then free[i,j]:='.';
j:=j+2;
end;
i:=i+2;
end;
for i:=9 to 15 do
for j:=9 to 15 do
begin
if (free[i,j]='_')or(free[i,j]='|')or(free[i,j]='.')then textcolor(15);
if free[i,j]='x' then textcolor(12);
if free[i,j]='o' then textcolor(11);
gotoxy(i,j);write(free[i,j]);
end;
gotoxy(2,22);write('Ban:',u,' May:',u1);
gotoxy(15,23);write('An "p" de quay lai');
end;
if key='2'then begin
i:=9;
while i<=19 do
begin j:=9;
while j<=19 do
begin
if free[i,j]<>'|' then free[i,j]:='.';
j:=j+2;
end;
i:=i+2;
end;
for i:=9 to 19 do
for j:=9 to 19 do
begin
if (free[i,j]='_')or(free[i,j]='|')or(free[i,j]='.')then textcolor(15);
if free[i,j]='x' then textcolor(12);
if free[i,j]='o' then textcolor(11);
gotoxy(i,j);write(free[i,j]);
end;
gotoxy(2,22);write('Ban:',u,' May:',u1);
gotoxy(15,23);write('An "p" de quay lai');
end;
if key='3'then begin
i:=1;
while i<=21 do
begin j:=1;
while j<=21 do
begin
if free[i,j]<>'|' then free[i,j]:='.';
j:=j+2;
end;
i:=i+2;
end;
for i:=1 to 21 do
for j:=1 to 21 do
begin
if (free[i,j]='_')or(free[i,j]='|')or(free[i,j]='.')then textcolor(15);
if free[i,j]='x' then textcolor(12);
if free[i,j]='o' then textcolor(11);
gotoxy(i,j);write(free[i,j]);
end;
gotoxy(2,22);write('Ban:',u,' May:',u1);
gotoxy(15,23);write('An "p" de quay lai');
end;
end;
function tontai(free:mang;key:char):boolean;
var i,j,d:longint;
begin
i:=8; tontai:=true;
if key='1'then
while i<14 do
begin i:=i+2;j:=8;
while j<14 do
begin j:=j+2;d:=0;
if free[i-1,j]in['.','|','_'] then inc(d);
if free[i+1,j]in['.','|','_'] then inc(d);
if free[i,j-1]in['.','|','_'] then inc(d);
if free[i,j+1]in['.','|','_'] then inc(d);
if d=3 then exit(false);
end;
end;
if key='2'then
while i<18 do
begin i:=i+2;j:=8;
while j<18 do
begin j:=j+2;d:=0;
if free[i-1,j]in['.','|','_'] then inc(d);
if free[i+1,j]in['.','|','_'] then inc(d);
if free[i,j-1]in['.','|','_'] then inc(d);
if free[i,j+1]in['.','|','_'] then inc(d);
if d=3 then exit(false);
end;
end;
if key='3'then begin
i:=0;
while i<20 do
begin i:=i+2;j:=0;
while j<20 do
begin j:=j+2;d:=0;
if free[i-1,j]in['.','|','_'] then inc(d);
if free[i+1,j]in['.','|','_'] then inc(d);
if free[i,j-1]in['.','|','_'] then inc(d);
if free[i,j+1]in['.','|','_'] then inc(d);
if d=3 then exit(false);
end;
end;
end;
end;
procedure menu(free:mang;u,u1:longint);
var a,b,a1,b1,i,j,g,g1,d,d1,x,y,x1,y1,w1,min:longint;
move,key:char;
free1:mang;
begin clrscr;
writeln(' [1]:Bat dau');
writeln(' [2]:Huong dan');
writeln(' [3]:Thoat');
write('Chon:');key:=readkey;
if key='3'then halt;
if key='2'then
begin clrscr;
writeln('An cac phim a,d,s,w de di chuyen con tro chuot.');
writeln('Di chuyen con tro chuot vao giua cac cham roi an phim "b" de noi');
writeln('cac dau cham lai voi nhau.');
writeln;
write('An Enter de quay lai>>');
readln;
end;
if key='1'then
begin clrscr;
writeln('Ban chon che do nao');
writeln(' [1]:3x3');
writeln(' [2]:5x5');
writeln(' [3]:10x10');
write('Chon:');key:=readkey;
end;
{che do 3x3}
if key='1' then begin
a:=9;b:=9;a1:=9;b1:=9;u:=0;u1:=0;
{reset lai ban do}
for i:=9 to 15 do
for j:=9 to 15 do
if free[i,j]<>','then free[i,j]:=' ';
{Luot cua Ban}
while u+u1<9 do
begin clrscr;
ve(free,u,u1,key);
move:='\';g:=1;
while (move<>'b')and(g=1) do
begin gotoxy(10,17);write('Luot cua Ban');
gotoxy(a,b); g:=0;
move:=readkey;
case move of
'a':begin a:=a-1;if a<=8 then inc(a);gotoxy(a,b);g:=1; end;
'd':begin a:=a+1;if a>=16 then dec(a);gotoxy(a,b);g:=1; end;
'w':begin b:=b-1;if b<=8 then inc(b);gotoxy(a,b);g:=1; end;
's':begin b:=b+1;if b>=16 then dec(b);gotoxy(a,b);g:=1; end;
'b':begin if ((b mod 2=0)and(a mod 2<>0))or((b mod 2<>0)and(a mod 2=0)) then
if b mod 2=0 then begin free[a,b]:='|';free[a,b+1]:='|';end
else free[a,b]:='_' else move:='/';
if (free[a,b]='|') then
begin
if a>=3 then if (free[a-2,b]='|')and(free[a-1,b-1]='_')and(free[a-1,b+1]='_')then begin g:=1;inc(u);free[a-1,b]:='x';move:='\';end;
if (free[a+2,b]='|')and(free[a+1,b-1]='_')and(free[a+1,b+1]='_')then begin g:=1;inc(u);free[a+1,b]:='x';move:='\';end;
end;
if free[a,b]='_' then
begin
if (free[a-1,b+1]='|')and(free[a,b+2]='_')and(free[a+1,b+1]='|')then begin g:=1;inc(u);free[a,b+1]:='x';move:='\';end;
if b>=3 then if (free[a-1,b-1]='|')and(free[a,b-2]='_')and(free[a+1,b-1]='|')then begin g:=1;inc(u);free[a,b-1]:='x';move:='\';end;
end;
if ((a mod 2<>0)and(b mod 2<>0))or((a mod 2=0)and(b mod 2=0))then begin move:='/';g:=1; end;
end;
'p':menu(free,u,u1);
else begin move:='\';g:=1;end;
end;
ve(free,u,u1,key);
if u+u1>=9 then break;
end;
{Luot cua May}
g1:=1;
while (g1=1)and(u+u1<=9) do
begin gotoxy(10,17);write('Luot cua May. ');delay(500);
gotoxy(10,17);write('Luot cua May.. ');delay(500);
gotoxy(10,17);write('Luot cua May...');delay(500);
i:=8;g1:=0;d1:=u1;
while (i<14)and(u+u1<=9) do
begin j:=8; i:=i+2;
while (j<14)and(u+u1<=9) do
begin j:=j+2;d:=0;
if free[i-1,j]in['.','|','_'] then inc(d);
if free[i+1,j]in['.','|','_'] then inc(d);
if free[i,j-1]in['.','|','_'] then inc(d);
if free[i,j+1]in['.','|','_'] then inc(d);
if d=3 then
begin g1:=1;inc(u1);
if not(free[i-1,j]in['.','|','_']) then
begin
free[i-1,j]:='|';free[i-1,j+1]:='|';free[i,j]:='o';
end;
if not(free[i+1,j]in['.','|','_']) then
begin
free[i+1,j]:='|';free[i+1,j+1]:='|';free[i,j]:='o';
end;
if not(free[i,j-1]in['.','|','_']) then
begin
free[i,j-1]:='_';free[i,j]:='o';
end;
if not(free[i,j+1]in['.','|','_']) then
begin
free[i,j+1]:='_';free[i,j]:='o';
end;
if d=3 then break;
end ;
if d=3 then break;
end;
if d=3 then break;
end;
ve(free,u,u1,key);
if d1=u1 then begin
i:=8;g1:=0;d1:=0;x:=0;
while (i<14)and(u+u1<=9) do
begin j:=8; i:=i+2;
while (j<14)and(u+u1<=9) do
begin j:=j+2;d:=0;
if free[i-1,j]in['.','|','_'] then inc(d);
if free[i+1,j]in['.','|','_'] then inc(d);
if free[i,j-1]in['.','|','_'] then inc(d);
if free[i,j+1]in['.','|','_'] then inc(d);
if d<2 then
begin
if not(free[i-1,j]in['.','|','_']) then
begin x:=0;
free[i-1,j]:='|';free[i-1,j+1]:='|';
if not(tontai(free,key))then begin free[i-1,j]:=' ';free[i-1,j+1]:=' ';x:=6;end else break;
end ;
if not(free[i+1,j]in['.','|','_']) then
begin x:=0;
free[i+1,j]:='|';free[i+1,j+1]:='|';
if not(tontai(free,key))then begin free[i+1,j]:=' ';free[i+1,j+1]:=' ';x:=6;end else break;
end ;
if not(free[i,j-1]in['.','|','_']) then
begin x:=0;
free[i,j-1]:='_';
if not(tontai(free,key))then begin free[i,j-1]:=' ';x:=6;end else break;
end ;
if not(free[i,j+1]in['.','|','_']) then
begin x:=0;
free[i,j+1]:='_';
if not(tontai(free,key))then begin free[i,j+1]:=' ';x:=6;end else break;
end;
if (d<2)and(x<>6)then break;
end;
if (d=2)or(d=4)then inc(d1);
if (d<2)and(x<>6)then break;
end;
if (d<2)and(x<>6)then break;
end;
if (d<2)and(x<>6)then break;
end;
ve(free,u,u1,key);
if d1=9 then begin
i:=8;
while i<14 do
begin i:=i+2; j:=8;
while j<14 do
begin j:=j+2; d:=0;
if free[i-1,j]in['.','|','_'] then inc(d);
if free[i+1,j]in['.','|','_'] then inc(d);
if free[i,j-1]in['.','|','_'] then inc(d);
if free[i,j+1]in['.','|','_'] then inc(d);
if d=2 then begin
if not(free[i-1,j]in['.','|','_']) then
begin
free[i-1,j]:='|';free[i-1,j+1]:='|';
end else
if not(free[i+1,j]in['.','|','_']) then
begin
free[i+1,j]:='|';free[i+1,j+1]:='|';
end else
if not(free[i,j-1]in['.','|','_']) then
begin
free[i,j-1]:='_';
end else
if not(free[i,j+1]in['.','|','_']) then
begin
free[i,j+1]:='_';
end;
break;
end;
if d=2 then break;
end;
if d=2 then break;
end;
if d=2 then break;
end;
if d=2 then break;
i:=8; u1:=0;
while i<14 do
begin i:=i+2; j:=8;
while j<14 do
begin j:=j+2;d:=0;
if free[i-1,j]in['.','|','_'] then inc(d);
if free[i+1,j]in['.','|','_'] then inc(d);
if free[i,j-1]in['.','|','_'] then inc(d);
if free[i,j+1]in['.','|','_'] then inc(d);
if (free[i,j]<>'x')and(d=4)then begin free[i,j]:='o';inc(u1);end;
end;
end;
end;{ket thuc luot danh cua May}
if u+u1>=9 then
begin
if u>u1 then begin gotoxy(10,8);write('Ban thang');end;
if u<u1 then begin gotoxy(10,8);write('Ban thua');end;
gotoxy(10,23);write('An Enter de quay lai>>>');readln;
end;
end;{ket thuc khi danh het}
end;{ket thuc 3x3}
{che do 5x5}
if key='2' then begin
a:=9;b:=9;u:=0;u1:=0;
{reset lai ban do}
for i:=9 to 19 do
for j:=9 to 19 do
if free[i,j]<>','then free[i,j]:=' ';
{Luot cua Ban}
while u+u1<25 do
begin clrscr;
ve(free,u,u1,key);
move:='\';g:=1;
while (move<>'b')and(g=1) do
begin gotoxy(18,22);write('Luot cua Ban');
gotoxy(a,b); g:=0;
move:=readkey;
case move of
'a':begin a:=a-1;if a<=8 then inc(a);gotoxy(a,b);g:=1; end;
'd':begin a:=a+1;if a>=20 then dec(a);gotoxy(a,b);g:=1; end;
'w':begin b:=b-1;if b<=8 then inc(b);gotoxy(a,b);g:=1; end;
's':begin b:=b+1;if b>=20 then dec(b);gotoxy(a,b);g:=1; end;
'b':begin if ((b mod 2=0)and(a mod 2<>0))or((b mod 2<>0)and(a mod 2=0)) then
if b mod 2=0 then begin free[a,b]:='|';free[a,b+1]:='|';end
else free[a,b]:='_' else move:='/';
if (free[a,b]='|') then
begin
if a>=3 then if (free[a-2,b]='|')and(free[a-1,b-1]='_')and(free[a-1,b+1]='_')then begin g:=1;inc(u);free[a-1,b]:='x';move:='\';end;
if (free[a+2,b]='|')and(free[a+1,b-1]='_')and(free[a+1,b+1]='_')then begin g:=1;inc(u);free[a+1,b]:='x';move:='\';end;
end;
if free[a,b]='_' then
begin
if (free[a-1,b+1]='|')and(free[a,b+2]='_')and(free[a+1,b+1]='|')then begin g:=1;inc(u);free[a,b+1]:='x';move:='\';end;
if b>=3 then if (free[a-1,b-1]='|')and(free[a,b-2]='_')and(free[a+1,b-1]='|')then begin g:=1;inc(u);free[a,b-1]:='x';move:='\';end;
end;
if ((a mod 2<>0)and(b mod 2<>0))or((a mod 2=0)and(b mod 2=0))then begin move:='/';g:=1; end;
end;
'p':menu(free,u,u1);
else begin move:='\';g:=1;end;
end;
ve(free,u,u1,key);
if u+u1>=25 then break;
end;
{Luot cua May}
g1:=1;
while (g1=1)and(u+u1<=25) do
begin gotoxy(10,17);write('Luot cua May. ');delay(500);
gotoxy(10,17);write('Luot cua May.. ');delay(500);
gotoxy(10,17);write('Luot cua May...');delay(500);
i:=8;g1:=0;d1:=u1;
while (i<18)and(u+u1<=25) do
begin j:=8; i:=i+2;
while (j<18)and(u+u1<=25) do
begin j:=j+2;d:=0;
if free[i-1,j]in['.','|','_'] then inc(d);
if free[i+1,j]in['.','|','_'] then inc(d);
if free[i,j-1]in['.','|','_'] then inc(d);
if free[i,j+1]in['.','|','_'] then inc(d);
if d=3 then
begin g1:=1;inc(u1);
if not(free[i-1,j]in['.','|','_']) then
begin
free[i-1,j]:='|';free[i-1,j+1]:='|';free[i,j]:='o';
end;
if not(free[i+1,j]in['.','|','_']) then
begin
free[i+1,j]:='|';free[i+1,j+1]:='|';free[i,j]:='o';
end;
if not(free[i,j-1]in['.','|','_']) then
begin
free[i,j-1]:='_';free[i,j]:='o';
end;
if not(free[i,j+1]in['.','|','_']) then
begin
free[i,j+1]:='_';free[i,j]:='o';
end;
if d=3 then break;
end ;
if d=3 then break;
end;
if d=3 then break;
end;
ve(free,u,u1,key);
if d1=u1 then begin
i:=8;g1:=0;d1:=0;x:=0;
while (i<18)and(u+u1<=25) do
begin j:=8; i:=i+2;
while (j<18)and(u+u1<=25) do
begin j:=j+2;d:=0;
if free[i-1,j]in['.','|','_'] then inc(d);
if free[i+1,j]in['.','|','_'] then inc(d);
if free[i,j-1]in['.','|','_'] then inc(d);
if free[i,j+1]in['.','|','_'] then inc(d);
if d<2 then
begin
if not(free[i-1,j]in['.','|','_']) then
begin x:=0;
free[i-1,j]:='|';free[i-1,j+1]:='|';
if not(tontai(free,key))then begin free[i-1,j]:=' ';free[i-1,j+1]:=' ';x:=6;end else break;
end ;
if not(free[i+1,j]in['.','|','_']) then
begin x:=0;
free[i+1,j]:='|';free[i+1,j+1]:='|';
if not(tontai(free,key))then begin free[i+1,j]:=' ';free[i+1,j+1]:=' ';x:=6;end else break;
end ;
if not(free[i,j-1]in['.','|','_']) then
begin x:=0;
free[i,j-1]:='_';
if not(tontai(free,key))then begin free[i,j-1]:=' ';x:=6;end else break;
end ;
if not(free[i,j+1]in['.','|','_']) then
begin x:=0;
free[i,j+1]:='_';
if not(tontai(free,key))then begin free[i,j+1]:=' ';x:=6;end else break;
end;
if (d<2)and(x<>6)then break;
end;
if (d=2)or(d=4)then inc(d1);
if (d<2)and(x<>6)then break;
end;
if (d<2)and(x<>6)then break;
end;
if (d<2)and(x<>6)then break;
end;
ve(free,u,u1,key);
if d1=25 then begin
i:=8;
while i<18 do
begin i:=i+2; j:=8;
while j<18 do
begin j:=j+2; d:=0;
if free[i-1,j]in['.','|','_'] then inc(d);
if free[i+1,j]in['.','|','_'] then inc(d);
if free[i,j-1]in['.','|','_'] then inc(d);
if free[i,j+1]in['.','|','_'] then inc(d);
if d=2 then begin
if not(free[i-1,j]in['.','|','_']) then
begin
free[i-1,j]:='|';free[i-1,j+1]:='|';
end else
if not(free[i+1,j]in['.','|','_']) then
begin
free[i+1,j]:='|';free[i+1,j+1]:='|';
end else
if not(free[i,j-1]in['.','|','_']) then
begin
free[i,j-1]:='_';
end else
if not(free[i,j+1]in['.','|','_']) then
begin
free[i,j+1]:='_';
end;
break
end;
if d=2 then break;
end;
if d=2 then break;
end;
if d=2 then break;
end;
if d=2 then break;
i:=8; u1:=0;
while i<18 do
begin i:=i+2; j:=8;
while j<18 do
begin j:=j+2;d:=0;
if free[i-1,j]in['.','|','_'] then inc(d);
if free[i+1,j]in['.','|','_'] then inc(d);
if free[i,j-1]in['.','|','_'] then inc(d);
if free[i,j+1]in['.','|','_'] then inc(d);
if (free[i,j]<>'x')and(d=4)then begin free[i,j]:='o';inc(u1);end;
end;
end;
end;{ket thuc luot danh cua May}
if u+u1>=25 then
begin
if u>u1 then begin gotoxy(10,8);write('Ban thang');end;
if u<u1 then begin gotoxy(10,8);write('Ban thua');end;
gotoxy(10,23);write('An Enter de quay lai>>>');readln;
end;
end;{ket thuc khi danh het}
end;{ket thuc 5x5}
{che do 10x10}
if key='3' then begin
a:=2;b:=2;u:=0;u1:=0;
{reset lai ban do}
for i:=1 to 21 do
for j:=1 to 21 do
if free[i,j]<>','then free[i,j]:=' ';
{Luot cua Ban}
while u+u1<100 do
begin clrscr;
ve(free,u,u1,key);
move:='\';g:=1;
while (move<>'b')and(g=1) do
begin gotoxy(18,22);write('Luot cua Ban');
gotoxy(a,b); g:=0;
move:=readkey;
case move of
'a':begin a:=a-1;if a<=0 then inc(a);gotoxy(a,b);g:=1; end;
'd':begin a:=a+1;if a>=22 then dec(a);gotoxy(a,b);g:=1; end;
'w':begin b:=b-1;if b<=0 then inc(b);gotoxy(a,b);g:=1; end;
's':begin b:=b+1;if b>=22 then dec(b);gotoxy(a,b);g:=1; end;
'b':begin if ((b mod 2=0)and(a mod 2<>0))or((b mod 2<>0)and(a mod 2=0)) then
if b mod 2=0 then begin free[a,b]:='|';free[a,b+1]:='|';end
else free[a,b]:='_' else move:='/';
if (free[a,b]='|') then
begin
if a>=3 then if (free[a-2,b]='|')and(free[a-1,b-1]='_')and(free[a-1,b+1]='_')then begin g:=1;inc(u);free[a-1,b]:='x';move:='\';end;
if (free[a+2,b]='|')and(free[a+1,b-1]='_')and(free[a+1,b+1]='_')then begin g:=1;inc(u);free[a+1,b]:='x';move:='\';end;
end;
if free[a,b]='_' then
begin
if (free[a-1,b+1]='|')and(free[a,b+2]='_')and(free[a+1,b+1]='|')then begin g:=1;inc(u);free[a,b+1]:='x';move:='\';end;
if b>=3 then if (free[a-1,b-1]='|')and(free[a,b-2]='_')and(free[a+1,b-1]='|')then begin g:=1;inc(u);free[a,b-1]:='x';move:='\';end;
end;
if ((a mod 2<>0)and(b mod 2<>0))or((a mod 2=0)and(b mod 2=0))then begin move:='/';g:=1; end;
end;
'p':menu(free,u,u1);
else begin move:='\';g:=1;end;
end;
ve(free,u,u1,key);
if u+u1>=25 then break;
end;
{Luot cua May}
g1:=1;
while (g1=1)and(u+u1<=100) do
begin gotoxy(10,17);write('Luot cua May. ');delay(500);
gotoxy(10,17);write('Luot cua May.. ');delay(500);
gotoxy(10,17);write('Luot cua May...');delay(500);
i:=2;g1:=0;d1:=u1;
while (i<20)and(u+u1<=100) do
begin j:=2; i:=i+2;
while (j<20)and(u+u1<=100) do
begin j:=j+2;d:=0;
if free[i-1,j]in['.','|','_'] then inc(d);
if free[i+1,j]in['.','|','_'] then inc(d);
if free[i,j-1]in['.','|','_'] then inc(d);
if free[i,j+1]in['.','|','_'] then inc(d);
if d=3 then
begin g1:=1;inc(u1);
if not(free[i-1,j]in['.','|','_']) then
begin
free[i-1,j]:='|';free[i-1,j+1]:='|';free[i,j]:='o';
end;
if not(free[i+1,j]in['.','|','_']) then
begin
free[i+1,j]:='|';free[i+1,j+1]:='|';free[i,j]:='o';
end;
if not(free[i,j-1]in['.','|','_']) then
begin
free[i,j-1]:='_';free[i,j]:='o';
end;
if not(free[i,j+1]in['.','|','_']) then
begin
free[i,j+1]:='_';free[i,j]:='o';
end;
if d=3 then break;
end ;
if d=3 then break;
end;
if d=3 then break;
end;
ve(free,u,u1,key);
if d1=u1 then begin
i:=0;g1:=0;d1:=0;x:=0;
while (i<20)and(u+u1<=100) do
begin j:=0; i:=i+2;
while (j<20)and(u+u1<=100) do
begin j:=j+2;d:=0;
if free[i-1,j]in['.','|','_'] then inc(d);
if free[i+1,j]in['.','|','_'] then inc(d);
if free[i,j-1]in['.','|','_'] then inc(d);
if free[i,j+1]in['.','|','_'] then inc(d);
if d<2 then
begin
if not(free[i-1,j]in['.','|','_']) then
begin x:=0;
free[i-1,j]:='|';free[i-1,j+1]:='|';
if not(tontai(free,key))then begin free[i-1,j]:=' ';free[i-1,j+1]:=' ';x:=6;end else break;
end ;
if not(free[i+1,j]in['.','|','_']) then
begin x:=0;
free[i+1,j]:='|';free[i+1,j+1]:='|';
if not(tontai(free,key))then begin free[i+1,j]:=' ';free[i+1,j+1]:=' ';x:=6;end else break;
end ;
if not(free[i,j-1]in['.','|','_']) then
begin x:=0;
free[i,j-1]:='_';
if not(tontai(free,key))then begin free[i,j-1]:=' ';x:=6;end else break;
end ;
if not(free[i,j+1]in['.','|','_']) then
begin x:=0;
free[i,j+1]:='_';
if not(tontai(free,key))then begin free[i,j+1]:=' ';x:=6;end else break;
end;
if (d<2)and(x<>6)then break;
end;
if (d=2)or(d=4)then inc(d1);
if (d<2)and(x<>6)then break;
end;
if (d<2)and(x<>6)then break;
end;
if (d<2)and(x<>6)then break;
end;
ve(free,u,u1,key);
if d1=100 then begin
i:=2; write('‡o');readln;
while i<20 do
begin i:=i+2; j:=2;
while j<20 do
begin j:=j+2; d:=0;
if free[i-1,j]in['.','|','_'] then inc(d);
if free[i+1,j]in['.','|','_'] then inc(d);
if free[i,j-1]in['.','|','_'] then inc(d);
if free[i,j+1]in['.','|','_'] then inc(d);
if d=2 then begin
if not(free[i-1,j]in['.','|','_']) then
begin
free[i-1,j]:='|';free[i-1,j+1]:='|';
end else
if not(free[i+1,j]in['.','|','_']) then
begin
free[i+1,j]:='|';free[i+1,j+1]:='|';
end else
if not(free[i,j-1]in['.','|','_']) then
begin
free[i,j-1]:='_';
end else
if not(free[i,j+1]in['.','|','_']) then
begin
free[i,j+1]:='_';
end;
break
end;
if d=2 then break;
end;
if d=2 then break;
end;
if d=2 then break;
end;
if d=2 then break;
i:=2; u1:=0;
while i<20 do
begin i:=i+2; j:=2;
while j<20 do
begin j:=j+2;d:=0;
if free[i-1,j]in['.','|','_'] then inc(d);
if free[i+1,j]in['.','|','_'] then inc(d);
if free[i,j-1]in['.','|','_'] then inc(d);
if free[i,j+1]in['.','|','_'] then inc(d);
if (free[i,j]<>'x')and(d=4)then begin free[i,j]:='o';inc(u1);end;
end;
end;
end;{ket thuc luot danh cua May}
if u+u1>=200 then
begin
if u>u1 then begin gotoxy(10,8);write('Ban thang');end;
if u<u1 then begin gotoxy(10,8);write('Ban thua');end;
gotoxy(10,23);write('An Enter de quay lai>>>');readln;
end;
end;{ket thuc khi danh het}
end;{ket thuc 10x10}
menu(free,u,u1);
end;
BEGIN
menu(free,u,u1);
END.