Skip to content

Instantly share code, notes, and snippets.

@fu-sen
Last active April 19, 2025 02:32
Show Gist options
  • 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-2025 BALLOON | FU-SEN
' The MIT License (MIT) - https://mit.balloon.net.eu.org/#2003-2025
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 330:GOSUB 220:NEXT L:S=0
160 GOSUB 220:PRINT:PRINT"COUNT ";S
170 IF I$=J$ THEN END
180 U=INSTR(I$,"0"):T=STICK(0)
190 ON T GOSUB 280,320,290,320,300,320,310
200 IF C=U GOTO 180
210 GOSUB 330: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 RETURN
330 H$=MID$(I$,C,1):MID$(I$,C,1)="0"
340 MID$(I$,U,1)=H$:U=C:RETURN
@fu-sen
Copy link
Author

fu-sen commented Jan 29, 2025

15puzzle_20250129

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment