This is a simple one - it's an over-engineered Pico-8 version of this Commodore 64 BASIC program:
10 PRINT CHR$(205.5+RND(1)); : GOTO 10 |
It's a random maze generator, and some folks wrote an interesting book about it
nice, i had forgotten about this.
though i was playing with those truchet variants two weeks ago, here's mostly the same thing, rotated 45°:
Not to sound like Orac, but FASCINATING ! Absolutely FASCINATING !
With the link of the article, (folks writing a book about it) especially so !
Now here's a question. Is it possible to use this method to build an airtight maze. That is, the player could be placed anywhere within and be able to reach every single point within ?
Awesome! I'm currently reading this book. Really cool to see this here.
a sad thing is, we can't adapt this one-liner to pico since print() forces a newline.
too bad, that was very close:
::io:: print(rnd(2)>1 and [[\]] or [[/]]) goto io |
having print() and println() would have been nice.
The other thing, too, is that the "/" and "\" characters in the Pico-8 font are printed with pixel-wide gaps, so the maze effect doesn't work visually.
That's part of why my code is so over-wrought: I started with just plain print, then implemented a screen character buffer, then wrote my own print function for tighter slashes, then just called it a day & shipped it :)
It's a pretty dumb literal translation, could definitely use some rethinking
ah yes, those CHR$ were more akin to glyphs (they were not regular slashes), but we don't have much of those either.
well, the closest thing we have to one-liners is tweetjam's 140 chars, that might be worth a try...
Here's an implementation that slips in at 136 chars.
Here's the code with sensible whitespace:
Basically, it uses the top part of the angle brackets (<>) as its diagonal and covers up the bottom part with a different character.
hey, very clever LRP! I've started my own take but the char count is still overboard... going back at it!
Now 114 characters!
Code:
This version uses clip() to limit how much of the brackets will print instead of printing the whole character and covering it up. Also I remembered that you can use the question mark instead of print().
Edit: Oh, you can pass cursor parameters to the question mark shorthand, too, so I cut another print() instance.
135 chars with plenty of room left
line() synchronized with print() for scrolling
that's why the slashes are huge (6x6)
cls() x=1 y=0 n=120 ::io:: d=rnd(2)>1 and 0 or 5 line(x+5-d,y,x+d,y+5,11) x+=6 if(x>n+6) x=1 y+=6 print(' ') if(y>n) y=n flip() goto io |
did we just start a 10printjam ? :)
112 chars!
cls()x=1y=0::t::d=flr(rnd(2))*5line(x+5-d,y,x+d,y+5)x+=6 if(x>126)x=1print(' ')y+=6 if(y>120)y=120 flip()goto t |
had to kick that beautiful green though
also '?' won't work there
Oh awesome! I was hoping some folks could improve on my first garbage attempt :D
ultrabrite: Nice! Well done.
lmorchard: Thanks for posting this. It was a fun puzzle and interesting history. It makes me wonder what the "most interesting shortest" pico-8 program is. There are a lot of contenders in the tweetjam thread.
that was fun, and the very reason why you have to love this board. you never know what you'll end up doing next :)
lmorchard, your cart is a great tribute to the c64 version, and a piece of art in itself! you could even go further, simulate the boot sequence, the one-liner appearing letter by letter (with a clickety sound?), 'run' and there you go. press a button, you get "break in 10\nready", another press, 'run'... (like those screenshots in the book). overengineer at will ;)
I know finding this in splore would blow my mind :)
oh, btw, 13 would be a truer color:
thanks a lot, have fun !
108 characters ?
x=0 y=0 cls() repeat a=flr(rnd(2))*8 line(x+a,y,8-a+x,y+8) flip() x+=8 if (x==128) x=0 y+=8 until z |
Or even 103-characters ? Counting 2-characters per CR. 47-symbols.
cls() for y=0,15 do for x=0,15 do a=flr(rnd(2))*8 line(x*8+a,y*8,8-a+x*8,y*8+8) flip() end end |
dw817, that's even 99 and 94 chars according to pico-8!
but you cheated, having the whole thing scroll up is part of the challenge!
nice try :)
Got to scroll hmm ? Let me see ...
y=0 cls()repeat for x=0,20 do a=flr(rnd(2))*6 line(x*6+a,y*6,6-a+x*6,y*6+6) flip()end y+=1 if(y>20)y=20 print""until z |
BTW, how do you count the number of characters in PICO ? I'm using Notepad ++ but it also counts CRs.
118, not bad! click on the token count! (made a few tweetjams before noticing)
me I'm at 110, thanks for print"" :) i think you can replace yours by ?""
cls()x=1y=0::t::d=flr(rnd(2))*5line(x+5-d,y,x+d,y+5)x+=6 if(x>126)x=1print"" y+=6 if(y>120)y=120 flip()goto t |
Ah !
This would be a lot easier if you could force a new variable into FOR/NEXT, I.E.:
FOR I=1,10 DO PRINT I I=0 END |
But unlike other languages, PICO has a mind of its own when making a FOR/NEXT loop and changing the variable makes no difference, giving results, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10.
I remember writing a bunch of 1-liners for Apple ][ years ago, each had to be less than 240-characters. I had little adventure games, shooters, a little word-processor, paint program, and other curious things.
Writing mini-code like this reminds me of it.
...
I'm not seeing a way to make your code any smaller. I changed the x=1 to x=0 as I thought that was confusing, but even changing your code to work with this new starting position, it's not any smaller.
cls()x=0y=0::t::d=flr(rnd(2))*6line(x+d,y,x+6-d,y+6)x+=6 if(x>125)x=0print"" y+=6 if(y>120)y=120 flip()goto t |
Here is a maze pattern where you can travel up or down:
x=0 y=0 b={0,0,0,1,0,1,1} c=0 cls() repeat a=b[c+1]*8 line(x+a,y,8-a+x,y+8) flip() x+=8 if x==128 then x=0 y+=8 end c+=1 if c==7 then c=0 end until forever |
I think you win this round for smallest code, UltraBrite.
Ah ! But using the dreaded GOTO ! :D
I think a new coding challenge is in order.
haha thanks. so I guess a victory lap is appropriate:
cls()y=0::t::for x=1,121,6 do d=flr(rnd(2))*5line(x,y+d,x+5,y+5-d)flip()end ?"" y=min(y+6,120)goto t |
one hundred characters V(^-^)V
Surprising that "?" is at all allowed for a command. I hadn't seen behavior like that since the T.R.S. 80, and even then after you typed it, it automatically changed it to PRINT.
Minju, it had some abbreviations too. "Gos." "Ret."
GFA is rather famous for allowing you to type abbreviated commands, but then enlarges them once you press ENTER. It even has the ability of completing your quotes or parentheses for formula if you forget them.
However, I'm not going to use "?" for print ever ...
You did point out something that slowed down my code and I MIGHT'VE been able to beat your last micro entry. Maybe. :)
I keep typing STEP in the FOR/NEXT and it keeps not being recognized, so I had to work around it without STEP.
Now I see it is merely an optional 3rd argument. That will definitely help my future coding so this knowledge is vital for me and I'm glad you showed me !
BlitzMAX has an added benefit. You can use TO or UNTIL. Thus:
FOR I=0 UNTIL 8 PRINT I NEXT |
Will print 0, 1, 2, 3, 4, 5, 6, 7 ... and stop. The UNTIL says to quit just one element before.
And yep, the victory lap is all yours. You even broke your initial record. You get the milk !
I thought that there might be enough space to add back in the C64 style, but I can't quite do it.
Here's one at 140 exactly, but with the wrong colors and one small bug:
good call LRP!
that's a tough one. I could iron out the bug and center the frame,
but that's a 144:
cls(13)clip(7,7,114,114)w=120y=1::t:: ?1 rectfill(0,y,w,w,1)for x=7,w,6 do d=flr(rnd(2))*5line(x,y+d,x+5,y+5-d,13)flip()end y=min(y+6,115)goto t |
note that I used color 13, because that's how I remember it:
Pico8 style tho
cls()y=2::s::for x=0,124,3 do cursor(x,y)if rnd(2)<1 then ?"/" else ?"\\" end end y+=5 if(y>115)y=112memcpy(24576,24896,8192) goto s |
That's 132 characters.
Just messing around. Here is one that does not create diagonal slopes but regular square walls, no sprites, and in one line of code to boot !
cls()for i=0,31 do for j=0,31 do x=j*4y=i*4if rnd()<.5then line(x,y,x+3,y)else line(x,y,x,y+3)end end end |
105-characters.
Horrendous stack abuse in 226 chars:
function f(a,b,x,y)if 7==pget(x,y)then line(a,b,x,y)a=rnd(4)for i=0,3 do b=d[1+flr(i+a)%4]f(x,y,x+b[1],y+b[2]) end end end cls(7)rect(-1,-1,127,127,0)d={{2,0},{0,2},{-2,0},{0,-2}}f(1,1,1,1)pset(1,1,8)pset(125,125,9)::_::goto _ |
... ???
WHOA ! That's really quite BEAUTIFUL, Felice !
Quite a bit smaller than my original:
https://www.lexaloffle.com/bbs/?tid=27790
Putting a delay in your code:
function f(a,b,x,y)if 7==pget(x,y)then line(a,b,x,y)flip()a=rnd(4)for i=0,3 do b=d[1+flr(i+a)%4]f(x,y,x+b[1],y+b[2]) end end end cls(7)rect(-1,-1,127,127,0)d={{2,0},{0,2},{-2,0},{0,-2}}f(1,1,1,1)pset(1,1,8)pset(125,125,9)::_::goto _ |
I can see quite easily that your maze is superior. Mine chooses a random point when it runs out of areas to draw. Yours intelligently REWINDS back to the next available direction and continues from there, ensuring a really REALLY hard maze to navigate once complete.
Superb !
Heh, I wouldn't say it intelligently rewinds. Abusing the stack so horribly feels just wrong to me (worst case is close to 4000 levels deep), but there's enough to do it, it seems.
I'd prefer a nice iterative solution that uses pixel colors to indicate where you came from when you're unwinding, but I took a mental glance at that and decided it would probably cost more than 280 chars, so I wussed out and used recursion. :)
Recursion is the one thing in programming I am definitely not good at.
Which is is a shame as a great many functions and routines could be written quite a bit more intelligently than the way I write them.
As for the stack, is there a limit to the size you can recursively call a routine ?
I can't remember for sure how lua handles stack frames, ie. whether there's a dedicated stack with a limited depth, or if they're just objects from the GC heap that link to each other.
You'd definitely do well to spend some time on lua.org, where they have pretty extensive (albeit sometimes not so well written) docs on the language. Also check out the manual or the wiki I linked for pico-8 specific Lua extensions (e.g. var+=val) and useful API calls, tweaks, etc.
The more you know... .:✨🌟
[Please log in to post a comment]