home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Oakland CPM Archive
/
oakcpm.iso
/
cpmug
/
cpmug013.ark
/
15_PUZ.ASC
next >
Wrap
Text File
|
1984-04-29
|
6KB
|
154 lines
100 REM WRITTEN BY W.A.BURTON
101 WIDTH 80 : PRINT CHR$(26)
102 DIM A$(5,5), NM$(5,5), RV$(4,4), A(4,4) : BL$=" "
103 GOSUB 148
104 PRINT TAB(15); "WHAT IS YOUR LUCKY NUMBER (1 TO 25000)"; : INPUT X
105 IF X<1 OR X>25000 OR X<>INT(X) THEN PRINT "WRONG !!"; : GOTO 104
106 X=X MOD 197 : FOR Y=1 TO X
107 X9=RND(1) : X9=RND(-Y)
108 NEXT Y : X9=0 : PRINT CHR$(26)
109 PRINT TAB(20); "*** 15 PUZZLE ***" : PRINT : PRINT : PRINT
110 INPUT " DO YOU WANT INSTRUCTIONS"; R$
111 IF LEFT$(R$,1)="Y" THEN GOSUB 220
112 PRINT CHR$(26) : X9=1
113 PRINT "WAIT A FEW MOMENTS FOR PUZZLE TO BE CREATED"
114 GOSUB 172
115 GOSUB 179
116 GOSUB 159
117 PRINT : PRINT
118 REM 'COMMANDS' CHECKED HERE
119 R$="TRAP" : INPUT "YOUR PLAY"; R$
120 IF R$<>"HELP" THEN 125
121 PRINT : GOSUB 228 : PRINT
122 IF NM=1 THEN F$=" NORMAL " ELSE F$=" REVERSE "
123 PRINT TAB(15); "YOU ARE ATTEMPTING A"; F$; "SOLUTION"
124 PRINT : GOTO 119
125 IF LEN(R$)=1 THEN GOSUB 133
126 IF R$=A$(I+1,J) THEN SWAP A$(I,J), A$(I+1,J) : GOTO 131
127 IF R$=A$(I-1,J) THEN SWAP A$(I,J), A$(I-1,J) : GOTO 131
128 IF R$=A$(I,J+1) THEN SWAP A$(I,J), A$(I,J+1) : GOTO 131
129 IF R$=A$(I,J-1) THEN SWAP A$(I,J), A$(I,J-1) : GOTO 131
130 PRINT "INVALID COMMAND - TRY AGAIN !!" : GOTO 119
131 PRINT : PRINT : GOSUB 159 : TU=TU+1
132 GOTO 119
133 REM 'PAD' SINGLE CHARACTER ENTRIES
134 PD$=" " : PD$=PD$+R$
135 SWAP PD$, R$ : RETURN
136 REM DATA TABLES
137 DATA -1, -1, -1, -1, -1, -1, -1
138 DATA " 1", " 2", " 3", " 4", -1
139 DATA -1, " 5", " 6", " 7", " 8"
140 DATA -1, -1, " 9", 10, 11, 12
141 DATA -1, -1, 13, 14, 15, **, -1
142 DATA -1, -1, -1, -1, -1, -1
143 DATA 1, 2, 3, 4, 5, 6, 7, 8, 9
144 DATA 10, 11, 12, 13, 14, 15, 16
145 DATA 15, 14, 13, 12, 11, 10, " 9"
146 DATA " 8", " 7", " 6", " 5", " 4"
147 DATA " 3", " 2", " 1", **
148 REM LOAD EACH MATRIX
149 FOR X=0 TO 5 : FOR Y=0 TO 5
150 READ A$(X,Y) : NEXT Y,X : RESTORE
151 FOR X=0 TO 5 : FOR Y=0 TO 5
152 READ NM$(X,Y) : NEXT Y,X
153 FOR X=1 TO 4 : FOR Y=1 TO 4
154 READ A(X,Y)
155 NEXT Y, X
156 FOR X=1 TO 4 : FOR Y=1 TO 4
157 READ RV$(X,Y)
158 NEXT Y, X : RETURN
159 REM LOCATE THE BLANK (**)
160 FOR I1=1 TO 4
161 FOR J1=1 TO 4
162 IF A$(I1,J1)="**" THEN I=I1 : J=J1
163 NEXT J1, I1
164 IF (NM=1) AND (A$(4,4)="**") AND (A$(1,1)=" 1") THEN GOSUB 199
165 IF (RV=1) AND (A$(4,4)="**") AND (A$(1,1)="15") THEN GOSUB 210
166 REM PRINT OUT A$(ARRAY)
167 FOR X=1 TO 4
168 FOR Y=1 TO 4
169 PRINT BL$; A$(X,Y);
170 NEXT Y : PRINT : PRINT
171 NEXT X : PRINT : RETURN
172 REM 'SHUFFLE' A$(ARRAY) & A(ARRAY)
173 FOR X=1 TO 4 : FOR Y=1 TO 4
174 R8=INT(RND(1)*4)+1 : R9=INT(RND(1)*4)+1
175 IF X=R8 AND Y=R9 THEN 174
176 SWAP A$(X,Y), A$(R8,R9)
177 SWAP A(X,Y), A(R8,R9)
178 NEXT Y, X : RETURN
179 REM IS PUZZLE TO BE SOLVED IN 'NORMAL' OR 'REVERSE' FASHION
180 CO=0
181 IF A(1,2)=16 OR A(1,4)=16 THEN 186
182 IF A(2,1)=16 OR A(2,3)=16 THEN 186
183 IF A(3,2)=16 OR A(3,4)=16 THEN 186
184 IF A(4,1)=16 OR A(4,3)=16 THEN 186
185 GOTO 187
186 CO=CO+1
187 FOR X1=1 TO 4 : FOR X2=1 TO 4
188 FOR X3=1 TO 4 : FOR X4=1 TO 4
189 IF A(X1,X2) > A(X3,X4) THEN 191
190 NEXT X4, X3 : GOTO 192
191 CO=CO+1
192 A(X1,X2)=16
193 NEXT X2, X1
194 IF CO-(2*INT(CO/2))<>0 THEN 197
195 PRINT CHR$(26) : PRINT "THIS PUZZLE CAN BE SOLVED IN NORMAL ORDER"
196 NM=1 : PRINT : RETURN
197 PRINT CHR$(26) : PRINT "THIS PUZZLE CAN ONLY BE SOLVED IN REVERSE ORDER !! !"
198 RV=1 : PRINT : RETURN
199 REM CHECK FOR 'NORMAL' WIN
200 FOR X=1 TO 4 : FOR Y=1 TO 4
201 IF A$(X,Y)<>NM$(X,Y) THEN 203
202 NEXT Y, X : GOTO 204
203 RETURN
204 REM WIN
205 GOSUB 166 : PRINT : PRINT
206 PRINT TAB(25); "*** WINNER ***"
207 FOR X=1 TO 6 : PRINT : NEXT X
208 PRINT TAB(22); "YOU SOLVED IT IN"; TU; "MOVES"
209 GOTO 215
210 REM CHECK FOR 'REVERSE' WIN
211 FOR X=1 TO 4 : FOR Y=1 TO 4
212 IF A$(X,Y)<>RV$(X,Y) THEN 214
213 NEXT Y, X : GOTO 204
214 RETURN
215 REM GAME EXIT
216 PRINT : PRINT : R$="TRAP"
217 INPUT "DO YOU WANT TO TRY AGAIN"; R$
218 IF LEFT$(R$,1)="Y" THEN CLEAR : RUN 101
219 PRINT CHR$(26) : RESET
220 REM INSTRUCTIONS
221 PRINT CHR$(26)
222 PRINT "THE NUMBERS IN A '15 PUZZLE' (ZERO-15, PLUS THE BLANK '**') CAN BE ARRANGED"
223 PRINT "IN APPROXIMATELY 21,000,000,000,000 DIFFERENT WAYS..." : PRINT
224 PRINT "HOWEVER, ANY SINGLE ARRANGEMENT OF THE NUMBERS CAN ONLY BE REARRANGED"
225 PRINT "IN HALF THAT MANY WAYS. THEREFORE TO DEAL WITH ALL THE POSSIBILITIES, WE NEED"
226 PRINT "TWO MUTUALLY EXCLUSIVE OBJECTIVES. THE COMPUTER WILL GENERATE A PUZZLE TO BE"
227 PRINT "SOLVED AND TELL YOU WHICH OF TWO 'SOLUTIONS' TO ATTEMPT." : PRINT
228 PRINT"NORMAL: 1 2 3 4 REVERSE: 15 14 13 12" : PRINT
229 PRINT" 5 6 7 8 11 10 9 8" : PRINT
230 PRINT" 9 10 11 12 7 6 5 4" : PRINT
231 PRINT" 13 14 15 ** 3 2 1 **" : PRINT
232 IF X9=1 THEN RETURN
233 PRINT "REMEMBER THESE TWO DIAGRAMS, BECAUSE ONE (AND ONLY ONE) WILL REPRESENT THE"
234 PRINT "CORRECT SOLUTION TO A GIVEN PUZZLE. NOTE ALSO THAT IN BOTH CASES THE BLANK '**'"
235 PRINT "OCCUPIES THE LOWER RIGHT HAND CORNER." : PRINT
236 PRINT "HIT RETURN KEY FOR MORE" : WAIT 0,1,1
237 PRINT CHR$(26)
238 PRINT "A MOVE IS MADE BY SELECTING A NUMBER WHICH IS ADJACENT TO THE BLANK, AND MOVING"
239 PRINT "THAT NUMBER INTO THE SPACE WHICH THE BLANK OCCUPIED. TO DO SO, MERELY ENTER"
240 PRINT "THE NUMBER WHEN ASKED, 'YOUR MOVE ?'. " : PRINT
241 PRINT "IN THE CONTEXT OF THIS GAME, AN ADJACENT NUMBER IS ONE WHICH IS DIRECTLY"
242 PRINT "ABOVE, BELOW, TO THE RIGHT OF OR TO THE LEFT OF THE BLANK (THERE IS NO SUCH"
243 PRINT "THING AS DIAGONALLY ADJACENT)..." : PRINT
244 PRINT " EXAMPLE: 1 13 3 11" : PRINT
245 PRINT " 9 7 2 5" : PRINT
246 PRINT " 4 ** 12 8" : PRINT
247 PRINT " 6 14 10 15" : PRINT
248 PRINT "IN ABOVE EXAMPLE, THE ONLY LEGAL MOVES ARE: 4 - 7 - 12 - 14. THE COMPUTER"
249 PRINT "WILL REJECT INVALID MOVES. IF YOU FORGET POSITION THAT YOU ARE TRYING TO REACH,"
250 PRINT "ENTER 'HELP' WHEN ASKED, 'YOUR MOVE ?'. THIS WILL DISPLAY BOTH THE 'NORMAL'"
251 PRINT "AND 'REVERSE' OBJECTIVES." : PRINT
252 PRINT "HIT RETURN TO PLAY" : WAIT 0,1,1 : PRINT CHR$(26) : RETURN