2011 m. balandžio 13 d., trečiadienis

Programos nuo 2010 rudens. Kryžiukai-nuliukai

2010-10-02 suprograminau kryžiukus-nuliukus, t.y. žaidimas kryžiukai-nuliukai su nepatogiu valdymu, prieš kompiuterį, kuris ėjimus daro randomu į bet kurį laisvą langelį.
Vėliau pridėjau kompiuteriui "proto", ir jis dabar sugeba "nužvelgti" jūsų mintis vienu ėjimu į priekį, ir jeigu mato grėsmę pralaimėti sekančiu ėjimu, tai bando tam priešintis, tačiau pats naudingų progų neišnaudoja...

Programa parašyta su labai daug teksto kartojimo (ctrl+C, ctrl+V) , dėl to ir kodas išėjo ilgas.

Taigi:

program XO;
uses crt;
var a,a11,a12,a13,a21,a22,a23,a31,a32,a33:byte;
e,r,n:byte;
c,c11,c12,c13,c21,c22,c23,c31,c32,c33:byte;
begin
randomize;
clrscr;

e:=0; {e - "error flag"}
r:=0; {r - "result flag"}
n:=0; {n - "overflow" skaitliukas. Pildosi tol, kol pasiekia 9 - maksimalá lentos langeliø skaièiø}
c:=0; {c - intelektas}

a11:=0;
a12:=0;
a13:=0;
a21:=0;
a22:=0;
a23:=0;
a31:=0;
a32:=0;
a33:=0;

c11:=0;
c12:=0;
c13:=0;
c21:=0;
c22:=0;
c23:=0;
c31:=0;
c32:=0;
c33:=0;

writeln('2010-10-02 RS');
writeln('Zaidimas "Kryziukai-nuliukai"');
writeln;
writeln('Tokia tvarka sunumeruoti lentos eilutes ir stulpeliai: ');
writeln(' 1 2 3 ');
writeln(' |---|---|---|');
writeln('1 | | | |');
writeln(' |---|---|---|');
writeln('2 | | | |');
writeln(' |---|---|---|');
writeln('3 | | | |');
writeln(' |---|---|---|');

writeln('Ejimas daromas parasant dvizenkli skaiciu, kurio pirmasis skaitmuo reiskia ');
writeln('eilutes numeri, o antrasis - stulpelio numeri.');
writeln('Pirmieji einate jus (kryziukai). Kompiuteris (nuliukai) atsako automatiskai.');
writeln('Pradekite:');


while (r<1) and (n<>9) do
begin
e:=0;
if n mod 2 = 0 then read(a)
else
begin
if c=11 then a:=11;
if c=22 then a:=22;
if c=33 then a:=33;
if c=12 then a:=12;
if c=21 then a:=21;
if c=13 then a:=13;
if c=23 then a:=23;
if c=31 then a:=31;
if c=32 then a:=32;


if c=0 then
begin
a:=random(9);
a:=(a div 3 + 1)*10 + (a mod 3 + 1);
end;
end;;
n:=n+1;

if not ((a=11) or (a=12) or (a=13) or (a=21) or (a=22) or (a=23) or (a=31) or (a=32) or (a=33)) then e:=1;



if a=11
then if a11=0
then if n mod 2 = 1
then a11:=1
else a11:=4
else e:=1;
if a=12
then if a12=0
then if n mod 2 = 1
then a12:=1
else a12:=4
else e:=1;
if a=13
then if a13=0
then if n mod 2 = 1
then a13:=1
else a13:=4
else e:=1;
if a=21
then if a21=0
then if n mod 2 = 1
then a21:=1
else a21:=4
else e:=1;
if a=22
then if a22=0
then if n mod 2 = 1
then a22:=1
else a22:=4
else e:=1;
if a=23
then if a23=0
then if n mod 2 = 1
then a23:=1
else a23:=4
else e:=1;
if a=31
then if a31=0
then if n mod 2 = 1
then a31:=1
else a31:=4
else e:=1;
if a=32
then if a32=0
then if n mod 2 = 1
then a32:=1
else a32:=4
else e:=1;
if a=33
then if a33=0
then if n mod 2 = 1
then a33:=1
else a33:=4
else e:=1;



clrscr;


writeln(' 1 2 3 ');
writeln(' |---|---|---|');
write('1 | ');
if a11=0 then write(' ') else if a11=1 then write('X') else write('O');
write(' | ');
if a12=0 then write(' ') else if a12=1 then write('X') else write('O');
write(' | ');
if a13=0 then write(' ') else if a13=1 then write('X') else write('O');
writeln(' |');
writeln(' |---|---|---|');
write('2 | ');
if a21=0 then write(' ') else if a21=1 then write('X') else write('O');
write(' | ');
if a22=0 then write(' ') else if a22=1 then write('X') else write('O');
write(' | ');
if a23=0 then write(' ') else if a23=1 then write('X') else write('O');
writeln(' |');
writeln(' |---|---|---|');
write('3 | ');
if a31=0 then write(' ') else if a31=1 then write('X') else write('O');
write(' | ');
if a32=0 then write(' ') else if a32=1 then write('X') else write('O');
write(' | ');
if a33=0 then write(' ') else if a33=1 then write('X') else write('O');
writeln(' |');
writeln(' |---|---|---|');
{ writeln(a11,' ',a12,' ',a13);
writeln(a21,' ',a22,' ',a23);
writeln(a31,' ',a32,' ',a33);}


if e=1 then n:=n-1;
if e=1 then if n mod 2 = 0 then writeln('Klaida. Iveskite koordinate is naujo');

if a11+a12+a13=3 then r:=3;
if a21+a22+a23=3 then r:=3;
if a31+a32+a33=3 then r:=3;
if a11+a21+a31=3 then r:=3;
if a12+a22+a32=3 then r:=3;
if a13+a23+a33=3 then r:=3;
if a11+a22+a33=3 then r:=3;
if a13+a22+a31=3 then r:=3;

if a11+a12+a13=12 then r:=12;
if a21+a22+a23=12 then r:=12;
if a31+a32+a33=12 then r:=12;
if a11+a21+a31=12 then r:=12;
if a12+a22+a32=12 then r:=12;
if a13+a23+a33=12 then r:=12;
if a11+a22+a33=12 then r:=12;
if a13+a22+a31=12 then r:=12;

c:=0;
if (a33=0) then if (a11=1) and (a22=1) then c:=33;
if (a33=0) then if (a31=1) and (a32=1) then c:=33;
if (a33=0) then if (a13=1) and (a23=1) then c:=33;

if (a11=0) then if (a22=1) and (a33=1) then c:=11;
if (a11=0) then if (a21=1) and (a12=1) then c:=11;
if (a11=0) then if (a31=1) and (a13=1) then c:=11;

if (a13=0) then if (a31=1) and (a22=1) then c:=13;
if (a13=0) then if (a11=1) and (a12=1) then c:=13;
if (a13=0) then if (a23=1) and (a33=1) then c:=13;

if (a31=0) then if (a22=1) and (a13=1) then c:=31;
if (a31=0) then if (a11=1) and (a21=1) then c:=31;
if (a31=0) then if (a32=1) and (a33=1) then c:=31;

if (a21=0) then if (a11=1) and (a31=1) then c:=21;
if (a21=0) then if (a22=1) and (a23=1) then c:=21;

if (a12=0) then if (a11=1) and (a13=1) then c:=12;
if (a12=0) then if (a32=1) and (a22=1) then c:=12;

if (a23=0) then if (a21=1) and (a22=1) then c:=23;
if (a23=0) then if (a13=1) and (a33=1) then c:=23;

if (a32=0) then if (a12=1) and (a22=1) then c:=32;
if (a32=0) then if (a31=1) and (a33=1) then c:=32;

if (a22=0) then if (a11=1) and (a33=1) then c:=22;
if (a22=0) then if (a13=1) and (a31=1) then c:=22;
if (a22=0) then if (a21=1) and (a23=1) then c:=22;
if (a22=0) then if (a12=1) and (a32=1) then c:=22;


end;


if r=0 then writeln('Rezultatas: Lygios');
if r=3 then writeln('Rezultatas: jus laimejote. Plojimai!');
if r=12 then writeln('Rezultatas: kompiuteris laimejo. Kokia geda!');

readln;
readln;

end.

Komentarų nėra:

Rašyti komentarą