+Atarius Maximus Posted August 26, 2017 Share Posted August 26, 2017 It's one of the most well known single lines of code on the Commodore 64. It produces a simple, endless maze on the screen. It's also the title of a great book from MIT Press, in which the authors use that simple line of code as an example of an important but neglected type of programming practice, and a gateway into a deeper understanding of how computing works in society and what the writing, reading, and execution of computer code mean. That's deep. Tonight, I just thought it'd be fun to try and get the same output from that line of code with 7800basic, and maybe a few other languages, just as a pointless yet fun thing to do. The challenge of of the exercise was to try and do it with one line of code. I don't think it's possible to do it in 7800basic with just one line of code, but in my first try I did it with 12 lines of code. I'm guessing Mike could condense it. Up for the challenge? The code below does the trick with 7800basic. I could remove the last three lines (which simply slows down the output) and it would work fine with just 9 lines of code, but I was looking to emulate the slower line by line output of the C64. The graphic file simply contains the "/" and "\". It's included in the zip file attachment. set zoneheight 8 set doublewide on incgraphic tileset_10print.png 160A 0 1 2 3 1 characterset tileset_10print displaymode 160A P0C1=$88:P0C2=$88:e=1:f=1:g=0 main BACKGRND=$82:d=rand&1:if d=0 then plotchars 'a' 0 e f else plotchars 'b' 0 e f e=e+8:if e>104 then f=f+1:e=1:if f>24 then drawwait:clearscreen:f=1 Wait g=g+1:drawscreen:if g>2 then g=0:goto main goto Wait I was able to make it work with one line in a few other programming languages: Powershell: for(){Write-Host(Random("\","/"))-N} Perl: perl -pe '$_="~"ge$_?"/":"\\"' </dev/urandom Python 3: import random while 1:print(random.choice('/\\'),end='') C++: int main(){for(;;)cout<<(rand()%2?"/":"\\");} Yeah, I wasted an hour of my life, but it was interesting. Now it's time to actually read the book. 10print_7800basic.zip 5 Quote Link to comment Share on other sites More sharing options...
BydoEmpire Posted August 26, 2017 Share Posted August 26, 2017 Pretty slick, I'll have to try that later. I remember "one line programming contests" back in the c64 days, you could cram a lot into one line! Thanks for sharing! Quote Link to comment Share on other sites More sharing options...
+Atarius Maximus Posted August 26, 2017 Author Share Posted August 26, 2017 Pretty slick, I'll have to try that later. I remember "one line programming contests" back in the c64 days, you could cram a lot into one line! Thanks for sharing! Of course after I finished that simple 7800 maze generator I started thinking about how it could possibly be made into a game. I wasn't a part of any of those one line programming contests back in the day. That would have been cool! 1 Quote Link to comment Share on other sites More sharing options...
toiletunes Posted August 26, 2017 Share Posted August 26, 2017 Entombed 7800? Pretty sweet! Quote Link to comment Share on other sites More sharing options...
Jinks Posted August 27, 2017 Share Posted August 27, 2017 Of course after I finished that simple 7800 maze generator I started thinking about how it could possibly be made into a game. I wasn't a part of any of those one line programming contests back in the day. That would have been cool! The 8bit atari computer guys have one liner competitions every year. Quote Link to comment Share on other sites More sharing options...
+Atarius Maximus Posted August 27, 2017 Author Share Posted August 27, 2017 The 8bit atari computer guys have one liner competitions every year. That's cool. I never really browse on A8 forums because I never had one as a kid, there's just not much nostalgic draw to that platform for me. I had a C64 in the 80's, and was the only computer I used throughout the 80's and into the early 90's in college. Either way, I'll have to browse around in the A8 forum and take a look. Edit: I didn't find a one liner competition with a quick search, but I did find the "10 liner" competition. Looks like fun! Quote Link to comment Share on other sites More sharing options...
Jinks Posted August 27, 2017 Share Posted August 27, 2017 That's cool. I never really browse on A8 forums because I never had one as a kid, there's just not much nostalgic draw to that platform for me. I had a C64 in the 80's, and was the only computer I used throughout the 80's and into the early 90's in college. Either way, I'll have to browse around in the A8 forum and take a look. Edit: I didn't find a one liner competition with a quick search, but I did find the "10 liner" competition. Looks like fun! Oh I remembered wrong. If we could get a fraction of those guys to do 7800 basic it would be unreal. Quote Link to comment Share on other sites More sharing options...
+Atarius Maximus Posted August 27, 2017 Author Share Posted August 27, 2017 Oh I remembered wrong. If we could get a fraction of those guys to do 7800 basic it would be unreal. Agreed! I made a multi-cart easylfash binary that includes all 34 of the C64 10liner games from 2016 and 2017. It can be attached as a cartridge image in Vice. I'd do the same thing for the other platforms if I knew how. Somebody beat me to making a game out of the one line of C64 code that I started this thread about. Check out the "Mazo" game. It's pretty simplistic, the object is simply to move a single dot through the maze from left to right and do your best to not touch the sides of the maze. Info from the author: You are trapped in a rose thorn hedge maze! To escape, find your way to the path on the right side. a = upleft s = upright z=downleft x=downright The less you are in contact with the thorns, the smaller your doctor bill when you do escape. This game pays homage to the inventor of the 1 line maze generator. It sure comes in handy when I can dedicate the rest of the 9 lines to game logic instead of background maze graphics. The player is a one pixel sprite to allow navigation of the tight maze. It uses sprite to background checks. 1 x=25:y=60:d=0:poke2047,255:poke53269,255:forz=16321to16382:pokez,0:next 2 fori=1024to2023:pokei,(77.5+rnd(1)):next:fori=1053to2020step40:pokei,160:next 3 poke16320,1:poke53281,13:k=peek(197):ifk=12thenx=x-1:y=y+1:goto7 4 ifk=23thenx=x+1:y=y+1:goto7 5 ifk=13theny=y-1:x=x+1:goto7 6 ifk=10theny=y-1:x=x-1:goto7 7 poke53294,0:poke53262,x:poke53263,y:if peek(53279)=0thenpoke53280,0:goto9 8 poke53280,2:d=d+1 9 if x<248thengoto3 10 print"doctor bill in dollars:":printd:print" - mazo by onlineprof2010" Since the code does not have special characters, it can be copied and pasted into vice but it has to copied into a text editor first and have the line ending spaces removed. If that does not work, load up the basic program below and then do a list. C64-10liners.zip Quote Link to comment Share on other sites More sharing options...
RevEng Posted August 27, 2017 Share Posted August 27, 2017 The challenge of of the exercise was to try and do it with one line of code. I don't think it's possible to do it in 7800basic with just one line of code, but in my first try I did it with 12 lines of code. I'm guessing Mike could condense it. Up for the challenge? Meh, I'm all about moar features. Here's my alternate version... rem ** truchet patterns in 8 lines - including this comment. Reset=color-change, Select=pattern-change set zoneheight 8 dim screendata=$2200:dim mode=a:dim color=b:dim pass=c:dim intcolor=d:dim intbackcolor=e:dim modemask=f:displaymode 320A:characterset tileset_10print:plotmap screendata 0 0 0 20 23 0 0 40 : plotmap screendata 0 80 0 20 23 20 0 40: BACKGRND=$84:P0C2=$88:modemask=1:incgraphic tileset_10print.png 320A 0 1 main for y=0 to 22:for x=0 to 39:r=rand&modemask:r=r+mode:pokechar screendata x y 40 24 r:if pass>0 then drawscreen:if (framecounter&1)=0 then intcolor=intcolor+1:if (framecounter&3)=0 then intbackcolor=intbackcolor+1 if switchselect then mode=mode+2:x=0:y=0:pass=0:if mode>6 then modemask=3:if mode>9 then mode=mode+2:if mode>19 then mode=0:modemask=1 if switchreset then color=color+$10:x=0:y=0:pass=0:BACKGRND=$04 + color:P0C2=$08 + color wait if switchselect || switchreset then goto wait else next:next:pass=1:goto main topscreenroutine if color=$f0 then for inttemp1=0 to 185:inttemp2=intcolor+inttemp1:WSYNC=0:BACKGRND=intbackcolor:P0C2=inttemp2:next:BACKGRND=0:return else return BTW, this sort of non-rotated mirrored-image tiling is properly called Truchet tiling. Check out that wiki entry, and you'll see your slashes there. There was a type-in program in one of the A8 magazines that stuck that fact in my brain, oh so long ago. Just to be clear, the code is very difficult to read because stuffing it into a few lines was part of the challenge. Nobody should use this as an example of anything, except maybe an example of how not to code. [edit - added in some 4 tile Truchet patterns, compacted 2 lines of code] 10print.bas.a78 10print.bas.bin 10print3_7800basic.zip 2 Quote Link to comment Share on other sites More sharing options...
+Atarius Maximus Posted August 28, 2017 Author Share Posted August 28, 2017 Meh, I'm all about moar features. Here's my alternate version... rem ** truchet patterns in 8 lines - including this comment. Reset=color-change, Select=pattern-change set zoneheight 8 dim screendata=$2200:dim mode=a:dim color=b:dim pass=c:dim intcolor=d:dim intbackcolor=e:dim modemask=f:displaymode 320A:characterset tileset_10print:plotmap screendata 0 0 0 20 23 0 0 40 : plotmap screendata 0 80 0 20 23 20 0 40: BACKGRND=$84:P0C2=$88:modemask=1:incgraphic tileset_10print.png 320A 0 1 main for y=0 to 22:for x=0 to 39:r=rand&modemask:r=r+mode:pokechar screendata x y 40 24 r:if pass>0 then drawscreen:if (framecounter&1)=0 then intcolor=intcolor+1:if (framecounter&3)=0 then intbackcolor=intbackcolor+1 if switchselect then mode=mode+2:x=0:y=0:pass=0:if mode>6 then modemask=3:if mode>9 then mode=mode+2:if mode>19 then mode=0:modemask=1 if switchreset then color=color+$10:x=0:y=0:pass=0:BACKGRND=$04 + color:P0C2=$08 + color wait if switchselect || switchreset then goto wait else next:next:pass=1:goto main topscreenroutine if color=$f0 then for inttemp1=0 to 185:inttemp2=intcolor+inttemp1:WSYNC=0:BACKGRND=intbackcolor:P0C2=inttemp2:next:BACKGRND=0:return else return BTW, this sort of non-rotated mirrored-image tiling is properly called Truchet tiling. Check out that wiki entry, and you'll see your slashes there. There was a type-in program in one of the A8 magazines that stuck that fact in my brain, oh so long ago. Just to be clear, the code is very difficult to read because stuffing it into a few lines was part of the challenge. Nobody should use this as an example of anything, except maybe an example of how not to code. [edit - added in some 4 tile Truchet patterns, compacted 2 lines of code] Amen to not using it as an example of how to code! Looking through the files submitted for the competition, people would generally submit the long and short versions of the code, so you could actually review the longer version to more easily see what they did. I did the same thing with mine in the original post but didn't share the "long" version. After a little more google searching it looks like there IS a one liner competition as well, but that's really taking things to an extreme. It's certainly possible to make a one line "game" in basic, but it's unlikely to be anything you'd want to play twice. Thanks for posting it, I was in fact pretty curious to see how you'd do it differently. Quote Link to comment Share on other sites More sharing options...
RevEng Posted August 28, 2017 Share Posted August 28, 2017 My pleasure. Thanks for the fun diversion! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.