Log In  

Cart #28650 | 2016-09-17 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA
10

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

P#28651 2016-09-17 00:19 ( Edited 2018-08-05 00:14)

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°:

s=4
cls()
for j=0,128/s do
 for i=0,128/s do
  if (band(i,1)==band(j,1)) then
   if (rnd(2)>1) then
    line(i*s,j*s,i*s+s,j*s)
    line(i*s,j*s+s,i*s+s,j*s+s)
   else
    line(i*s,j*s,i*s,j*s+s)
    line(i*s+s,j*s,i*s+s,j*s+s)
   end
  end
 end
end

P#28659 2016-09-17 04:06 ( Edited 2016-09-18 00:26)

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 ?

P#28663 2016-09-17 12:33 ( Edited 2016-09-17 16:33)

Awesome! I'm currently reading this book. Really cool to see this here.

P#28707 2016-09-17 19:16 ( Edited 2016-09-17 23:16)

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.

P#28734 2016-09-18 08:57 ( Edited 2016-09-18 12:57)

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

P#28736 2016-09-18 11:07 ( Edited 2016-09-18 15:09)

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...

P#28737 2016-09-18 12:00 ( Edited 2016-09-18 16:00)
1

Here's an implementation that slips in at 136 chars.

Cart #28741 | 2016-09-18 | Code ▽ | Embed ▽ | No License
1

Here's the code with sensible whitespace:

l=126
::x::
for i=0,250,3 do
 flip()
 print(
  sub(sub("<>",rnd(2)+1),1,1),
  i%l,
  122+flr(i/l)*3,
  6
 )
 print(
  8,
  i%l,
  125+flr(i/l)*3,
  0
 )
end
print(0)
goto x

Basically, it uses the top part of the angle brackets (<>) as its diagonal and covers up the bottom part with a different character.

P#28744 2016-09-18 15:16 ( Edited 2016-09-18 19:25)

hey, very clever LRP! I've started my own take but the char count is still overboard... going back at it!

P#28763 2016-09-18 18:34 ( Edited 2016-09-18 22:34)

Now 114 characters!

Cart #28766 | 2016-09-18 | Code ▽ | Embed ▽ | No License

Code:

l=126
::x::
for i=0,250,3 do
 y=122+flr(i/l)*3
 flip()
 clip(i%l,y,3,3)
?sub("<>",rnd(2)+1),i%l,y
end
clip()
?""
goto x

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.

P#28765 2016-09-18 18:58 ( Edited 2016-09-18 23:20)

135 chars with plenty of room left

Cart #28767 | 2016-09-18 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA

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 ? :)

P#28769 2016-09-18 19:32 ( Edited 2016-09-18 23:32)

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

P#28770 2016-09-18 20:04 ( Edited 2016-09-19 00:04)

Oh awesome! I was hoping some folks could improve on my first garbage attempt :D

P#28782 2016-09-18 23:14 ( Edited 2016-09-19 03:14)

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.

P#28783 2016-09-19 00:01 ( Edited 2016-09-19 04:01)

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 !

P#28790 2016-09-19 06:22 ( Edited 2016-09-19 10:22)

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
P#28805 2016-09-19 13:50 ( Edited 2016-09-19 17:50)

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 :)

P#28807 2016-09-19 14:22 ( Edited 2016-09-19 18:22)

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.

P#28810 2016-09-19 15:23 ( Edited 2016-09-19 19:26)

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
P#28817 2016-09-19 16:38 ( Edited 2016-09-19 20:38)

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.

P#28825 2016-09-19 20:01 ( Edited 2016-09-20 00:20)

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

P#28841 2016-09-19 23:20 ( Edited 2016-09-20 03:23)

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 !

https://youtu.be/7rOka5iWv0o?t=75

P#28842 2016-09-19 23:29 ( Edited 2016-09-20 03:32)

I thought that there might be enough space to add back in the C64 style, but I can't quite do it.


143

cls(12)y=-6w=114::t::clip(6,6,w,w)rectfill(0,y,128,128,1)for x=6,w,6 do
d=flr(rnd(2))*5line(x,y+d,x+5,y+5-d,12)flip()end
?""
y=min(y+6,w)goto t

Here's one at 140 exactly, but with the wrong colors and one small bug:

cls(3)y=0w=114::t::clip(6,6,w,w)rectfill(0,y,128,128,0)for x=6,w,6 do
d=flr(rnd(2))*5line(x,y+d,x+5,y+5-d,3)flip()end
?""
y=min(y+6,w)goto t

P#28854 2016-09-20 02:51 ( Edited 2016-09-20 06:51)

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:


NTSC:

PAL:

P#28888 2016-09-20 15:37 ( Edited 2016-09-20 19:37)

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.

P#28889 2016-09-20 16:01 ( Edited 2016-09-20 20:47)

If I'm permitted to use sprites, this might be rather small.

Cart #28991 | 2016-09-22 | Code ▽ | Embed ▽ | No License

cls()x=0 y=0::a::c=rnd(2) if(x*y<1 or x>14 or y>14)c=2
spr(c,x*8,y*8)x+=1 if(x==16)x=0 y+=1
flip()goto a

105 CHARS

P#28992 2016-09-21 23:00 ( Edited 2016-09-22 03:01)

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.

P#54660 2018-08-03 19:43 ( Edited 2018-08-03 23:46)

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 _

Cart #54696 | 2018-08-04 | Code ▽ | Embed ▽ | No License

P#54697 2018-08-04 18:56 ( Edited 2018-08-04 22:56)

... ???

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 !

P#54698 2018-08-04 19:13 ( Edited 2018-08-04 23:18)

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. :)

P#54700 2018-08-04 19:26 ( Edited 2018-08-04 23:26)

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 ?

P#54703 2018-08-04 20:01 ( Edited 2018-08-05 00:01)

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... .:✨🌟

P#54707 2018-08-04 20:14 ( Edited 2018-08-05 00:14)

[Please log in to post a comment]

Follow Lexaloffle:          
Generated 2024-03-19 02:09:19 | 0.026s | Q:61