p@9 %  L$MUST BOOT FROM SLOT 4, 5 OR 6CJJJJ \  i=l x ? L N9 +i C* ɭЅ?0ȱ L Ѕ?iȱi L CPlO^AABIT03{ VALUE.TEXT=vgA,FOURINAROW.TEXT,6 MAKEPIC.TEXTvg67PICTURESr=vg 7BFOURINAROW.CODEB\ ENIGMA.TEXTvg\k ENIGMA.CODEvg+`FG8`0($ p,&" COPYRIGHT APPLE COMPUTER, INC., 1984, 1985 C.LEUNGh&Y&&Y& 꽌ɪ\8`&&꽌ɪɖ'*&%&,E'зЮ꽌ɪФ`+*xH&x'8*7Ixix&&    ') +!  &п  x) +莶莸L莸LNO FILE SYSTEM.APPLE SYSTEM.APPLEJ) (jJJ>Lx "?I  `  C x Nx G .x- `V0^*^*>` aI꽌ɪVɭ .FUNC VALUE,3  ;function value(column,whose:integer; board:matrix):integer;   RETURN .EQU 00  BOARD .EQU 02  BASE .EQU 04  FRIEND .EQU 05  DIR .EQU 06  DIST .EQU 07  MYDOTS .EQU 08  FREE .EQU 09  STEP .EQU 0A  VAL T (CMP #7. (BNE SCLOOP (RTS (  POSINC .BYTE 18.+2.,2.,2.-18.,-18.  NEGINC .BYTE -18.-2.,-2.,18.-2.,18.  (.END %$2 LDA SCORE (CPX #00 (BEQ $4 (CPX FRIEND (BEQ $3 (RTS ;se hai incontrato il bordo del tabellone %$3 CLC ;o una pedina avversaria esci dalla subroutine (ADC #5 %$4 CLC (ADC DIST (STA SCORE (DEC DIST (INC FREE (LDA DISiale a questo incluso (EOR INLINE ;tutte le caselle contengono pedine del (BEQ $1 ;giocatore per cui calcoli VALUE incrementa MYDOTS (LDA #0F ;un valore qualunque non usato nel tabellone (STA INLINE (BNE $2 %$1 INC MYDOTS li (STA INLINE (LDA #10. (LDY BASE ;il registro Y contiene l'indirizzo  SCLOOP TYA ;relativo per l'elemento da esaminare (CLC (ADC STEP (TAY (LDA @BOARD,Y ;esamina il singolo elemento; se (TAX ;dall'elemento inizA #0 (SBC VAL (STA VAL (LDA #0 (SBC VAL+1 (STA VAL+1  END1 LDA VAL+1 (PHA (LDA VAL (PHA (LDA RETURN+1 (PHA (LDA RETURN (PHA (RTS (  ;subroutine per l'analisi delle singole direzioni   SCAN LDA FRIEND ;poni le condizioni inizia(CMP #3 ;quattro pedine in fila (BCC $1 (LDA #244. ;nel caso esci dalla subroutine (STA VAL (LDA #1. (STA VAL+1 (JMP END %$1 DEC DIR (BPL SCANNER  END LDA FRIEND ;poni il segno opportuno a VAL  BPL END1 (SEC (LDe spazi liberi (BCC $1 ;o occupati da pedine dello stesso (CLC ;giocatore di fianco all'elemento base (LDA SCORE (ADC VAL (STA VAL (LDA #0 (ADC VAL+1 (STA VAL+1 (LDA MYDOTS ;controlla se ci sono almeno uattro pedine in fila esci (LDA #0 ;dalla subroutine conn VALUE=500 (STA MYDOTS (STA FREE (STA SCORE (JSR SCAN (LDY DIR (LDA NEGINC,Y (STA STEP (JSR SCAN (LDA FREE ;aggiungi SCORE a VAL solo (CMP #3 ;se ci sono almeno tr(STA VAL+1 (JMP END  LEGAL LDA #0 ;poni le condizioni iniziali (STA VAL (STA VAL+1 (LDA #3 (STA DIR  SCANNER LDY DIR ;calcola SCORE per ogni direzione (LDA POSINC,Y ;e nel caso aggiungilo a VAL; se ci (STA STEP ;sono q(TYA ;dall'alto e mettilo in BASE (ADC #18. (TAY (LDA @BOARD,Y (BEQ $3 (PLA  ;calcola il valore della colonna (CPY #36. ;controlla se la mossa e' valida (BCS LEGAL ;se no poni VAL=-10000 (LDA #240. (STA VAL (LDA #216. ND (PLA ;calcola l'indirizzo relativo di (ASL A ;board[0,column]; il carry resta resettato (TAY ;calcola l'indirizzo relativo dell'ultima %$3 STY BASE ;casella libera della colonna partendo 'indirizzo del tabellone di gioco (STA BOARD (PLA (STA BOARD+1 (PLA ;calcola il valore assegnato alla pedina (PLA ;del giocatore per cui calcoli la (BMI $1 ;funzione value (LDA #5 (BPL $2 %$1 LDA #0FB %$2 STA FRIE .EQU 0B  SCORE .EQU 0D  INLINE .EQU 0E   ;prendi i dati dallo stack (PLA ;salva l'indirizzo di ritorno (STA RETURN (PLA (STA RETURN+1 (PLA ;scarta i soliti 4 byte inutili (PLA (PLA (PLA (PLA ;salva lO^A#close(pictures); #initturtle; #fillscreen(white); #viewport(186,276,3,189); #fillscreen(black); #viewport(187,277,3,189); #pencolor(none); #moveto(189,164); #chartype(10); #top:='FOURIN AROW'; #for i:=1 to 11 " do begin )wchar(top[i]); )turntck(aux,6,24,0,24,24,3+26*column,9+26*row,10)  end;   procedure start;  var top:string; $i:integer; $pictures:file of packed array[1..24,1..48] of boolean;  begin #reset(pictures,'pictures'); #aux:=pictures^; #get(pictures); #apple:=pictures^; +note(23,35); +note(25,35); +note(26,70); +note(26,35) (end  end;   procedure start1;  var row,column:integer;  begin #viewport(3,182,164,189); #fillscreen(black); #viewport(0,279,0,191); #for row:=0 to 5 #do for column:=0 to 6 &do drawblo26,35); +note(26,35); +note(28,35); +note(30,35); +note(26,70); +note(25,35); +note(21,35); +note(26,35); +note(26,35); +note(28,35); +note(30,35); +note(31,35); +note(30,35); +note(28,35); +note(26,35); +note(25,35); +note(21,35); to 20 +do begin 1for j:=1 to 20*i 1do ; 1note(1,1) .end (end  end;   procedure sound2;  begin #if sound #then begin +note(26,35); +note(26,35); +note(28,35); +note(30,35); +note(26,35); +note(30,35); +note(28,35); +note(21,35); +note(; +note(31,20); +note(36,25); +note(0,50); +note(31,30); +note(36,125) (end  end;   procedure sound1;  var i,j:integer;  begin #if sound #then begin +for i:=1 to 30 +do begin 1for j:=1 to random mod 20 1do ; 1note(1,1) .end; +for i:=1  function gt(alpha,beta:gametrack):boolean;  var i:integer;  begin #for i:=1 to 40 #do if alpha[i]>beta[i] &then begin .gt:=true; .exit(gt) +end; #gt:=false  end;   procedure sound0;  begin #if sound #then begin +note(7,20); +note(22,20)$quit:boolean; $maxdepth:integer;   procedure play;forward;   procedure home;  var i:integer;  begin #pencolor(none); #chartype(0); #for i:=0 to 2 #do begin )moveto(192,22+8*i); )wstring(' ') &end  end;  $keyin:char; $time:integer; $sound:boolean; $base1,base,basec,baseh:link; $movenum:integer; $trace:gametrack; $starter:mover1; $mirror:integer; $notset:boolean; $learned:boolean; $status:(full,learning,tracing); $numcol:array[0..21]of integer; fc); %matrix=array[0..7,0..8] of integer; %link=^game; %game=packed record 4move:gametrack; 4first:mover1; 4next:link 1end;  var apple:packed array[1..24,1..48] of boolean; $aux:packed array[1..24,1..48] of boolean; $board:matrix; $i,j:integer; (*$C copyright Carlo Magnaghi *)  (*$S+,G+,R-*)  program fourinarow;  uses turtlegr,applestu;  const compudot=5; &humandot=-5; &emptydot=0; &outdot=maxint; &fourline=500; &illegal=-10000;  type gametrack=packed array[1..40] of 0..7; %mover1=(fh,o(90); )move(2); )if (i=4)or(i=8) )then begin 1turnto(-90); 1move(8) .end &end; #move(1); #wchar(chr(1)); #moveto(192,150); #wstring('written by'); #moveto(193,141); #wstring('C. Magnaghi'); #moveto(192,132); #wstring('20 MAY 1983'); #for i:=120 downto 95 #do if odd(i) &then drawblock(i,15,0,0,100,1,186,i,15); #drawblock(aux,6,0,0,24,24,186,95,4); #drawblock(apple,6,0,0,24,24,186,95,14); #start1  end;   procedure remember;  var fst:boolean; $aux,aux1:link; $errcode:integerdot #do row:=row+1; #board[row,column]:=who  end;   function value(column,whose:integer; board:matrix):integer; external;   function rvalue(column,depth,whose,dummy:integer; board:matrix):integer;  var i,k,bestvalue:integer;  begin #k:=value(cox,6,24,0,24,24,c,9+26*(6-i),8); &drawblock(apple,6,who,0,24,24,c,9+26*(5-i),14); &i:=i+1 #until board[i,column]<>0  end;   procedure domove(who,column:integer; var board:matrix);  var row:integer;  begin #row:=0; #while board[row+1,column]=empty1move:=trace; 1first:=starter .end &else reduced:=true; #until reduced or (i<2)  end;   procedure grmove(who,column:integer);  var i,c:integer;  begin #i:=0; #c:=3+26*(column-1); #if who>0 #then who:=0 #else who:=24; #repeat &drawblock(auj:=j+1; 4aux:=aux^.next 1end )end; &for k:=0 to 7 &do ymax[k]:=0; &for k:=1 to 40 &do ymax[trace[k]]:=ymax[trace[k]]+1; &c:=0; &for k:=1 to 7 &do if ymax[k]<6 )then c:=c+1; &if j>=c-numcol[i div 2] &then with aux1^ +do begin 1next:=aux; i-2; &trace[i]:=0; &trace[i-1]:=0; &trace1[i]:=7; &trace1[i-1]:=7; &aux:=base; &j:=0; &k:=0; &while gt(trace,aux^.move) &do aux:=aux^.next; &aux1:=aux; &while (aux<>nil)and(k<8) &do begin ,k:=k+1; ,if not(gt(aux^.move,trace1)) ,then begin 4tarter &end; #aux1^.next:=aux2; #goto 2;  1: new(base); #with base^ #do begin )next:=aux; )move:=trace; )first:=starter &end;  2: for j:=1 to 40 #do if trace[j]=0 &then trace1[j]:=7 &else trace1[j]:=trace[j]; #reduced:=false; #repeat &i:=#if gt(aux^.move,trace) #then goto 1; #cont:=true; #while (cont and (aux<>nil)) #do if gt(trace,aux^.move) &then begin .aux1:=aux; .aux:=aux^.next +end &else cont:=false; #new(aux2); #with aux2^ #do begin )next:=aux; )move:=trace; )first:=sr aux,aux1,aux2:link; $trace1:gametrack; $ymax:array[0..7]of integer; $c,i,j,k:integer; $cont,reduced:boolean;  begin #i:=40; #learned:=true; #while trace[i]=0 #do i:=i+1; #trace[i]:=0; #trace[i-1]:=0; #aux:=base; #if aux=nil #then goto 1; :=true; #while (aux<>nil)and(cont) #do if gt(trace,aux^.move) &then aux:=aux^.next &else cont:=false; &if aux=nil &then badgame:=false &else if aux^.move=trace +then badgame:=true +else badgame:=false  end;   procedure learn;  label 1,2;  va:=aux^.next .end; +aux:=baseh; +while aux<>nil +do begin 1memory^:=aux^; 1put(memory); 1aux:=aux^.next .end; +close(memory,lock) (end; #exit(program)  end;   function badgame:boolean;  var cont:boolean;aux:link;  begin #aux:=base1; #cont&then aux1^.next:=nil; &close(memory)  end;   procedure memorize;  var aux:link; $memory:file of game;  begin #if learned #then begin +rewrite(memory,'lost.games'); +aux:=basec; +while aux<>nil +do begin 1memory^:=aux^; 1put(memory); 1aux(fst) &then begin .fst:=true; .aux1^.next:=nil +end; &while not(eof(memory)) &do begin ,if fst ,then begin 4fst:=false; 4baseh:=aux 1end; ,aux^:=memory^; ,aux1:=aux; ,new(aux); ,aux1^.next:=aux; ,get(memory) )end; &if not(fst) t(program) (end; #(*$I+*) #new(aux);fst:=true; #while (not(eof(memory))and(memory^.first=FC)) #do begin )if fst )then begin 1fst:=false; 1basec:=aux .end; )aux^:=memory^; )aux1:=aux; )new(aux); )aux1^.next:=aux; )get(memory) &end; &if not; $memory:file of game;  begin #baseh:=nil;basec:=nil; #(*$I-*) #reset(memory,'lost.games'); #errcode:=ioresult; #if errcode=10 #then begin +close(memory); +exit(remember) (end; #if errcode<>0 #then begin +writeln('I/O error ',errcode); +exilumn,whose,board); #bestvalue:=abs(k); #if (bestvalue=fourline)or(bestvalue=-illegal)or(depth=maxdepth) #then rvalue:=k-depth*whose #else begin +domove(compudot*whose,column,board); +if whose=1 +then begin 3bestvalue:=maxint; 3for i:=1 to 7 3do begin 9k:=rvalue(i,depth+1,-whose,bestvalue,board); 9if kend 6end; 3rvalue:=bestvalue 0end +else begin 3bestvalue:=-maxint; (num<>4) &then begin .notset:=false; .if num>4 .then mirror:=8 +end; &if status=tracing &then begin .movenum:=movenum+1; .trace[movenum]:=abs(mirror-num); .if movenum=40 .then status:=learning * end; &domove(humandot,num,board); &grmove(-1,nu192,30); Achartype(10); Awstring('ops, I lose'); Asound1; Aread(keyin); Ahome; Aexit(play) >end 6end .end  end;   procedure play;  var num,c1:integer; $cont:boolean;  begin #c1:=i; #base1:=base; #repeat &num:=input(c1); &if (notset)and4num:=num+1 1until board[y,x]<>who; 1if num>3 1then begin 9if who>0 9then begin Apencolor(none); Amoveto(192,30); Achartype(10); Awstring('wow I win !'); Asound2; Aread(keyin); Ahome; Aexit(play) >end 9else begin Apencolor(none); Amoveto(1 #do for dy:=-1 to 1 &do if (dx<>0)or(dy>0) )then begin 1x:=column;  y:=row; 1num:=-1; 1repeat 4x:=x+dx; 4y:=y+dy; 4num:=num+1 1until board[y,x]<>who;  x:=column; 1y:=row; 1repeat 4x:=x-dx; 4y:=y-dy; 10); #wstring('It''s a draw'); #read(keyin); #home; #exit(play)  end;   procedure four(column:integer);  var row,who,dx,dy,x,y,num:integer;  begin  row:=1; #while board[row,column]=0 #do row:=row+1; #who:=board[row,column]; #for dx:=0 to play); #83,115:sound:=not sound &end; &drawblock(apple,6,24,0,24,24,3+26*n,165,10) #until false  end;   procedure draw;  var i:integer;  begin #for i:=1 to 7 #do if board[1,i]=0 &then exit(draw); #pencolor(none); #moveto(192,30); #chartype(-wstring('( Yes/No )'); -read(keyin); -if ((keyin='Y')or(keyin='y'))and 0(status=tracing)and(movenum<39) -then begin 5status:=learning; 5trace[movenum+1]:=4; 5trace[movenum+2]:=4; 5if memavail>1024 5then learn 2end; -home *end; #82,114:exit(en begin 2input:=n+1; 2exit(input) /end; #81,113:begin -quit:=true; -exit(play) *end; #84,116:begin -chartype(10); -pencolor(none); -moveto(192,38); -wstring('Was my move'); -moveto(192,30); -wstring('really bad?'); -moveto(192,22); h:char; $n:integer;  begin #if keypress #then read(keyin); #n:=c1-1; #repeat &read(ch); &drawblock(apple,6,24,0,24,24,3+26*n,165,0); &case ord(ch) of ' 8:begin -n:=n-1; -if n<0 -then n:=6 *end; '21:n:=(n+1) mod 7; '32:if board[1,n+1]=0 *th; )if k>bestval )then begin 1bestval:=k; 1bestmove:=i .end &end; #choice:=bestmove;  if not(chance)and(status=tracing) #then begin +status:=learning; +if memavail>1024 +then learn (end  end;   function input(c1:integer):integer;  var c)drawblock(apple,6,time,0,24,24,186,95,14); )k:=rvalue(i,1,1,-maxint,board); )trace[movenum]:=abs(mirror-1); )if k>-490 )then if badgame .then k:=-490; )if k>-490 )then chance:=true; )if k<-490 )then numcol[movenum div 2]:=numcol[movenum div 2]+1 $2:maxdepth:=9; $3:maxdepth:=7; $4:maxdepth:=5;  5,6,7:maxdepth:=4 #end; #if maxdepth>(43-movenum) #then maxdepth:=43-movenum; #for i:=1 to 7 #do begin )time:=24-time; )drawblock(apple,6,0,0,24,24,186,95,4);   function choice:integer;  var i,k,bestval,bestmove:integer; $chance:boolean; $j:0..7;  begin #chance:=false; #numcol[movenum div 2]:=0; #bestval:=-maxint; #j:=0; #for i:=1 to 7 #do if board[1,i]=0 &then j:=j+1; #case j of # 1:maxdepth:=1;3for i:=1 to 7 3do begin 9k:=rvalue(i,depth+1,-whose,bestvalue,board); 9if k>bestvalue 9then begin Abestvalue:=k; Aif bestvalue>=dummy Athen begin Irvalue:=bestvalue; Iexit(rvalue) Fend >end 6end; + rvalue:=bestvalue 0end (end  end; m); &four(num); &draw; &movenum:=movenum+1; &c1:=choice; &if (notset)and(c1<>4) &then begin .notset:=false; .if c1>4 .then mirror:=8 +end; &if status=tracing &then begin & trace[movenum]:=abs(mirror-c1); .if movenum=40 .then status:=learning +end; &domove(compudot,c1,board); &grmove(1,c1); &drawblock(apple,6,24,0,24,24,3+26*(c1-1),165,10); &four(c1); &cont:=true; &while (base1<>nil)and(cont) &do if gt(trace,base1^.move) )then base1:=base1^.next )else cont:=fal ** **'); #conv(19,' ** *:::*** ** **'); #conv(18,' *::**::**::** * *'); #conv(17,' *:::::***:::::* * *'); #conv(16,' *:::::::::::::::* ******** ********'); #conv(23,' *:* ****** ******'); #conv(22,' *::* **** ****'); #conv(21,' *:::* *** ***'); #conv(20,' *::::*  program makepic;  var f:file of packed array[1..24,1..48] of boolean; !  procedure conv(row:integer;str48:string);  var i:integer;  begin #for i:=1 to 48 #do f^[row,i]:=(str48[i]='*')  end;   procedure sub1;  begin #conv(24,' * O^A0,24,24,3+26*(i-1),165,10); .play; .basec:=base +end &else begin .base:=baseh; .starter:=fh; .movenum:=0; .drawblock(apple,6,24,0,24,24,81,165,10); .i:=4; .play; .baseh:=base +end; &if quit &then memorize; &start1 #until false  end. &then begin .base:=basec; .starter:=fc; .movenum:=1; .i:=random mod 3 + 3; .if i<>4 .then begin 6notset:=false; 6if i>4 6then mirror:=8 3end; .trace[1]:=abs(mirror-i); .domove(compudot,i,board); .grmove(1,i); .sound0; .drawblock(apple,6,24,,22); &wstring('(Comp/User)'); ¬set:=true; &mirror:=0; &if status=learning &then status:=tracing; &for i:=1 to 40 &do trace[i]:=0; &read(keyin); &home; &randomize; &if (keyin='Q')or(keyin='q') &then memorize; &if (keyin='C')or(keyin='c') rd[i,0]:=outdot; ,board[i,8]:=outdot )end; &for i:=0 to 8 &do begin ,board[0,i]:=outdot; ,board[7,i]:=outdot )end; &chartype(10); &pencolor(none); &moveto(192,38); &wstring('Who of us'); &moveto(192,30); &wstring('goes first?'); &moveto(192se; &draw; &sound0 #until false  end;   begin #time:=0; #sound:=true; #quit:=false; #remember; #start; #status:=learning; #learned:=false; #repeat &for i:=1 to 7 &do for j:=1 to 6 )do board[j,i]:=emptydot; &for i:=0 to 7 &do begin ,boa '); #conv(15,' *::::::::::::::* '); #conv(14,' *::::::::::::::* '); #conv(13,' *::::::::::::::* ')  end; !  procedure sub2;  begin #conv(12,' *::::::::::::::* '); #conv(11,' *::::::::::::::* '); #conv(10,' *::::::::::::::* '); #conv( 9,' *::::::::::::::* '); #co FOURINAR (xHpP``@@?@   8@f?@@@    8@F8nv( 2,' '); #conv( 1,' ')  end;   begin #sub1; #sub2; #rewrite(f,'pictures'); #put(f); #sub3; #sub4; #put(f); #close(f,LOCK)  end. #conv( 6,' ************* * * '); #conv( 5,' *********** * ** ** '); #conv( 4,' *** *** *** *** '); #conv( 3,' '); #co * '); #conv( 9,' ************** * * '); #conv( 8,' *************** * * '); #conv( 7,' ************** * * '); 3,' ************** * * ')  end;   procedure sub4;  begin #conv(12,' ************** * * '); #conv(11,' ************** * * '); #conv(10,' ************** *nv(17,' ***** ***** * ** * ** '); #conv(16,' *************** * *** * '); #conv(15,' ************** * * '); #conv(14,' ************** * * '); #conv(1#conv(21,' *** * * '); #conv(20,' **** * * '); #conv(19,' *** * * '); #conv(18,' ** ** ** ** ** ** '); #corocedure sub3;  begin #conv(24,' '); #conv(23,' * * '); #conv(22,' ** ** '); 4,' *:::**:::** *** ***'); #conv( 3,' *** *** **** ****'); #conv( 2,' ****** ******'); #conv( 1,' ******** ********')  end;   pnv( 8,' *:::::::::::::::* * *'); #conv( 7,' *::::::::::::::* * *'); #conv( 6,' *:::::::::::::* ** **'); #conv( 5,' *:::::::::::* ** **'); #conv( Gpȡ#؏צ *@ ۨڨ(ȡ& š2$Jߡ#$2$}0ߡZȡ$ȡ3 צ ops, I lose &⫀˄ šá%䥀婀ٕ(á٥˄ šá婀  It's a drawR `ߤ ؤáߤ ؤ ȡ ȡō݂܂ڤ ۤˡݕܕڤ ۤˡšmš5  wow I win !.0468:<>@BDFHJLNPRTVXZ\^`bdfhjlnprtvxz|~VR܏ǥ   ,ȡ ؤáá  & Was my move really bad? ( Yes/No )YéyÍÄ'Ʉ,婀婀(š ߓ߹t  "$&(*,_婀š šɡšޓÄ(š 0 V ܏ǥ۹ɡ ȡ2RܑPQQPšQPPġPRRPB  ȡ ݤá߹ . ( "  &" +š+䕫  ȡޕޥǺ_Ǻ ەۤ ؤˡ;\ ٤áۤ ٤ښ! ,ڨHQQPPP'Íݩ Í Q܏܏áJPRSRSȡ2RܑPQQPɡQPPȡPRRPIPRSRSȡ (ȡ*  ȡ ɡġ ښ횹ɍ5\?4N šK ە ښ٢ ؚ  ښ(ȡ9á ڣ ڟɄ ڣ ب أ +Inz ۟ڄۣ ۟áۥ :J (áڟáTڥHڟ˄ ڣ  or    ܣÄ$ءګܨ  ٢ ښؓ٢  $ءګܨ  ٢ ښؓ٢ Gt Ɓ. Vצ lost.games؟ˡب أ ؟ˡǖצ written byǍצ C. MagnaghiDŽצ 20 MAY 1983x*_́*ʁġ**dǺ***KǺ_Ǻ_+L>n Ɓ1  lost.games" á  ˡ&צ I/O errȡ.ȡK؏ ُ 6- b+ƁWH+picturesK+H++H+ Ǻǽ  ǻǽ ǽǤ צ FOURIN AROWP* ́*ʁȡ,*Z**Í Z**ȡ ُȡ([Lpߡ############F##############F#ǶǤǽ  ǿ ؕ(áإǥ ڄ婀 0   ܩ ȡ4 ۩ ȡۤ ܤ۹ܹ ܩ ȡ(ܤ ܤ ܹ ܩ ȡ( ܤ ܤܹ &צ Who of usצ goes first?צ (Comp/User)á( ܩ ȡ婀ܹQéqÍ Cécite(op[0,linenum]); %readnum(x+m+3,y,problem[linenum,1]); %gotoxy(x+2*m+3,y-1); %write('='); %readnum(x+2*m+6,y,problem[linenum,2]) "end;  begin #repeat &readline(1,8,0); &for i:=0 to 2 &do begin ,ch:=readop(m*(i+1)+3*i,9); ,if ch<>rgtarrow ,t=rgtarrow)and(first or(num[i+1]<>' ')); -if ch<>rgtarrow -then num[i+1]:=ch; -first:=(ch=' ')or(ch=rgtarrow)and(num[i+1]=' ') *end $end; "begin %readnum(x,y,problem[linenum,0]); %ch:=readop(x+m+1,y); %if ch<>rgtarrow %then op[0,linenum]:=ch; %wr'for i:=0 to m-1 'do begin -repeat 0gotoxy(x+i-1,y-1); 0read(keyboard,ch); 0ch:=upcase(ch); 0gotoxy(x+i-1,y-1); 0if ch<>rgtarrow 0then write(ch) 0else write(num[i+1]); -until (ch>='A')and(ch<='J')or(ch=' ')and(i'); &unitclear(1); &read(ch) #until (ch<>'N')and(ch<>'n')  end;  procedure printsol(x,y:integer; solved:boolean);  var row,column,num,i:integer;  begin #for row:=0 to 2 #do for column:=0 to 2 &do for num:=0 to m-1 )do begin /gotoxy(x+(3+m)*column+num-1,(y+row*2+row div 2)-1); /if (solved)and(problem[row,columnn begin /sol[x]:=num; /imp[x]:=index; /suggested:=true; /usednum:=usednum+[num];  gotoxy(2*(ord(x)-65),16); /write(invs,num,norm); ,end 'else suggested:=false $end; $procedure piumeno; $begin 'carry:=0; 'status:=eq; 'for k:=m dy,count,count3,nz,max,min,a,axmod10:integer; &t1,t2,t3,res:array[1..10] of integer; &temp1,temp2,temp3:stringm; &status:(eq,g1,ge); &x:char; $procedure suggest(x:char; num:integer); $begin 'if num<0 'then num:=num+10; 'if not(num in usednum) 'the1until (all_used=false)or(free[1,i]=1) )end #until count='J'; ! countvar  end;  procedure try(index:char; undefnum:integer; usednum:set09);  var i:integer; $index1:char; $suggested,check1:boolean; "function check:boolean; "var i,j,k,h,temp,carre)or(free[0,i]=1); ,if free[1,i]>1 ,then repeat 4all_used:=true; 4for j:=0 to 2 4do if replace[problem[j,i][free[1,i]]]='=' 7then all_used:=false; 4if all_used and(free[1,i]>1) 4then free[1,i]:=pred(free[1,i]) 1,' '); &for i:=0 to 2 &do begin ,if free[0,i]>1 ,then repeat 4all_used:=true; 4for j:=0 to 2 4do if replace[problem[i,j][free[0,i]]]='=' 7then all_used:=false; 4if all_used and(free[0,i]>1) 4then free[0,i]:=pred(free[0,i]) 1until (all_used=falshen score[index]:=score[index]+presence[index]; &max:=0; &for index:='A' to 'J' &do if (score[index]>max)and(replace[index]='=') )then begin 1max:=score[index]; 1index1:=index .end; &if max=0 &then countvar; &replace[index1]:=count; &write(index,for index:='A' to 'J' ,do begin 2if temph[index]>0 2then score[index]:=score[index]+sqr(temph[index]+usedh); 2if tempv[index]>0 2then score[index]:=score[index]+sqr(tempv[index]+usedv); /end )end; &for index:='A' to 'J' &do if score[index]>0 )t2 ,do begin 2temp:=problem[i,j][free[0,i]]; 2if replace[temp]<>'=' 2then usedh:=usedh+1 2else temph[temp]:=temph[temp]+1; 2temp:=problem[j,i][free[1,i]]; 2if replace[temp]<>'=' 2then usedv:=usedv+1 2else tempv[temp]:=tempv[temp]+1; /end; #gotoxy(0,14); #write(clreol); #repeat &count:=succ(count); &for index:='A' to 'J' &do score[index]:=0; &for i:=0 to 2 &do begin ,usedh:=0; ,usedv:=0; ,for index:='A' to 'J' ,do begin 2temph[index]:=0; 2tempv[index]:=0 /end; ,for j:=0 to do for j:=0 to 2 (do for num:=1 to m +do problem[i,j][num]:=replace[problem[i,j][num]]; %exit(reorder) "end;  begin #initvar; #for i:=0 to 2 #do for j:=0 to 2 &do for num:=1 to m )do presence[problem[i,j][num]]:=succ(presence[problem[i,j][num]]);(do free[i,j]:=m; %for index:='A' to 'J' %do presence[index]:=0; "end; "procedure countvar; "begin %index1:=' '; %for index:='A' to 'J' %do if replace[index]>index1 %then index1:=replace[index]; %usednum:=ord(index1)-ord('@'); %for i:=0 to 2 %..'J'] of integer; $free:array[0..1,0..2] of integer; $count,temp:char; $all_used:boolean; "procedure initvar; "begin %for index:='A' to 'J' %do replace[index]:='='; %replace[' ']:=' '; %count:='@'; %for i:=0 to 1 %do for j:=0 to 2 2+i div 2)-1); )write('=') &end; #gotoxy(x-1,y+2); #for i:=1 to 3*m+6 #do write('_');  end;  procedure reorder;  var i,j,num,max,usedh,usedv:integer;  index,index1:char; $replace:array[' '..'J'] of char; $presence,score,temph,tempv:array[' '][num+1]<>' ') /then write(sol[problem[row,column][num+1]]) /else write(problem[row,column][num+1]) ,end; #for i:=0 to 2 #do begin )gotoxy(x+m*(i+1)+3*i-2,y); )write(op[1,i]); )gotoxy(x+m,(y+i*2+i div 2)-1); )write(op[0,i]); )gotoxy(x+2*m+3,(y+i*ownto 1 'do begin -temp:=carry; -if sol[temp1[k]]<=9 -then temp:=temp+sol[temp1[k]] -else if (status=eq)and(sol[temp2[k]]<=9)and(sol[temp3[k]]<=9) 2then begin :suggest(temp1[k],sol[temp3[k]]-sol[temp2[k]]-carry); :if not(suggested) :then exit(check); :temp:=temp+sol[temp1[k]] 7end 2else begin :temp:=temp+min; :status:=ge 7end; -if sol[temp2[k]]<=9 -then temp:=temp+sol[temp2[k]] -else if (status=eq)and(sol[temp1[k]]<=9)and(sol[temp3[k]]<=9) 2then begin :suggest(temp2[k],soj,0] ?end :else begin Btemp1:=problem[2,j]; Btemp2:=problem[1,j]; Btemp3:=problem[0,j] ?end; :if op[i,j]='/' :then begin Bk:=m; Bwhile (sol[temp2[k]]=0)and(k>1) Bdo k:=k-1; Bif sol[temp2[k]]=0 Bthen exit(check) ?end 7end .end; .case op[i,jmp3:=problem[j,2] t3[k] /then exit(check); $end; "begin %check:=false; %suggested:=false; %max:=0; %for i:=0 to 9 rry>0 'then exit(check); 'for k:=m downto count 'do if k>=count3 *then if res[k]<>t3[k] /then exit(check); 'if count9 2then begin :suggest(temp3[k],res[k]); :if not(suggested) 1 to m-nz /do if (t2[k]>0)and((t2[k]<=0)or(0 in usednum)) 2then exit(check); 'carry:=0; 'for k:=m downto 1 'do begin -res[k]:=carry; -for h:=0 to m-k -do res[k]:=res[k]+t1[k+h]*t2[m-h]; -carry:=res[k] div 10; -res[k]:=res[k] mod 10 *end; 'if ca-then begin 5t2[k]:=min; 5count:=k+1 2end; -t3[k]:=sol[temp3[k]]; -if t3[k]>9 -then begin 5t3[k]:=max; 5count3:=k+1 2end *end; 'nz:=m; 'for k:=m-1 downto 1 'do if (t1[k]>0)and((t1[k]<=9)or(0 in usednum)) *then nz:=k; *if nz9 -then begin 5t1[k]:=min; 5count:=k+1 2end; -t2[k]:=sol[temp2[k]]; -if t2[k]>9 check) ,end; $2,4,6,8:if odd(axmod10) ,then exit(check) )end &end; $begin 'if ((sol[temp1[m]]<=9)<>(sol[temp2[m]]<=9))and *(sol[temp3[m]]<=9) 'then begin /if sol[temp1[m]]<=9 /then begin 7a:=sol[temp1[m]]; 7x:=temp2[m] 4end /else begin 7a:=end; *3:begin /suggest(x,(7*axmod10)mod 10); /if not(suggested) /then exit(check) ,end; *7:begin /suggest(x,(3*axmod10)mod 10); /if not(suggested) /then exit(check) ,end; *9:begin /suggest(x,(10-axmod10)mod 10); /if not(suggested) /then exit('then exit(check) $end; $procedure perdiviso; &procedure casenum; &begin )case a of *0:if axmod10<>0 ,then exit(check); *5:if (axmod10<>5)and(axmod10<>0) ,then exit(check); *1:begin /suggest(x,axmod10); /if not(suggested) /then exit(check) , temp<9 ;then status:=eq 2end -else case status of 3eq:begin 9suggest(temp3[k],temp); 9if not(suggested) 9then exit(check) 6end; 3ge:if carry=0 6then status:=g1 6else status:=eq; 3g1:if temp<9 6then status:=eq 2end *end; 'if carry=1 [temp3[k]]<>temp 6then exit(check); 3ge:if sol[temp3[k]]carry:=1; >status:=eq ;end 6else if carry=0 ;then status:=g1 ;else status:=eq; 3g1:if (sol[temp3[k]]<>temp)and(sol[temp3[k]]<>(temp+1) mod 10) 6then exit(check) 6else ifl[temp3[k]]-sol[temp1[k]]-carry); :if not(suggested) :then exit(check); :temp:=temp+sol[temp2[k]] 7end 2else begin :temp:=temp+min; :status:=ge 7end; -carry:=temp div 10; -temp:=temp mod 10; -if sol[temp3[k]]<=9 -then case status of 3eq:if sol] of /'+','-':piumeno; /'*','/':perdiviso .end; ) end; %check:=true;  end;  begin #if undefnum=0 #then begin +write(bell,bell); +if printed +then begin 3gotoxy(0,4); 3write(showcurs,' C''e'' un''altra soluzione ->'); 3unitclear(1); 3read(ch); 3gotoxy(0,4); 3write(hidecurs,'-Sto'' pensando-',clreol) 0end; +printsol(1,19,true); +printed:=true (end #else begin +if sol[index]>9 +then begin 3for i:=0 to 9 3do if not(i in usednum) 6then begin >gotoxy(2*(ord(index)-65),16); >ɏ=ɏȡ_0ynAJȡ  J = J  @ȡ:ȡ"ɚ ȡ ȡɂݏ܂إ]   ˄/˥]   J  "]  ȡکۏکɂɏ٥] ȡJڏ ٩ˡٚ  ɏȡ_ צOK? ->&Nn˄P ȡAJȄ ݩɄۄܩÄ  ˍܩˡ  ܚ ܩ  Ä٥] کɂ۩ˡۚکɂ٥] ɏ=ܳܩö8@ڳ *'ȡ.ȡ݂݂ܩˡ  BdENIGMA una '); &if printed &then write('altra '); &write('soluzione ->',clreol); &unitclear(1); &read(ch); #until (ch='F')or(ch='f'); #write(clrscr)  end. write('Editazione',clreos); .problem:=copy; .printsol(1,8,false); .readproblem(true) +end; ©:=problem; &gotoxy(0,4); &write('-Sto'' pensando-'); &write(hidecurs); &reorder; &try('A',usednum,[]); &write(showcurs); &gotoxy(0,4); &write('Nessif (ch<>'E')and(ch<>'e') &then begin .{$I-} .repeat 1gotoxy(0,4); 1write('Numero cifre ->',clreos); 1readln(m) .until (m>0)and(m<=10); .{$I+} .gotoxy(0,4); .write('Aspetto i dati',clreol); .readproblem(false) +end &else begin .gotoxy(0,4); .#writeln(invs,': :'); #writeln(' ENIGMA di Carlo Magnaghi '); #writeln(': :',norm); #repeat &printed:=false; &sol[' ']:=0; &for index:='A' to 'J' &do begin ,sol[index]:=255; ,imp[index]:=' ' )end; &um) (end  end;  begin #showcurs:=chr(5); #hidecurs:=chr(6); #bell:=chr(7); #clreos:=chr(11); #clrscr:=chr(12); #norm:=chr(14); #invs:=chr(15); #rgtarrow:=chr(21); #clreol:=chr(29); #ch:=' '; #write(clrscr); #gotoxy(0,0); Fthen begin Nimp[index1]:=' '; Nusednum:=usednum-[sol[index1]]; Nsol[index1]:=255; Ngotoxy(2*(ord(index1)-65),16); Nwrite(' ') Kend ;end; 3sol[index]:=255; 3gotoxy(2*(ord(index)-65),16); 3write(' ') 0end +else try(succ(index),undefnum-1,usednwrite(i); >sol[index]:=i; # repeat Acheck1:=check >until not(check1) or not(suggested); >if check1 >then try(succ(index),undefnum-1,usednum+[i]); >if index<'J' >then for index1:=succ(index) to 'J' Cdo if imp[index1]=indexAJȡ J $nb  AJȡ/  J š  J @ȡȡiȡO]   ]   J v  ̀ʀȡỳʀȡd̀ʀȡMƀ]   J ƀ]   J ʀ̀AJ̀ʀȡƀ J        ȡR    ɡ#    š   \05 XXȡ  XXġXXȡYYȡꥀ              š ɸ   ġ6 ġ#    ˡ    ɡi   ȡO˲8   J  š(8     .  Ų.      ɡL ɶ ȡ8$  Ų$      ɸ  ġ    ɶ  ȡL    .   $ɶ   J .   š.    $  ˲B   J $   š$      ˲8   J    š     ɸ  ġ:B  J  ȷ˲8  J  Ȅ˲L  J  ȡ/˲L  J B W-˲B  J L W˲8  J    ȡ.  ˲L    á mnrjkˡ ˶˄ W  oW  WW  ?W   '  qaQ#= ˲L  J  ȥˡ ˲8   J  ɡ  V áVVa˲8   J  ˥˲8   J   ˄   ɡV ]RV?8    . áVV ɡVG,   J  Ȅ˲8   J  ȄsB  ˲8   J ˲L   J    ˲B   J    V    ˲8   J  ȡV˲8   J    J  Ȅ˲8   J  ȄsL  ˲8   J ˲B   J    ˲L   J    V˲B   J  ȡ" ˲B   J  Vå˲L #0ɡ ضY J ؚAJAؗA x  Vɸ  ġ  ˲L   J  ȡ" ˲L   J  Vå˲BƀÍƀš̀̀ʀȡ? ] ƀ  J =á̀ʀƀń"ƀƀʀƀÍʀJá  w [d J =Äƀ J á J ʀ皶 ̀ʀȡƀš̀̀ʀȡ? ] ƀ  J =á̀ʀƀń"ƀƀʈ AJ̀ʀȡs_ J š'ƀ J ƀ J _ J ق4 J š'ƀ J ƀ J 4 J ؂AJ̀ʀȡ<ƀ J š%ƀ J ƀ J ƀ J AJ̀ʀȡ6ƀ J ̀ʀȡAJ̀ʀȡ_ J 4 J ̀ʀȡ] ƀ ̀ ʀ J =ˡ_ʀ J _ʀ J ] ƀ ̀ ʀ J =ˡ4ʀ J 4ʀ Já8L] B] 8] 6L] B] 8] á8L] B] 8] 6L] B] 8] /áH B  J ń B  J á */ MO */  J_( á¡~צ C'&FéfÍr b  :8n ¥ J AJȡ*˩ J AJA E˩e˄tצNumero cifre -> ũ ȄצAspetto i dati5צ Editazione]Z]Z-Sto' pensando-A צNessuna ¡altra  soluzione ->צ ENIGMA di Carlo Magnaghi צ: :¥ J AJȡ*˩ J AJA E˩e˄tצNumero cifre -> ũ J  J A  J A    3>    צ: :e' un'altra soluzione ->&צ-Sto' pensando-¹襀 J  š ȡA J ۚ ݓޓݡۗ JɡgJ ȡZAJAáCAJA