Skip to content

Instantly share code, notes, and snippets.

@fu-sen
Last active February 12, 2021 12:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fu-sen/7274454 to your computer and use it in GitHub Desktop.
Save fu-sen/7274454 to your computer and use it in GitHub Desktop.
' 15 puzzle | MSX-BASIC
' Copyright (c) 2003 Keiichi Shiga (BALLOON | FU-SEN)
' The MIT License (MIT) - https://mit.balloon.net.eu.org/#2003
100 I$="123456789ABCDEF0":J$=I$:S=100
110 CLS:FOR L=S TO 1 STEP -1
120 U=INSTR(I$,"0"):R=RND(-TIME)*4+1
130 ON R GOSUB 280,290,300,310
140 IF C=U GOTO 120
150 GOSUB 320:GOSUB 220:NEXT L:S=0
160 GOSUB 220:PRINT:PRINT"SCORE ";S
170 IF I$=J$ THEN END
180 U=INSTR(I$,"0"):T=STICK(0)
190 ON T GOSUB 280,,290,,300,,310
200 IF C=U GOTO 180
210 GOSUB 320:S=S+1:GOTO 160
220 LOCATE 0,0,0
230 FOR Y=0 TO 3:FOR X=0 TO 3
240 N=VAL("&H"+MID$(I$,X+Y*4+1,1))
250 IF N=0 THEN PRINT ".. ";:GOTO 270
260 PRINT USING "## ";N;
270 NEXT X:PRINT:NEXT Y:RETURN
280 C=U+(U>4)*4:RETURN
290 C=U-(U MOD 4>0):RETURN
300 C=U-(U<13)*4:RETURN
310 C=U+(U MOD 4<>1):RETURN
320 H$=MID$(I$,C,1):MID$(I$,C,1)="0"
330 MID$(I$,U,1)=H$:U=C:RETURN
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment