[HN Gopher] "BASIC Computer Games" code in modern languages
       ___________________________________________________________________
        
       "BASIC Computer Games" code in modern languages
        
       Author : martincmartin
       Score  : 162 points
       Date   : 2023-07-31 16:26 UTC (6 hours ago)
        
 (HTM) web link (github.com)
 (TXT) w3m dump (github.com)
        
       | codeguppy wrote:
       | I love the old Usborne BASIC books... and the old type-in BASIC
       | program books. I have in my collection a few of those. I love the
       | work of Jeff on converting those old games to JavaScript.
       | 
       | As I mentioned, I'm also impressed by the old Usborne books,
       | therefore I also tried recently to create an illustrated
       | JavaScript course in that style ... See here the first 30%:
       | 
       | https://codeguppy.com/site/download/coding_course.pdf
        
       | russnewcomer wrote:
       | The library in the city near where I grew up had some variant of
       | this book in it. Unfortunately, the variant of BASIC was
       | something that didn't compile on the 286 my parents had purchased
       | and either I didn't ask or they couldn't help me at age ~5/6 to
       | get around the compiler errors, and I thought I wasn't smart
       | enough to be a programmer for about 8 years.
       | 
       | Then I got into the mid-wave mod scene in 1998, and I realized I
       | had the wrong compiler, but man, I just thought I couldn't follow
       | directions right.
        
       | baudaux wrote:
       | You can play Basic games using exaequos.com: bwbasic
       | /usr/games/basic/animal.bas for example
        
       | dang wrote:
       | Related. (I thought I saw another one recently but couldn't find
       | it...)
       | 
       |  _Play Basic Computer Games in the Browser_ -
       | https://news.ycombinator.com/item?id=34377776 - Jan 2023 (1
       | comment)
       | 
       |  _Basic Computer Games (1978)_ -
       | https://news.ycombinator.com/item?id=28572761 - Sept 2021 (12
       | comments)
       | 
       |  _Updating "101 Basic Computer Games" for 2021_ -
       | https://news.ycombinator.com/item?id=26273866 - Feb 2021 (65
       | comments)
       | 
       |  _Basic Computer Games (ported to C#, Java, JavaScript, Python,
       | Ruby, VB.NET)_ - https://news.ycombinator.com/item?id=26188324 -
       | Feb 2021 (3 comments)
       | 
       |  _BASIC Computer Games_ -
       | https://news.ycombinator.com/item?id=19604142 - April 2019 (120
       | comments)
       | 
       |  _BASIC Computer Games (1978)_ -
       | https://news.ycombinator.com/item?id=9026063 - Feb 2015 (31
       | comments)
       | 
       |  _Atari Archives: BASIC Computer Games_ -
       | https://news.ycombinator.com/item?id=3200133 - Nov 2011 (23
       | comments)
       | 
       |  _BASIC Computer Games Book, published in 1978_ -
       | https://news.ycombinator.com/item?id=1866103 - Nov 2010 (36
       | comments)
        
       | daneel_w wrote:
       | Somewhat related trivia: Sid Meier's Pirates! for the Commodore
       | 64 is written mostly in BASIC, coupled with assembly for parts
       | requiring snappier performance (for example the full-screen
       | scrolling while sailing).
        
         | riidom wrote:
         | That was a pretty common mix, I know mostly from the CPC, but
         | it was the same in (another) green, basically.
         | 
         | Been a kid at that time, I run into performance issues with the
         | BASIC-only approach pretty quick. Sadly I had no good books
         | about assembly or knew someone knowledgeable about it.
        
           | UncleSlacky wrote:
           | You could at least access and control interrupts directly
           | from Locomotive BASIC on the CPC.
        
         | the_af wrote:
         | I still cannot wrap my head around this. I was schooled about
         | this fact by one of the C64 experts who frequent HN, and I'm
         | still amazed.
         | 
         | C64 BASIC was terrible even for its time. Due to licensing
         | issues, its capabilities lagged behind those of other BASICs
         | from home computers of the same era. Everything cool you could
         | do with it was basically cheating: PEEK and POKE. As a child,
         | this frustrated me to no end. Even my friend with his Speccy
         | had access to a better BASIC.
         | 
         | And still... Pirates! was made with Commodore BASIC.
        
           | daneel_w wrote:
           | C-64 BASIC V2 has all of the same important fundamentals that
           | other BASICs of that era had. What mainly set it aside was
           | the lack of dedicated graphical functions. What was available
           | on the other home computers was on one hand too slow (or too
           | limited) to be useful for pretty much any type of game
           | development - forcing those platforms, too, to "cheat" by
           | interacting with the hardware by POKEing around - but on the
           | other hand fun and educational to explore graphics
           | programming with. The exception would be the very capable
           | BASIC of the Sharp MZ-700 which was of an entirely different
           | class. For the C-64 there were plenty of third-party options.
        
             | the_af wrote:
             | Well, the C64 itself was a capable machine, so it's no
             | surprise extensions to BASIC had cool capabilities. The
             | issue is that the provided BASIC sucked, no if or buts
             | about it. I remember missing a simple LOCATE statement for
             | placing text (text! not even graphics) that the Speccy's
             | BASIC had, if I remember correctly.
             | 
             | To me, missing dedicated graphical functions (or cool text
             | functions like LOCATE) was a big miss precisely because the
             | C64 was a multimedia computer. As a kid I wanted to do cool
             | stuff with my C64 and had to resort to obscure (to me) POKE
             | commands. "POKE" is not really BASIC, it's a cheat.
             | 
             | I remember when I finally got my PC-XT clone, loaded with
             | GW-BASIC. It had a DRAW statement! I could draw pixels with
             | easy to understand commands, no POKE! My mind was blown. I
             | could even forget I was using a monochrome CRT... I
             | wouldn't get my colors back until a few years later.
        
               | daneel_w wrote:
               | My opinion from having written so much in all kinds of
               | BASICs back then is that it is convenience more than
               | unlocking doors. Learning, for example, the two memory
               | addresses to POKE to on the C-64 to move the cursor to a
               | fixed position is a tool one learned no different than
               | learning the more convenient alternatives of "PRINTAT"
               | and "LOCATE". But I do agree that drawing lines etc.
               | directly in BASIC provided a lot of fun. BASIC, by its
               | nature, was the real limitation.
               | 
               |  _> "POKE" is not really BASIC, it's a cheat._
               | 
               | I don't understand why you don't consider it BASIC, or
               | why it's cheating. Practically every BASIC out there from
               | that era allows for direct interaction with the
               | computer's memory. It's fundamental functionality of the
               | lowest level possible, and the diametrical opposite of
               | cheating.
        
               | UncleSlacky wrote:
               | Spectrum BASIC had PRINT AT (which is probably what
               | you're thinking of). The C64 would probably have to use
               | control characters to achieve the same thing in BASIC if
               | it's anything like PET BASIC (inverted playing card suit
               | characters etc.).
        
               | daneel_w wrote:
               | Yep, stringing together control characters, or setting
               | the cursor position in the screen editor's memory with
               | two POKEs.
        
         | ksherlock wrote:
         | The Apple IIgs BASIC files end with this nugget to save
         | themselves during development:
         | 
         | 63999 F$ = "TOWN": PRINT "Saving "F$"...": PRINT "UNLOCK"F$:
         | PRINT "SAVE"F$: PRINT "LOCK"F$: PRINT "DELETE/PIRATES/"F$:
         | PRINT "SAVE/PIRATES/"F$: PRINT 27648 - ( PEEK (176) * 256 +
         | PEEK (175))" bytes free": END
         | 
         | (The print strings actually have an embedded control-D / 0x04
         | so they're executed as commands rather than printed)
        
       | markstos wrote:
       | I had a book like at that at age 10. I would spend what seemed
       | liked hours typing them in to play the games... and usually there
       | was a syntax error and they wouldn't work, and often I couldn't
       | fix them. But I was fascinated and kept trying. The games I got
       | to work were that much more rewarding!
        
       | firesteelrain wrote:
       | I contributed to a few of these last year because I wanted to
       | learn a new language. These programs are hard to translate if
       | they are sufficiently large. One way to cheat is to look at
       | someone else's translation to a familiar language like Python
       | then make your translation from there. The problem like that, as
       | someone mentioned elsewhere, is that if you are not careful then
       | you are copying over their bugs blindly (in addition to the
       | original program bugs). We were encouraged as part of the project
       | to try to stay true to the original design. I did add in some
       | error handling. I also found bugs in the python decomposition of
       | a few of them (I don't remember which one's and didn't have the
       | time to fix them).
        
       | davidrupp wrote:
       | I learned a lot about programming by taking a book like this that
       | was written specifically for the TRS-80 (which I did not own),
       | and translating the programs to what I owned instead, which was a
       | Sinclair ZX80. This primarily involved translating between
       | different flavors of BASIC, but also deciding what I could
       | arrange to leave out and still have an interesting game, due to
       | the relatively constrained resources of my machine. Excellent
       | experience.
        
         | martincmartin wrote:
         | I learned a lot about programming by taking this book and,
         | since I didn't own a computer, figuring out how the code could
         | produce the example listing. That's where I learned things
         | like, to swap the values of two variables, you copy one to a
         | third variable temporarily. I learned a ton of patterns like
         | that.
         | 
         | Eventually I got my VIC-20, then an Apple ][, then an Amiga.
        
       | jquast wrote:
       | I wrote a small script to load Hamurrabi.bas onto my Apple-1
       | replica over serial and to play against it interactively, as a
       | sort of screensaver.
       | 
       | Though I played this as a kid, I learned some interesting anti-
       | mechanics by writing an "automatic player", that I can still get
       | the highest rating by systemically starving 3% of the population
       | each year, and that there is no need to leave any food in store
       | for the successor after your final turn, and that losing half of
       | the population to plague is actually in your favor.
        
       | JohnFen wrote:
       | I love the idea of the programs in that book being used as the
       | basis for a kind of Rosetta Stone.
        
       | xen2xen1 wrote:
       | Went to look on eBay for a copy, had one in my youth. Immediately
       | crossed my mind to show it to my dad, who passed in 2020. Sad.
       | That many memories. Oh my.
        
         | DennisP wrote:
         | My dad passed in late 2019. Not long after, I had a vivid dream
         | in which I showed him a programming book I thought he'd like,
         | then we browsed the computer section of a bookstore for what
         | felt like a pleasant hour or so.
        
       | kgr wrote:
       | I wrote a BASIC to JS compiler/transpiler that includes all of
       | the programs from "BASIC Computer Games" as examples.
       | 
       | You can try it out in your browser at:
       | https://codepen.io/kgr/full/yLQyLjR
       | 
       | Just select the game you want to to run from the top-left list
       | box, then press the "Compile" button and you'll see the
       | translated JS source in the right text-area. Then press the "Run"
       | button to run it.
       | 
       | The source code for the compiler is available at:
       | https://github.com/kgrgreer/foam3/tree/429f2fd2b4cef0e37996a...
        
       | sbuttgereit wrote:
       | Ah yes. One of the things I'll do when I'm learning a new
       | computer language is pull out my now ancient copy of the 1973
       | edition of the book and just convert one of these games to the
       | new language. The conversion might not look very much like the
       | original when I'm done, but it is functionally equivalent. What I
       | like about the approach is that the games in the book are small
       | enough problems to solve as not really to be a major undertaking
       | while being complex enough to be interesting.... and, of course,
       | nostalgia.
       | 
       | Way back when copying these games from the book into a VIC-20 and
       | C-64, along with a healthy dose of the 80's era computer magazine
       | programs, were my introduction to programming. Having to convert
       | between BASIC versions was part of the learning experience.
        
       | behringer wrote:
       | I'd just like to point out, there are _modern_ BASIC compilers
       | out there so you can still enjoy these books on a modern PC with
       | modern tooling!
       | 
       | Decimal BASIC is one such BASIC compiler that should be perfectly
       | compatible with these types of books!
       | 
       | http://hp.vector.co.jp/authors/VA008683/english/
       | 
       | If you love BASIC of all variations, come join us on discord at
       | https://discord.gg/HQaDgJvbbJ
        
       | mmastrac wrote:
       | What I'd really like to see are the multiplayer games from the
       | original 101 BASIC Computer Games ported to the web. I was too
       | young to understand how those worked as a kid, and my dad's copy
       | had some printing issues (occasional pages have white streaks
       | across it).
       | 
       | EDIT: To clarify BASIC Computer Games != 101 BASIC Computer Games
       | (the original has more than the microcomputer version including
       | CANAM and DOGS)
       | 
       | This is a later printing than what I have --
       | http://www.bitsavers.org/pdf/dec/_Books/101_BASIC_Computer_G...
        
         | dspillett wrote:
         | There are copies of the book on eBay, so it is available if you
         | want a better copy to work from yourself. A quick search finds
         | copies on archive.org too, though you might have to check a few
         | to find a good one (the one I just opened wasn't a very clear
         | scan, the code was not particularly easy to read due to being a
         | low-res scan of already low-quality text).
         | 
         | --
         | 
         | EDIT: having looked at the repository, it _is_ reimplementing
         | the games from that book in various languages, including
         | javascript hosted in a web page, so for a direct translation it
         | is exactly what you are looking for. If you want the multi-
         | player ones to be playable between remote players, you still
         | have some work to do!
        
           | sbuttgereit wrote:
           | There's actually a PDF copy of the book linked in the readme
           | of the GitHub repo that the post is about.
           | 
           | https://annarchive.com/files/Basic_Computer_Games_Microcompu.
           | ..
           | 
           | also there's a link that has web based running versions of
           | the game:
           | 
           | https://troypress.com/wp-content/uploads/user/js-
           | basic/index...
        
         | eesmith wrote:
         | This is exactly that.                 % git clone
         | https://github.com/coding-horror/basic-computer-games.git
         | Cloning into 'basic-computer-games'...       remote:
         | Enumerating objects: 23002, done.       remote: Counting
         | objects: 100% (1191/1191), done.       remote: Compressing
         | objects: 100% (542/542), done.       remote: Total 23002 (delta
         | 645), reused 1083 (delta 633), pack-reused 21811
         | Receiving objects: 100% (23002/23002), 76.04 MiB | 5.75 MiB/s,
         | done.       Resolving deltas: 100% (11501/11501), done.       %
         | cd basic-computer-games
         | 
         | then open "index.html" in your browser. This lets you browse
         | the games and play them.
         | 
         | Or, for a web server experience, in that directory:
         | % python -m http.server
         | 
         | then go to http://localhost:8000/ .
        
           | mmastrac wrote:
           | BASIC Computer Games != 101 BASIC Computer Games, the latter
           | of which had some programs that were designed to work on
           | time-sharing/mainframes.
           | 
           | https://en.wikipedia.org/wiki/BASIC_Computer_Games
        
             | eesmith wrote:
             | Thank you for the correction!
        
               | mmastrac wrote:
               | Thanks for the heads up on the web-capable versions of
               | the other games. That's pretty cool indeed.
               | 
               | I hope someone takes on the few missing multiplayer games
               | from the DEC version at some point but figuring out how
               | to port them is going to be a lot of work!
        
       | swayvil wrote:
       | I'll bet the new code is bigger than the old code.
        
         | jnellis wrote:
         | For the most part it is! I contributed to this project last
         | year or so. The goal was to make the ports as one file runnable
         | equivalents and not get all enterprisey but you can see (mainly
         | C#) that some people can't shake the habit. There was also a
         | lot of "we need a framework for running the programs", "we need
         | a framework for testing", and "we need a linting and style
         | compliance" efforts.
         | 
         | If you don't know BASIC then you'll have a hard time following
         | the spaghetti code that the original book has. Probably half of
         | the BASIC programs from the original book are either actually
         | broken, have bugs or don't work as intended. Of the people that
         | contributed, they either included the bugs and bad logic,
         | ported from someone else's port in another language (that
         | included new bugs and kept the old ones) or wrote a different
         | game entirely.
         | 
         | To create a truly verbatim port in as many lines as the
         | original while fixing the original bugs (and making it
         | readable) is quite time consuming.
        
           | firesteelrain wrote:
           | Your Lua implementations are pretty decent. I was just
           | learning Lua last year while reviewing your implementations.
        
             | jnellis wrote:
             | Me too! Those were my first and only Lua programs actually.
        
           | kwertyoowiyop wrote:
           | Interesting point that replicating all the logic of spaghetti
           | code can take a lot more lines than the original. Still, some
           | of the op-ified code I just read seems unnecessary.
        
           | jboy55 wrote:
           | Looking at the C# poker, it amuses me that you end up closer
           | to Enterprise FizzBuzz(1) than the basic game.
           | 
           | (1) https://github.com/EnterpriseQualityCoding/FizzBuzzEnterp
           | ris...
        
       | progmetaldev wrote:
       | I remember "graduating" from Atari 8-bit BASIC to QBasic on an
       | i386, and being blown away at how much more you could do,
       | including switching graphics modes. I know a lot of people like
       | to say that BASIC teaches you bad coding habits, but I think it
       | also got young minds hooked into programming. If you had a deep
       | interest, you unlearned those bad habits, but still kept that
       | love of writing software. I still wish I could go back in time
       | and feel what it was like to first gain a grasp of seeing your
       | code perform some task, right in front of you.
        
         | martincmartin wrote:
         | "It is practically impossible to teach good programming to
         | students that have had a prior exposure to BASIC: as potential
         | programmers they are mentally mutilated beyond hope of
         | regeneration." -- Edsger W. Dijkstra
         | 
         | As someone who got their start with BASIC -- mainly from "BASIC
         | Computer Games" no less -- I was always kind of offended at
         | that quote.
        
           | ianbicking wrote:
           | It's a very Sapir-Whorf sentiment, that somehow we are
           | infected by what we learn, unable to imagine outside of those
           | formative experiences. And like Sapir-Whorf, also false!
        
             | contingencies wrote:
             | Sapir-Whorf in the conventionally conceived sense of
             | language-as-local-limitation is clearly false, partly as it
             | invalidates itself as an origin story. (How would you
             | invent a language if you can't think outside of it?)
             | 
             | Sapir-Whorf in the sense of language-as-influence however
             | is clearly true, even if academics occasionally state
             | otherwise, because at their core all languages used by
             | communities of a size greater than one individual rely upon
             | semantics that are socially dictated.
             | 
             | Personally, _perl_ screwed me up a lot more than BASIC -
             | but who can argue with the expressive power of regex for
             | text extraction and matching problems?
             | 
             | Wikipedia has a fun excerpt featuring PG (and Ruby) on just
             | this question https://en.wikipedia.org/wiki/Linguistic_rela
             | tivity#Programm...
        
             | bitwize wrote:
             | I have noticed, however, that the more experience one has
             | with C, the more flummoxed they are by Rust. It's why I
             | tell C old hands who grouse about Rust: Rust isn't for you,
             | it's for your replacement.
        
           | glimshe wrote:
           | Dijkstra's maxim is both harmful and clueless. Many of the
           | greatest programmers in the world started with BASIC. When I
           | "graduated" from BASIC to Pascal, I very quickly dropped the
           | BASIC approach to program flow, as any software engineer
           | worth their salt would do. Dijkstra infantilizes programmers,
           | as if it wasn't obvious that BASIC's approach is cumbersome
           | and people just keep programming C++ as if it was BASIC...
           | 
           | Once you go to a "proper" programming language, there is
           | nothing to "unlearn". The new approach is so obviously
           | better! At the same time, having an interpreter up within 2
           | seconds of turning the computer one was AMAZING and got a lot
           | of people interested in programming.
           | 
           | Much of the software world you see today was built by people
           | who started with BASIC!
        
           | humanistbot wrote:
           | As someone whose first language was BASIC, which led me down
           | a path that eventually culminated in a CS Ph.D, I have also
           | not been a fan of that quote.
           | 
           | It implies that Dijkstra was a terrible educator who could
           | only truly teach blank minds. For all his imagination and
           | creativity on theoretical CS and math, he was very rigid in
           | other ways. Imagine a history professor saying that students
           | who have been exposed to various myths and ideologies are
           | mentally mutilated beyond hope, or a literature professor
           | saying that students who have been exposed to pop culture
           | retellings of the classics are mentally mutilated beyond
           | hope.
           | 
           | Remember that Dijkstra looked down on anyone who wrote using
           | word processors, because he thought any academic should be
           | able to work out their argument in their head and just write
           | it down. Eventually he came to even reject the mechanical
           | typewriter.
        
       | tkb wrote:
       | Jeff Atwood had a piece in his "Coding Horror" blog about this
       | project: https://blog.codinghorror.com/updating-the-single-most-
       | influ...
       | 
       | (Personally I grew up on the British early 1980s Usborne BASIC
       | programming books, now wonderfully available at
       | https://usborne.com/gb/books/computer-and-coding-books . My copy
       | of "Computer Battlegames" - which I'd arbitrarily picked in the
       | bookshop over "Computer Spacegames" - was the closest to the
       | classic "BASIC Computer Games", which I never came across - not
       | sure if it was more a US thing.)
        
         | bitwize wrote:
         | Ahl's collection is more diverse: it has battle games, board
         | games, sports simulations, economic simulations, even
         | rudimentary demoeffects ("Sine Wave").
         | 
         | One of the variants of the Football (American football) game is
         | particularly intriguing; you will notice that the opposing
         | teams are Dartmouth and Rutgers. This game is traceable back to
         | Dartmouth College, where and when BASIC was first developed by
         | Kemeny and Kurtz. It was, as I recall, originally written by
         | members of the Dartmouth football team as a way to have a bit
         | of fun. The idea that someone who wasn't a scientist, engineer,
         | or professional programmer could program a computer to some
         | non-tech, non-business application was a huge mind blow at the
         | time, and a major contributor to BASIC's enduring popularity.
        
       | [deleted]
        
       | jj999 wrote:
       | If I translate a copyrighted work into another language is the
       | translated work under copyright?
        
         | dragonwriter wrote:
         | Yes. If it is sufficiently original to be a distinct work (most
         | human translations will be), it is a derivative work with its
         | own copyright; if it is, e.g., a purely mechanical translation,
         | it is covered by the copyright on the original.
         | 
         | In either case, without permission or a copyright exception
         | (e.g., fair use) it is also a violation of the original
         | copyright, either as a derivative work or a copy.
        
           | dcminter wrote:
           | In this case, however, the original author is not enforcing
           | their copyright: https://blog.adafruit.com/2022/06/16/david-
           | ahl-places-all-hi...
        
         | ptspts wrote:
         | I am not a lawyer. I think the translation is considered
         | derivative work under copyright.
        
         | voakbasda wrote:
         | IANAL, but my understanding is "yes, that would be considered a
         | derived work". Of course, it really only matters if you expect
         | to end up in court over it.
         | 
         | Translating ancient programs like this are unlikely to trigger
         | a legal case, but I would not rule it out entirely in this day
         | and age.
        
       ___________________________________________________________________
       (page generated 2023-07-31 23:00 UTC)