Sokoban 80 by David Payne
A downloadable game
You are a warehouse worker im a warehouse. You need to push the crates onto their final positions as indicated by the dots.
You can only push crates, not pull them. You can only push one crate at a time. This version has only 1 level.
If you have managed to solve the level then try to do it in the minimum number of moves possible (463).
Copy (note that the Copy key is mapped to the End key in JSBeeb) to restart the level.
m - one less than the number of rows in the level
l - one less than the number in columns in the level
g(m,l) - the level data array
a,b,r - general purpose variables
x,y - x and y coordinates of worker
z - number of moves made
c - number of crates not on dots (the level has been completed and the game ends when this is zero)
k - key pressed
p - set when a move has been made. 8 = moving into a blank space, 3 = pushing a crate, 0 = not a valid move
0 - blank space
1 - dot
2 - crate
3 - crate on dot
4 - worker
5 - worker on dot
6 - wall
The level data is stored in the REM on line 100 (line 1000 in the expanded version). As the 7 "building blocks" as listed above only require 3 bits to store them (i.e. 000 to 110), 2 "building blocks" are stored in each character.
Program structure (referring to the expanded version):
lines 100 to 308 initialisation
lines 309 to 803 main game loop
lines 804 to 900 "game over"
lines 901 to 1000 data
Expanded listing with comments: 100l=13 101m=09 102DIMg(m,l) define the graphics characters 103FORa=&C00TO&C37 104?a=(a?&F17-32)*3 105NEXT read/decode the level data and display the level 106a=&1B54 107b=0 disable cursor keys for editing 108*FX4,1 200MODE4 disable cursor 201VDU23,1,0;0;0;0; initialise move count 202z=0 initialise crate not on dot count 203c=10 204FORj=0TOm 205FORi=0TOl 206g(j,i)=(?a-32)DIV8^b MOD8 300VDU224+g(j,i) 301a=a+b 302b=1-b 303NEXT 304PRINT 305NEXT display the number of moves made (0) 306PRINT;0 set the x and y coordinates of worker 307x=07 308y=04 309REPEAT 310k=GET-135 if key press was invalid then try again 400IFk<0ORk>4THENUNTIL0 401r=ASC(MID$("DCEGA",k+1,1))-64 402b=r DIV3-1 403a=r MOD3-1 look at what lies in the direction that we are going 500r=g(y+b,x+a)AND6 501p=0 if it's a blank space/dot or a crate with a blank space/dot on the other side of it then it's a valid move 502IFr=0THENp=8ELSEIFr=2THENIF(g(y+b*2,x+a*2)AND6)=0THENp=3 if not a valid move then try again unless Copy key was pressed in which case restart level 600IFp=0THENUNTILk=0:RUN valid move so increment move count 601z=z+1 make move move worker off current position 602g(y,x)=g(y,x)AND1 603x=x+a 604y=y+b increment c if crate was pushed off a dot 605c=c-(g(y,x)=p) move worker to new position 700g(y,x)=g(y,x)AND1OR4 also move crate to new position if pushing one 701g(y+b,x+a)=g(y+b,x+a)ORr decrement c if crate was pushed onto a dot 702c=c+(g(y+b,x+a)=p) redisplay "local" blocks affected by move 703FORr=-1TO1 800VDU31,x+a*r,y+b*r,224+g(y+b*r,x+a*r) 801NEXT display the number of moves made 802PRINTTAB(0,m+1);z 803UNTILc=0 enable cursor keys for editing 804*FX4,0 enable cursor 900VDU23,1,1;0;0;0; graphics data 901REM (( uKSWWSKuuKS__SKu4JiuuaJ44JiuuaJ4mmm JJJ level data 1000REMVVVVVV .!P PV.!P0 "P.!PRV&P.! @P&P.!PP "VVVVP60P &"000P & P P VVVVVV
The emulator that I use is an online one - JSBeeb. https://bbc.godbolt.org/
Simply copy and paste the program into it and type RUN.
The program assumes that PAGE (the start of the program) is set to &1900 which is the default in JSBeeb.
Leave a comment
Log in with itch.io to leave a comment.