//©Petr Skocdopole - Skosoft 
//February 2026,Prague, Czech Rep.
//skoc76@gmail.com
 
#pragma mode( separator(.,;)integer(h32) )

EXPORT result1:=0,result2:=0,game,com,diff,PLR1,PLR2;


KONEC();
CH();
HH();

EXPORT GAME_of_PAIRS()
BEGIN


CHOOSE(game,"Who is playing?",
"Human vs. Computer",
"Computer vs. Human",
"Human vs. Human");

IF game==1 THEN PLR1:="HUMAN";
CHOOSE(com,"Difficulty?",
"Sclerotic",
"Smart kid",
"Superior",
"Unbeatable");
IF com==1 THEN PLR2:="SCLEROTIC";END;
IF com==2 THEN PLR2:="SMART KID";END;
IF com==3 THEN PLR2:="SUPERIOR";END;
IF com==4 THEN PLR2:="UNBEATABLE";END;
diff:=com;
END;
IF game==2 THEN PLR2:="HUMAN"; 
CHOOSE(com,"Difficulty?",
"Sclerotic",
"Smart kid",
"Superior",
"Unbeatable");
IF com==1 THEN PLR1:="SCLEROTIC";END;
IF com==2 THEN PLR1:="SMART KID";END;
IF com==3 THEN PLR1:="SUPERIOR";END;
IF com==4 THEN PLR1:="UNBEATABLE";END;
diff:=com;CH();

END;

IF game==3 THEN PLR1:="HUMAN 1";PLR2:="HUMAN 2";HH();
END;



LOCAL touch;
LOCAL PLAN1,PLAN2,PLAN3,PLAN4,PLAN5,pair1,pair2;
//PLAN1=initialcards, PLAN2=scrambledcards,PLAN3=memory->uncoveredcards,4-5 are searches
LOCAL row,col,f,j,x,y,card:=9811;
LOCAL pair1;
LOCAL pair2;
LOCAL row1,row2,col1,col2;
LOCAL color:=0;
LOCAL count:=0;
LOCAL score1:=1,score2:=1;
LOCAL cmp;
LOCAL search;

0▶result1;0▶result2;





MAKEMAT(0,8,8)▶PLAN1;
MAKEMAT(0,8,8)▶PLAN2;
MAKEMAT(0,8,8)▶PLAN3;

MAKEMAT(0,8,8)▶pair1;
MAKEMAT(0,8,8)▶pair2;


RECT();

DIMGROB_P(G1,240,240);
DIMGROB_P(G2,240,240);
DIMGROB_P(G4,330,240);
DIMGROB_P(G3,240,240,#5C0001);


RECT_P(G2,0,0,239,239,#224624);
RECT_P(G4,240,0,319,240,#54B5FB);


FOR col FROM 1 TO 8 DO
FOR row FROM 1 TO 8 DO
card:=card+1;

PLAN1(row,col):=card;
IF card==9837 THEN card:=9855;END;
IF card==9861 THEN card:=9811;END;
END;END;


FOR row FROM 1 TO 8 DO
FOR col FROM 1 TO 8 DO

REPEAT
x:=ROUND(RANDINT(7)+1,0);
y:=ROUND(RANDINT(7)+1,0);
UNTIL PLAN2(x,y)==0;
PLAN2(x,y):=PLAN1(row,col);
END;
END;

BLIT(G4);
BLIT(G2);

LOCAL k;

FOR col FROM 0 to 241 STEP 30 DO
LINE_P(col-2,0,col-2,239,#000000);
LINE_P(col-1,0,col-1,239,#000000);
LINE_P(col,0,col,239,#000000); 
LINE_P(col+1,0,col+1,239,#000000);
LINE_P(col+2,0,col+2,239,#000000);
LINE_P(0,col-2,239,col-2,#000000);
LINE_P(0,col-1,239,col-1,#000000);
LINE_P(0,col,239,col,#000000);
LINE_P(0,col+1,239,col+1,#000000);
LINE_P(0,col+2,239,col+2,#000000);

FOR k FROM 3 to 230 STEP 30 DO
IF col>230 THEN BREAK;END;
LINE_P(col+3,k,col+3,k+24,#FFFFFF);
LINE_P(col+27,k,col+27,k+24,#FFFFFF);
LINE_P(k,col+3,k+24,col+3,#FFFFFF);
LINE_P(k,col+27,k+24,col+27,#FFFFFF);
END;

END;



LOCAL C;
FOR row FROM 1 TO 8 DO
FOR col FROM 1 TO 8 DO
C:=(PLAN2(row,col)-9810)*5;

TEXTOUT_P(CHAR(PLAN2(row,col)),G1,
row*30-26,col*30-28,7,#000000,30,RGB(200,255-C,C));
TEXTOUT_P(CHAR(PLAN2(row,col)),G1,
row*30-25,col*30-28,7,#000000);
END;END;






//--------------HUMAN-------------

WHILE result1+result2<32 DO


score1:=1;
score2:=1;

LOCAL divx:=30,divy:=30;

WHILE score1>0 DO // HUMAN cycle
TEXTOUT_P(PLR1,250,20,1,#FFD86C,60,#303030);
TEXTOUT_P("████████",250,40,2,#54B5FB);
TEXTOUT_P("score: "+result1,250,40,2,#000000);
TEXTOUT_P(PLR2,250,213,1,#FFD86C,60,#54B5FB);
TEXTOUT_P("████████",250,190,2,#54B5FB);
TEXTOUT_P("score: "+result2,250,190,2,#000000);
IF result1+result2==32 THEN WAIT(1);KONEC();END;
WHILE count<1 DO //firstcard

touch:=mouse();

IF SIZE(touch(1)) THEN
x:=B→R(touch(1,1));
y:=B→R(touch(1,2));

IF x<29 THEN row1:=1; END;
IF x>29 AND x<59 THEN row1:=2; END;
IF x>59 AND x<89 THEN row1:=3; END;
IF x>89 AND x<119 THEN row1:=4; END;
IF x>119 AND x<149 THEN row1:=5; END;
IF x>149 AND x<179 THEN row1:=6; END;
IF x>179 AND x<209 THEN row1:=7; END;
IF x>209 AND x<239 THEN row1:=8; END;

IF y<29 THEN col1:=1; END;
IF y>29 AND y<59 THEN col1:=2; END;
IF y>59 AND y<89 THEN col1:=3; END;
IF y>89 AND y<119 THEN col1:=4; END;
IF y>119 AND y<149 THEN col1:=5; END;
IF y>149 AND y<179 THEN col1:=6; END;
IF y>179 AND y<209 THEN col1:=7; END;
IF y>209 AND y<239 THEN col1:=8; END;

GETPIX_P(x,y)▶color;

IF color==#224624 THEN
y:=B→R(touch(1,2));
pair1(row1,col1):=PLAN2(row1,col1);
PLAN3(row1,col1):=PLAN2(row1,col1);

BLIT_P(row1*30-26,col1*30-26,row1*30-3,
col1*30-3,G1,row1*30-26,col1*30-26,
row1*30-3,col1*30-3);
count:=count+1;
END;
END;
END;

WHILE count<2 DO //second card

touch:=mouse();

IF SIZE(touch(1)) THEN

x:=B→R(touch(1,1));
y:=B→R(touch(1,2));

IF x<29 THEN row2:=1; END;
IF x>29 AND x<59 THEN row2:=2; END;
IF x>59 AND x<89 THEN row2:=3; END;
IF x>89 AND x<119 THEN row2:=4; END;
IF x>119 AND x<149 THEN row2:=5; END;
IF x>149 AND x<179 THEN row2:=6; END;
IF x>179 AND x<209 THEN row2:=7; END;
IF x>209 AND x<239 THEN row2:=8; END;

IF y<29 THEN col2:=1; END;
IF y>29 AND y<59 THEN col2:=2; END;
IF y>59 AND y<89 THEN col2:=3; END;
IF y>89 AND y<119 THEN col2:=4; END;
IF y>119 AND y<149 THEN col2:=5; END;
IF y>149 AND y<179 THEN col2:=6; END;
IF y>179 AND y<209 THEN col2:=7; END;
IF y>209 AND y<239 THEN col2:=8; END;

GETPIX_P(x,y)▶color;

IF color==#224624 THEN
pair2(row2,col2):=PLAN2(row2,col2);
PLAN3(row2,col2):=PLAN2(row2,col2);

BLIT_P(row2*30-26,col2*30-26,row2*30-3,
col2*30-3,G1,row2*30-26,col2*30-26,
row2*30-3,col2*30-3);
WAIT(0.5);count:=count+1;
END;

END;
END;


IF pair1(row1,col1)<>pair2(row2,col2) 
THEN WAIT(1.5);count:=0;score1:=score1-score1;ELSE // TADY JE KONEC SMYČKY 


BLIT_P(row1*30-26,col1*30-26,row1*30-3,
col1*30-3,G3,row1*30-26,col1*30-26,
row1*30-3,col1*30-3);

BLIT_P(row2*30-26,col2*30-26,row2*30-3,
col2*30-3,G3,row2*30-26,col2*30-26,
row2*30-3,col2*30-3);

result1:=result1+1;WAIT(0.3);count:=0;PLAN3(row1,col1):=1;PLAN3(row2,col2):=1;

TEXTOUT_P("████████",250,40,2,#54B5FB);
TEXTOUT_P("score: "+result1,250,40,2,#000000);
TEXTOUT_P("████████",250,190,2,#54B5FB);
TEXTOUT_P("score: "+result2,250,190,2,#000000);

WAIT(0.5);
IF result1+result2==32 THEN WAIT(1);KONEC();END;
END;


IF score1==0 THEN

BLIT_P(row1*30-26,col1*30-26,row1*30-3,
col1*30-3,G2,row1*30-26,col1*30-26,
row1*30-3,col1*30-3);
BLIT_P(row2*30-26,col2*30-26,row2*30-3,
col2*30-3,G2,row2*30-26,col2*30-26,
row2*30-3,col2*30-3);
END;


END;

WAIT(1);
//------------COMPUTER------------------
LOCAL er;

WHILE score2>0 DO //COMPUTER
MAKEMAT(0,8,8)▶PLAN4;
MAKEMAT(0,8,8)▶PLAN5;

TEXTOUT_P(PLR1,250,20,1,#FFD86C,60,#54B5FB);
TEXTOUT_P("████████",250,40,2,#54B5FB);
TEXTOUT_P("score: "+result1,250,40,2,#000000);
TEXTOUT_P(PLR2,250,213,1,#FFD86C,60,#303030);
TEXTOUT_P("████████",250,190,2,#54B5FB);
TEXTOUT_P("score: "+result2,250,190,2,#000000);

IF result1+result2==32 THEN WAIT(1);KONEC();END;

IF diff==1 THEN
FOR er FROM 1 TO 40 DO
row:=ROUND(RANDINT(7)+1,0);col:=ROUND(RANDINT(7)+1,0);
PLAN3(row,col):=0;
END;
END;
IF diff==2 THEN FOR er FROM 1 TO 14 DO
row:=ROUND(RANDINT(7)+1,0);col:=ROUND(RANDINT(7)+1,0);
PLAN3(row,col):=0;
END;
END;
IF diff==3 THEN FOR er FROM 1 TO 5 DO
row:=ROUND(RANDINT(7)+1,0);col:=ROUND(RANDINT(7)+1,0);
PLAN3(row,col):=0;
END;
END;

PLAN2-PLAN3▶PLAN4;



FOR row FROM 1 TO 8 DO
FOR col FROM 1 TO 8 DO
IF PLAN4(row,col)==0 THEN PLAN5(row,col):=PLAN2(row,col);
END;
END;
END;

search:=0;

WHILE search<64 DO

FOR row FROM 1 TO 8 DO
FOR col FROM 1 TO 8 DO

IF PLAN5(row,col)<>0 THEN row1:=row;col1:=col; pair1(row,col):=PLAN5(row,col);PLAN5(row,col):=0;BREAK(2); //najde první už taženou kartu
END;

END;
END;
search:=search+1;

FOR row FROM 1 TO 8 DO
FOR col FROM 1 TO 8 DO

if PLAN5(row,col)==pair1(row1,col1) THEN row2:=row;col2:=col;pair2(row,col):=PLAN5(row,col);PLAN5(row,col):=0;cmp:=2;
PLAN3(row,col):=1;PLAN3(row1,col1):=1;search:=search+64;
END;

END;
END;


END; //WHILE search...





WHILE count<1 DO //Firstcard


IF cmp==2 THEN BLIT_P(row1*30-26,col1*30-26,row1*30-3,
col1*30-3,G1,row1*30-26,col1*30-26,
row1*30-3,col1*30-3);
WAIT(1);count:=count+1;ELSE

x:=RANDINT(237)+1;
y:=RANDINT(237)+1;


IF x<29 THEN row1:=1; END;
IF x>29 AND x<59 THEN row1:=2; END;
IF x>59 AND x<89 THEN row1:=3; END;
IF x>89 AND x<119 THEN row1:=4; END;
IF x>119 AND x<149 THEN row1:=5; END;
IF x>149 AND x<179 THEN row1:=6; END;
IF x>179 AND x<209 THEN row1:=7; END;
IF x>209 AND x<239 THEN row1:=8; END;

IF y<29 THEN col1:=1; END;
IF y>29 AND y<59 THEN col1:=2; END;
IF y>59 AND y<89 THEN col1:=3; END;
IF y>89 AND y<119 THEN col1:=4; END;
IF y>119 AND y<149 THEN col1:=5; END;
IF y>149 AND y<179 THEN col1:=6; END;
IF y>179 AND y<209 THEN col1:=7; END;
IF y>209 AND y<239 THEN col1:=8; END;

GETPIX_P(x,y)▶color;

IF color==#224624 THEN
pair1(row1,col1):=PLAN2(row1,col1);
PLAN3(row1,col1):=PLAN2(row1,col1);

BLIT_P(row1*30-26,col1*30-26,row1*30-3,
col1*30-3,G1,row1*30-26,col1*30-26,
row1*30-3,col1*30-3);
//----------------searchin for pair
PLAN2-PLAN3▶PLAN4;

FOR row FROM 1 TO 8 DO
FOR col FROM 1 TO 8 DO
IF PLAN4(row,col)==0 THEN PLAN5(row,col):=PLAN2(row,col);
END;
END;
END;

PLAN5(row1,col1):=0;

FOR row FROM 1 TO 8 DO
FOR col FROM 1 TO 8 DO

if PLAN5(row,col)==pair1(row1,col1) THEN row2:=row;col2:=col;pair2(row,col):=PLAN5(row,col);PLAN5(row,col):=0;cmp:=2;
PLAN3(row,col):=1;PLAN3(row1,col1):=1;WAIT(1);BLIT_P(row2*30-26,col2*30-26,row2*30-3,
col2*30-3,G1,row2*30-26,col2*30-26,
row2*30-3,col2*30-3);WAIT(0.5);count:=count+1;
END;

END;
END;


count:=count+1;
END;
END;

END;
WAIT(1);

WHILE count<2 DO //second card


IF cmp==2 THEN BLIT_P(row2*30-26,col2*30-26,row2*30-3,
col2*30-3,G1,row2*30-26,col2*30-26,
row2*30-3,col2*30-3);WAIT(0.5);count:=count+1;ELSE

x:=RANDINT(237)+1;
y:=RANDINT(237)+1;

IF x<29 THEN row2:=1; END;
IF x>29 AND x<59 THEN row2:=2; END;
IF x>59 AND x<89 THEN row2:=3; END;
IF x>89 AND x<119 THEN row2:=4; END;
IF x>119 AND x<149 THEN row2:=5; END;
IF x>149 AND x<179 THEN row2:=6; END;
IF x>179 AND x<209 THEN row2:=7; END;
IF x>209 AND x<239 THEN row2:=8; END;

IF y<29 THEN col2:=1; END;
IF y>29 AND y<59 THEN col2:=2; END;
IF y>59 AND y<89 THEN col2:=3; END;
IF y>89 AND y<119 THEN col2:=4; END;
IF y>119 AND y<149 THEN col2:=5; END;
IF y>149 AND y<179 THEN col2:=6; END;
IF y>179 AND y<209 THEN col2:=7; END;
IF y>209 AND y<239 THEN col2:=8; END;

GETPIX_P(x,y)▶color;

IF color==#224624 THEN
pair2(row2,col2):=PLAN2(row2,col2);
PLAN3(row2,col2):=PLAN2(row2,col2);

BLIT_P(row2*30-26,col2*30-26,row2*30-3,
col2*30-3,G1,row2*30-26,col2*30-26,
row2*30-3,col2*30-3);
WAIT(0.5);count:=count+1;
END;
END;

END;


IF pair1(row1,col1)<>pair2(row2,col2) 
THEN WAIT(1.5);count:=0;score2:=score2-score2;ELSE // TADY JE KONEC SMYČKY 


BLIT_P(row1*30-26,col1*30-26,row1*30-3,
col1*30-3,G3,row1*30-26,col1*30-26,
row1*30-3,col1*30-3);

BLIT_P(row2*30-26,col2*30-26,row2*30-3,
col2*30-3,G3,row2*30-26,col2*30-26,
row2*30-3,col2*30-3);WAIT(0.3);result2:=result2+1;
cmp:=0;count:=0;PLAN3(row1,col1):=1;PLAN3(row2,col2):=1;

TEXTOUT_P("████████",250,40,2,#54B5FB);
TEXTOUT_P("score: "+result1,250,40,2,#000000);
TEXTOUT_P("████████",250,190,2,#54B5FB);
TEXTOUT_P("score: "+result2,250,190,2,#000000);

WAIT(0.5);
IF result1+result2==32 THEN WAIT(1);KONEC();END;
END;


IF score2==0 THEN

BLIT_P(row1*30-26,col1*30-26,row1*30-3,
col1*30-3,G2,row1*30-26,col1*30-26,
row1*30-3,col1*30-3);
BLIT_P(row2*30-26,col2*30-26,row2*30-3,
col2*30-3,G2,row2*30-26,col2*30-26,
row2*30-3,col2*30-3);
END;


END;


END;



END;



//—————————COMPUTER VS. HUMAN——————————

CH()
BEGIN
LOCAL touch;
LOCAL PLAN1,PLAN2,PLAN3,PLAN4,PLAN5,pair1,pair2;
//PLAN1=initialcards, PLAN2=scrambledcards,PLAN3=memory->uncoveredcards,4-5 are searches
LOCAL row,col,f,j,x,y,card:=9811;
LOCAL pair1;
LOCAL pair2;
LOCAL row1,row2,col1,col2;
LOCAL color:=0;
LOCAL count:=0;
LOCAL score1:=1,score2:=1;
LOCAL cmp;
LOCAL search;

LOCAL draw:=1;
0▶result1;0▶result2;




MAKEMAT(0,8,8)▶PLAN1;
MAKEMAT(0,8,8)▶PLAN2;
MAKEMAT(0,8,8)▶PLAN3;

MAKEMAT(0,8,8)▶pair1;
MAKEMAT(0,8,8)▶pair2;


RECT();

DIMGROB_P(G1,240,240);
DIMGROB_P(G2,240,240);
DIMGROB_P(G4,330,240);
DIMGROB_P(G3,240,240,#5C0001);


RECT_P(G2,0,0,239,239,#224624);
RECT_P(G4,240,0,319,240,#54B5FB);


FOR col FROM 1 TO 8 DO
FOR row FROM 1 TO 8 DO
card:=card+1;

PLAN1(row,col):=card;
IF card==9837 THEN card:=9855;END;
IF card==9861 THEN card:=9811;END;
END;END;


FOR row FROM 1 TO 8 DO
FOR col FROM 1 TO 8 DO

REPEAT
x:=ROUND(RANDINT(7)+1,0);
y:=ROUND(RANDINT(7)+1,0);
UNTIL PLAN2(x,y)==0;
PLAN2(x,y):=PLAN1(row,col);
END;
END;




BLIT(G4);
BLIT(G2);

LOCAL k;

FOR col FROM 0 to 241 STEP 30 DO

LINE_P(col-2,0,col-2,239,#000000);
LINE_P(col-1,0,col-1,239,#000000);
LINE_P(col,0,col,239,#000000); 
LINE_P(col+1,0,col+1,239,#000000);
LINE_P(col+2,0,col+2,239,#000000);
LINE_P(0,col-2,239,col-2,#000000);
LINE_P(0,col-1,239,col-1,#000000);
LINE_P(0,col,239,col,#000000);
LINE_P(0,col+1,239,col+1,#000000);
LINE_P(0,col+2,239,col+2,#000000);

FOR k FROM 3 to 230 STEP 30 DO
IF col>230 THEN BREAK;END;
LINE_P(col+3,k,col+3,k+24,#FFFFFF);
LINE_P(col+27,k,col+27,k+24,#FFFFFF);
LINE_P(k,col+3,k+24,col+3,#FFFFFF);
LINE_P(k,col+27,k+24,col+27,#FFFFFF);
END;

END;



LOCAL C;
FOR row FROM 1 TO 8 DO
FOR col FROM 1 TO 8 DO
C:=(PLAN2(row,col)-9810)*5;

TEXTOUT_P(CHAR(PLAN2(row,col)),G1,
row*30-26,col*30-28,7,#000000,30,RGB(200,255-C,C));
TEXTOUT_P(CHAR(PLAN2(row,col)),G1,
row*30-25,col*30-28,7,#000000);
END;END;

//--------------COMPUTER---------------

WHILE result1+result2<32 DO

score1:=1;
score2:=1;

LOCAL divx:=30,divy:=30;

LOCAL er;

WHILE score2>0 DO //COMPUTER

MAKEMAT(0,8,8)▶PLAN4;
MAKEMAT(0,8,8)▶PLAN5;

TEXTOUT_P(PLR1,250,20,1,#FFD86C,60,#303030);
TEXTOUT_P("████████",250,40,2,#54B5FB);
TEXTOUT_P("score: "+result1,250,40,2,#000000);
TEXTOUT_P(PLR2,250,213,1,#FFD86C,60,#54B5FB);
TEXTOUT_P("████████",250,190,2,#54B5FB);
TEXTOUT_P("score: "+result2,250,190,2,#000000);

IF result1+result2==32 THEN WAIT(0.5);KONEC();END;
WAIT(1);
IF diff==1 THEN
FOR er FROM 1 TO 40 DO
row:=ROUND(RANDINT(7)+1,0);col:=ROUND(RANDINT(7)+1,0);
PLAN3(row,col):=0;
END;
END;
IF diff==2 THEN FOR er FROM 1 TO 14 DO
row:=ROUND(RANDINT(7)+1,0);col:=ROUND(RANDINT(7)+1,0);
PLAN3(row,col):=0;
END;
END;
IF diff==3 THEN FOR er FROM 1 TO 5 DO
row:=ROUND(RANDINT(7)+1,0);col:=ROUND(RANDINT(7)+1,0);
PLAN3(row,col):=0;
END;
END;

IF draw==1 THEN x:=ROUND(RANDINT(7)+1,0); y:=ROUND(RANDINT(7)+1,0);PLAN3(x,y):=PLAN2(x,y);draw:=draw+1;END;

PLAN2-PLAN3▶PLAN4;



FOR row FROM 1 TO 8 DO
FOR col FROM 1 TO 8 DO
IF PLAN4(row,col)==0 THEN PLAN5(row,col):=PLAN2(row,col);
END;
END;
END;

search:=0;

REPEAT

FOR row FROM 1 TO 8 DO
FOR col FROM 1 TO 8 DO

IF PLAN5(row,col)<>0 THEN row1:=row;col1:=col; pair1(row,col):=PLAN5(row,col);PLAN5(row,col):=0;BREAK(2); //najde první už taženou kartu
END;

END;
END;
search:=search+1;

FOR row FROM 1 TO 8 DO
FOR col FROM 1 TO 8 DO

IF PLAN5(row,col)==pair1(row1,col1) THEN row2:=row;col2:=col;pair2(row,col):=PLAN5(row,col);PLAN5(row,col):=0;cmp:=2;
PLAN3(row,col):=1;PLAN3(row1,col1):=1;search:=search+64;
END;

END;
END;


UNTIL search>64;




draw:=draw+1;

WHILE count<1 DO //Firstcard


IF cmp==2 THEN BLIT_P(row1*30-26,col1*30-26,row1*30-3,
col1*30-3,G1,row1*30-26,col1*30-26,
row1*30-3,col1*30-3);
WAIT(1);count:=count+1;ELSE

x:=RANDINT(237)+1;
y:=RANDINT(237)+1;


IF x<29 THEN row1:=1; END;
IF x>29 AND x<59 THEN row1:=2; END;
IF x>59 AND x<89 THEN row1:=3; END;
IF x>89 AND x<119 THEN row1:=4; END;
IF x>119 AND x<149 THEN row1:=5; END;
IF x>149 AND x<179 THEN row1:=6; END;
IF x>179 AND x<209 THEN row1:=7; END;
IF x>209 AND x<239 THEN row1:=8; END;

IF y<29 THEN col1:=1; END;
IF y>29 AND y<59 THEN col1:=2; END;
IF y>59 AND y<89 THEN col1:=3; END;
IF y>89 AND y<119 THEN col1:=4; END;
IF y>119 AND y<149 THEN col1:=5; END;
IF y>149 AND y<179 THEN col1:=6; END;
IF y>179 AND y<209 THEN col1:=7; END;
IF y>209 AND y<239 THEN col1:=8; END;

GETPIX_P(x,y)▶color;

IF color==#224624 THEN
pair1(row1,col1):=PLAN2(row1,col1);
PLAN3(row1,col1):=PLAN2(row1,col1);

BLIT_P(row1*30-26,col1*30-26,row1*30-3,
col1*30-3,G1,row1*30-26,col1*30-26,
row1*30-3,col1*30-3);
//----------------searchin for pair
PLAN2-PLAN3▶PLAN4;

FOR row FROM 1 TO 8 DO
FOR col FROM 1 TO 8 DO
IF PLAN4(row,col)==0 THEN PLAN5(row,col):=PLAN2(row,col);
END;
END;
END;

PLAN5(row1,col1):=0;

FOR row FROM 1 TO 8 DO
FOR col FROM 1 TO 8 DO

IF PLAN5(row,col)==pair1(row1,col1) THEN row2:=row;col2:=col;pair2(row,col):=PLAN5(row,col);PLAN5(row,col):=0;cmp:=2;
PLAN3(row,col):=1;PLAN3(row1,col1):=1;WAIT(1);BLIT_P(row2*30-26,col2*30-26,row2*30-3,
col2*30-3,G1,row2*30-26,col2*30-26,row2*30-3,col2*30-3);WAIT(0.5);count:=count+1;
END;

END;
END;


count:=count+1;
END;
END;

END;
WAIT(1);

WHILE count<2 DO //second card


IF cmp==2 THEN BLIT_P(row2*30-26,col2*30-26,row2*30-3,
col2*30-3,G1,row2*30-26,col2*30-26,
row2*30-3,col2*30-3);WAIT(0.5);count:=count+1;ELSE

x:=RANDINT(237)+1;
y:=RANDINT(237)+1;

IF x<29 THEN row2:=1; END;
IF x>29 AND x<59 THEN row2:=2; END;
IF x>59 AND x<89 THEN row2:=3; END;
IF x>89 AND x<119 THEN row2:=4; END;
IF x>119 AND x<149 THEN row2:=5; END;
IF x>149 AND x<179 THEN row2:=6; END;
IF x>179 AND x<209 THEN row2:=7; END;
IF x>209 AND x<239 THEN row2:=8; END;

IF y<29 THEN col2:=1; END;
IF y>29 AND y<59 THEN col2:=2; END;
IF y>59 AND y<89 THEN col2:=3; END;
IF y>89 AND y<119 THEN col2:=4; END;
IF y>119 AND y<149 THEN col2:=5; END;
IF y>149 AND y<179 THEN col2:=6; END;
IF y>179 AND y<209 THEN col2:=7; END;
IF y>209 AND y<239 THEN col2:=8; END;

GETPIX_P(x,y)▶color;

IF color==#224624 THEN
pair2(row2,col2):=PLAN2(row2,col2);
PLAN3(row2,col2):=PLAN2(row2,col2);

BLIT_P(row2*30-26,col2*30-26,row2*30-3,
col2*30-3,G1,row2*30-26,col2*30-26,
row2*30-3,col2*30-3);
WAIT(0.5);count:=count+1;
END;
END;

END;


IF pair1(row1,col1)<>pair2(row2,col2) 
THEN WAIT(1.5);count:=0;score2:=score2-score2;ELSE // TADY JE KONEC SMYČKY 


BLIT_P(row1*30-26,col1*30-26,row1*30-3,
col1*30-3,G3,row1*30-26,col1*30-26,
row1*30-3,col1*30-3);

BLIT_P(row2*30-26,col2*30-26,row2*30-3,
col2*30-3,G3,row2*30-26,col2*30-26,
row2*30-3,col2*30-3);WAIT(0.3);result1:=result1+1;

cmp:=0;count:=0;PLAN3(row1,col1):=1;PLAN3(row2,col2):=1;

TEXTOUT_P("████████",250,40,2,#54B5FB);
TEXTOUT_P("score: "+result1,250,40,2,#000000);
TEXTOUT_P("████████",250,190,2,#54B5FB);
TEXTOUT_P("score: "+result2,250,190,2,#000000);

WAIT(0.5);
IF result1+result2==32 THEN WAIT(1);KONEC();END;
END;

IF score2==0 THEN

BLIT_P(row1*30-26,col1*30-26,row1*30-3,
col1*30-3,G2,row1*30-26,col1*30-26,
row1*30-3,col1*30-3);
BLIT_P(row2*30-26,col2*30-26,row2*30-3,
col2*30-3,G2,row2*30-26,col2*30-26,
row2*30-3,col2*30-3);
END;
END;


WAIT(1);

//-------------HUMAN--------------




WHILE score1>0 DO // HUMAN cycle


TEXTOUT_P(PLR1,250,20,1,#FFD86C,60,#54B5FB);
TEXTOUT_P("████████",250,40,2,#54B5FB);
TEXTOUT_P("score: "+result1,250,40,2,#000000);
TEXTOUT_P(PLR2,250,213,1,#FFD86C,60,#303030);
TEXTOUT_P("████████",250,190,2,#54B5FB);
TEXTOUT_P("score: "+result2,250,190,2,#000000);
IF result1+result2==32 THEN WAIT(1);KONEC();END;

WHILE count<1 DO //firstcard

touch:=mouse();

IF SIZE(touch(1)) THEN
x:=B→R(touch(1,1));
y:=B→R(touch(1,2));


IF x<29 THEN row1:=1; END;
IF x>29 AND x<59 THEN row1:=2; END;
IF x>59 AND x<89 THEN row1:=3; END;
IF x>89 AND x<119 THEN row1:=4; END;
IF x>119 AND x<149 THEN row1:=5; END;
IF x>149 AND x<179 THEN row1:=6; END;
IF x>179 AND x<209 THEN row1:=7; END;
IF x>209 AND x<239 THEN row1:=8; END;

IF y<29 THEN col1:=1; END;
IF y>29 AND y<59 THEN col1:=2; END;
IF y>59 AND y<89 THEN col1:=3; END;
IF y>89 AND y<119 THEN col1:=4; END;
IF y>119 AND y<149 THEN col1:=5; END;
IF y>149 AND y<179 THEN col1:=6; END;
IF y>179 AND y<209 THEN col1:=7; END;
IF y>209 AND y<239 THEN col1:=8; END;

GETPIX_P(x,y)▶color;

IF color==#224624 THEN
pair1(row1,col1):=PLAN2(row1,col1);
PLAN3(row1,col1):=PLAN2(row1,col1);

BLIT_P(row1*30-26,col1*30-26,row1*30-3,
col1*30-3,G1,row1*30-26,col1*30-26,
row1*30-3,col1*30-3);
count:=count+1;
END;
END;
END;

WHILE count<2 DO //second card

touch:=mouse();

IF SIZE(touch(1)) THEN

x:=B→R(touch(1,1));
y:=B→R(touch(1,2));

IF x<29 THEN row2:=1; END;
IF x>29 AND x<59 THEN row2:=2; END;
IF x>59 AND x<89 THEN row2:=3; END;
IF x>89 AND x<119 THEN row2:=4; END;
IF x>119 AND x<149 THEN row2:=5; END;
IF x>149 AND x<179 THEN row2:=6; END;
IF x>179 AND x<209 THEN row2:=7; END;
IF x>209 AND x<239 THEN row2:=8; END;

IF y<29 THEN col2:=1; END;
IF y>29 AND y<59 THEN col2:=2; END;
IF y>59 AND y<89 THEN col2:=3; END;
IF y>89 AND y<119 THEN col2:=4; END;
IF y>119 AND y<149 THEN col2:=5; END;
IF y>149 AND y<179 THEN col2:=6; END;
IF y>179 AND y<209 THEN col2:=7; END;
IF y>209 AND y<239 THEN col2:=8; END;

GETPIX_P(x,y)▶color;

IF color==#224624 THEN
pair2(row2,col2):=PLAN2(row2,col2);
PLAN3(row2,col2):=PLAN2(row2,col2);

BLIT_P(row2*30-26,col2*30-26,row2*30-3,
col2*30-3,G1,row2*30-26,col2*30-26,
row2*30-3,col2*30-3);
WAIT(0.5);count:=count+1;
END;

END;
END;

IF pair1(row1,col1)<>pair2(row2,col2) 
THEN WAIT(1.5);count:=0;score1:=score1-score1;ELSE // TADY JE KONEC SMYČKY 


BLIT_P(row1*30-26,col1*30-26,row1*30-3,
col1*30-3,G3,row1*30-26,col1*30-26,
row1*30-3,col1*30-3);

BLIT_P(row2*30-26,col2*30-26,row2*30-3,
col2*30-3,G3,row2*30-26,col2*30-26,
row2*30-3,col2*30-3);

result2:=result2+1;WAIT(0.3);count:=0;PLAN3(row1,col1):=1;PLAN3(row2,col2):=1;

TEXTOUT_P("████████",250,40,2,#54B5FB);
TEXTOUT_P("score: "+result1,250,40,2,#000000);
TEXTOUT_P("████████",250,190,2,#54B5FB);
TEXTOUT_P("score: "+result2,250,190,2,#000000);

WAIT(0.5);
IF result1+result2==32 THEN WAIT(1);KONEC();END;
END;


IF score1==0 THEN

BLIT_P(row1*30-26,col1*30-26,row1*30-3,
col1*30-3,G2,row1*30-26,col1*30-26,
row1*30-3,col1*30-3);
BLIT_P(row2*30-26,col2*30-26,row2*30-3,
col2*30-3,G2,row2*30-26,col2*30-26,
row2*30-3,col2*30-3);
END;
END;
END;

END;


//-------------HUMAN1 vs. HUMAN2-----------



HH()
BEGIN
LOCAL touch;
LOCAL PLAN1,PLAN2,PLAN3,PLAN4,PLAN5,pair1,pair2;
//PLAN1=initialcards, PLAN2=scrambledcards,PLAN3=memory->uncoveredcards,4-5 are searches
LOCAL row,col,f,j,x,y,card:=9811;
LOCAL pair1;
LOCAL pair2;
LOCAL row1,row2,col1,col2;
LOCAL color:=0;
LOCAL count:=0;
LOCAL score1:=1,score2:=1;
LOCAL cmp;
LOCAL search;

0▶result1;0▶result2;


MAKEMAT(0,8,8)▶PLAN1;
MAKEMAT(0,8,8)▶PLAN2;
MAKEMAT(0,8,8)▶PLAN3;

MAKEMAT(0,8,8)▶pair1;
MAKEMAT(0,8,8)▶pair2;


RECT();

DIMGROB_P(G1,240,240);
DIMGROB_P(G2,240,240);
DIMGROB_P(G4,330,240);
DIMGROB_P(G3,240,240,#5C0001);


RECT_P(G2,0,0,239,239,#224624);
RECT_P(G4,240,0,319,240,#54B5FB);


FOR col FROM 1 TO 8 DO
FOR row FROM 1 TO 8 DO
card:=card+1;

PLAN1(row,col):=card;
IF card==9837 THEN card:=9855;END;
IF card==9861 THEN card:=9811;END;
END;END;


FOR row FROM 1 TO 8 DO
FOR col FROM 1 TO 8 DO

REPEAT
x:=ROUND(RANDINT(7)+1,0);
y:=ROUND(RANDINT(7)+1,0);
UNTIL PLAN2(x,y)==0;
PLAN2(x,y):=PLAN1(row,col);
END;
END;




BLIT(G4);
BLIT(G2);

LOCAL k;

FOR col FROM 0 to 241 STEP 30 DO

LINE_P(col-2,0,col-2,239,#000000);
LINE_P(col-1,0,col-1,239,#000000);
LINE_P(col,0,col,239,#000000); 
LINE_P(col+1,0,col+1,239,#000000);
LINE_P(col+2,0,col+2,239,#000000);
LINE_P(0,col-2,239,col-2,#000000);
LINE_P(0,col-1,239,col-1,#000000);
LINE_P(0,col,239,col,#000000);
LINE_P(0,col+1,239,col+1,#000000);
LINE_P(0,col+2,239,col+2,#000000);

FOR k FROM 3 to 230 STEP 30 DO
IF col>230 THEN BREAK;END;
LINE_P(col+3,k,col+3,k+24,#FFFFFF);
LINE_P(col+27,k,col+27,k+24,#FFFFFF);
LINE_P(k,col+3,k+24,col+3,#FFFFFF);
LINE_P(k,col+27,k+24,col+27,#FFFFFF);
END;

END;



LOCAL C;
FOR row FROM 1 TO 8 DO
FOR col FROM 1 TO 8 DO
C:=(PLAN2(row,col)-9810)*5;

TEXTOUT_P(CHAR(PLAN2(row,col)),G1,
row*30-26,col*30-28,7,#000000,30,RGB(200,255-C,C));
TEXTOUT_P(CHAR(PLAN2(row,col)),G1,
row*30-25,col*30-28,7,#000000);
END;END;


//--------------HUMAN 1-------------

WHILE result1+result2<32 DO


score1:=1;
score2:=1;

LOCAL divx:=30,divy:=30;

WHILE score1>0 DO 
TEXTOUT_P(PLR1,250,20,1,#FFD86C,60,#303030);
TEXTOUT_P("████████",250,40,2,#54B5FB);
TEXTOUT_P("score: "+result1,250,40,2,#000000);
TEXTOUT_P(PLR2,250,213,1,#FFD86C,60,#54B5FB);
TEXTOUT_P("████████",250,190,2,#54B5FB);
TEXTOUT_P("score: "+result2,250,190,2,#000000);
IF result1+result2==32 THEN WAIT(1);KONEC();END;
WHILE count<1 DO //firstcard

touch:=mouse();

IF SIZE(touch(1)) THEN
x:=B→R(touch(1,1));
y:=B→R(touch(1,2));


IF x<29 THEN row1:=1; END;
IF x>29 AND x<59 THEN row1:=2; END;
IF x>59 AND x<89 THEN row1:=3; END;
IF x>89 AND x<119 THEN row1:=4; END;
IF x>119 AND x<149 THEN row1:=5; END;
IF x>149 AND x<179 THEN row1:=6; END;
IF x>179 AND x<209 THEN row1:=7; END;
IF x>209 AND x<239 THEN row1:=8; END;

IF y<29 THEN col1:=1; END;
IF y>29 AND y<59 THEN col1:=2; END;
IF y>59 AND y<89 THEN col1:=3; END;
IF y>89 AND y<119 THEN col1:=4; END;
IF y>119 AND y<149 THEN col1:=5; END;
IF y>149 AND y<179 THEN col1:=6; END;
IF y>179 AND y<209 THEN col1:=7; END;
IF y>209 AND y<239 THEN col1:=8; END;

GETPIX_P(x,y)▶color;

IF color==#224624 THEN
pair1(row1,col1):=PLAN2(row1,col1);
PLAN3(row1,col1):=PLAN2(row1,col1);

BLIT_P(row1*30-26,col1*30-26,row1*30-3,
col1*30-3,G1,row1*30-26,col1*30-26,
row1*30-3,col1*30-3);
count:=count+1;
END;
END;
END;

WHILE count<2 DO //second card

touch:=mouse();

IF SIZE(touch(1)) THEN

x:=B→R(touch(1,1));
y:=B→R(touch(1,2));

IF x<29 THEN row2:=1; END;
IF x>29 AND x<59 THEN row2:=2; END;
IF x>59 AND x<89 THEN row2:=3; END;
IF x>89 AND x<119 THEN row2:=4; END;
IF x>119 AND x<149 THEN row2:=5; END;
IF x>149 AND x<179 THEN row2:=6; END;
IF x>179 AND x<209 THEN row2:=7; END;
IF x>209 AND x<239 THEN row2:=8; END;

IF y<29 THEN col2:=1; END;
IF y>29 AND y<59 THEN col2:=2; END;
IF y>59 AND y<89 THEN col2:=3; END;
IF y>89 AND y<119 THEN col2:=4; END;
IF y>119 AND y<149 THEN col2:=5; END;
IF y>149 AND y<179 THEN col2:=6; END;
IF y>179 AND y<209 THEN col2:=7; END;
IF y>209 AND y<239 THEN col2:=8; END;

GETPIX_P(x,y)▶color;

IF color==#224624 THEN
pair2(row2,col2):=PLAN2(row2,col2);
PLAN3(row2,col2):=PLAN2(row2,col2);

BLIT_P(row2*30-26,col2*30-26,row2*30-3,
col2*30-3,G1,row2*30-26,col2*30-26,
row2*30-3,col2*30-3);
WAIT(0.5);count:=count+1;
END;

END;
END;


IF pair1(row1,col1)<>pair2(row2,col2) 
THEN WAIT(1.5);count:=0;score1:=score1-score1;ELSE // TADY JE KONEC SMYČKY 


BLIT_P(row1*30-26,col1*30-26,row1*30-3,
col1*30-3,G3,row1*30-26,col1*30-26,
row1*30-3,col1*30-3);

BLIT_P(row2*30-26,col2*30-26,row2*30-3,
col2*30-3,G3,row2*30-26,col2*30-26,
row2*30-3,col2*30-3);

result1:=result1+1;WAIT(0.3);count:=0;PLAN3(row1,col1):=1;PLAN3(row2,col2):=1;

TEXTOUT_P("████████",250,40,2,#54B5FB);
TEXTOUT_P("score: "+result1,250,40,2,#000000);
TEXTOUT_P("████████",250,190,2,#54B5FB);
TEXTOUT_P("score: "+result2,250,190,2,#000000);

WAIT(0.5);
IF result1+result2==32 THEN WAIT(1);KONEC();END;
END;


IF score1==0 THEN

BLIT_P(row1*30-26,col1*30-26,row1*30-3,
col1*30-3,G2,row1*30-26,col1*30-26,
row1*30-3,col1*30-3);
BLIT_P(row2*30-26,col2*30-26,row2*30-3,
col2*30-3,G2,row2*30-26,col2*30-26,
row2*30-3,col2*30-3);
END;


END;

WAIT(1);

//--------------HUMAN 2-------------



WHILE score2>0 DO // HUMAN cycle
TEXTOUT_P(PLR1,250,20,1,#FFD86C,60,#54B5FB);
TEXTOUT_P("████████",250,40,2,#54B5FB);
TEXTOUT_P("score: "+result1,250,40,2,#000000);
TEXTOUT_P(PLR2,250,213,1,#FFD86C,60,#303030);
TEXTOUT_P("████████",250,190,2,#54B5FB);
TEXTOUT_P("score: "+result2,250,190,2,#000000);
IF result1+result2==32 THEN WAIT(1);KONEC();END;
WHILE count<1 DO //firstcard

touch:=mouse();

IF SIZE(touch(1)) THEN
x:=B→R(touch(1,1));
y:=B→R(touch(1,2));


IF x<29 THEN row1:=1; END;
IF x>29 AND x<59 THEN row1:=2; END;
IF x>59 AND x<89 THEN row1:=3; END;
IF x>89 AND x<119 THEN row1:=4; END;
IF x>119 AND x<149 THEN row1:=5; END;
IF x>149 AND x<179 THEN row1:=6; END;
IF x>179 AND x<209 THEN row1:=7; END;
IF x>209 AND x<239 THEN row1:=8; END;

IF y<29 THEN col1:=1; END;
IF y>29 AND y<59 THEN col1:=2; END;
IF y>59 AND y<89 THEN col1:=3; END;
IF y>89 AND y<119 THEN col1:=4; END;
IF y>119 AND y<149 THEN col1:=5; END;
IF y>149 AND y<179 THEN col1:=6; END;
IF y>179 AND y<209 THEN col1:=7; END;
IF y>209 AND y<239 THEN col1:=8; END;

GETPIX_P(x,y)▶color;

IF color==#224624 THEN
pair1(row1,col1):=PLAN2(row1,col1);
PLAN3(row1,col1):=PLAN2(row1,col1);

BLIT_P(row1*30-26,col1*30-26,row1*30-3,
col1*30-3,G1,row1*30-26,col1*30-26,
row1*30-3,col1*30-3);
count:=count+1;
END;
END;
END;

WHILE count<2 DO //second card

touch:=mouse();

IF SIZE(touch(1)) THEN

x:=B→R(touch(1,1));
y:=B→R(touch(1,2));

IF x<29 THEN row2:=1; END;
IF x>29 AND x<59 THEN row2:=2; END;
IF x>59 AND x<89 THEN row2:=3; END;
IF x>89 AND x<119 THEN row2:=4; END;
IF x>119 AND x<149 THEN row2:=5; END;
IF x>149 AND x<179 THEN row2:=6; END;
IF x>179 AND x<209 THEN row2:=7; END;
IF x>209 AND x<239 THEN row2:=8; END;

IF y<29 THEN col2:=1; END;
IF y>29 AND y<59 THEN col2:=2; END;
IF y>59 AND y<89 THEN col2:=3; END;
IF y>89 AND y<119 THEN col2:=4; END;
IF y>119 AND y<149 THEN col2:=5; END;
IF y>149 AND y<179 THEN col2:=6; END;
IF y>179 AND y<209 THEN col2:=7; END;
IF y>209 AND y<239 THEN col2:=8; END;

GETPIX_P(x,y)▶color;

IF color==#224624 THEN
pair2(row2,col2):=PLAN2(row2,col2);
PLAN3(row2,col2):=PLAN2(row2,col2);

BLIT_P(row2*30-26,col2*30-26,row2*30-3,
col2*30-3,G1,row2*30-26,col2*30-26,
row2*30-3,col2*30-3);
WAIT(0.5);count:=count+1;
END;

END;
END;


IF pair1(row1,col1)<>pair2(row2,col2) 
THEN WAIT(1.5);count:=0;score2:=score2-score2;ELSE // TADY JE KONEC SMYČKY 


BLIT_P(row1*30-26,col1*30-26,row1*30-3,
col1*30-3,G3,row1*30-26,col1*30-26,
row1*30-3,col1*30-3);

BLIT_P(row2*30-26,col2*30-26,row2*30-3,
col2*30-3,G3,row2*30-26,col2*30-26,
row2*30-3,col2*30-3);

result2:=result2+1;WAIT(0.3);count:=0;PLAN3(row1,col1):=1;PLAN3(row2,col2):=1;

TEXTOUT_P("████████",250,40,2,#54B5FB);
TEXTOUT_P("score: "+result1,250,40,2,#000000);
TEXTOUT_P("████████",250,190,2,#54B5FB);
TEXTOUT_P("score: "+result2,250,190,2,#000000);

WAIT(0.5);
IF result1+result2==32 THEN WAIT(1);KONEC();END;
END;


IF score2==0 THEN

BLIT_P(row1*30-26,col1*30-26,row1*30-3,
col1*30-3,G2,row1*30-26,col1*30-26,
row1*30-3,col1*30-3);
BLIT_P(row2*30-26,col2*30-26,row2*30-3,
col2*30-3,G2,row2*30-26,col2*30-26,
row2*30-3,col2*30-3);
END;


END;

WAIT(1);

END;


END;

//-----------------THE END---------------------

KONEC()
BEGIN

DelHVars(com);DelHVars(diff);DelHVars(game);
RECT();
RECT_P(15,15,305,225,#5C0001);
RECT_P(30,30,290,210,#224624);

TEXTOUT_P(PLR1+":",75,77,4,#FFFFFF);TEXTOUT_P(result1,220,75,4,#FFFFFF);

TEXTOUT_P(PLR2+":",75,142,4,#FFFFFF);TEXTOUT_P(result2,220,140,4,#FFFFFF);

TEXTOUT_P("Press any key to start again",160,213,1,#FFFFFF);

WAIT();

DelHVars(30);

GAME_of_PAIRS()
END;


