“BASIC Computer Games” code in modern languages
github.com
github.com
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.
As someone who got their start with BASIC -- mainly from "BASIC Computer Games" no less -- I was always kind of offended at that quote.
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_relativity#Programm...
(Even though the BASIC I learned GW-BASIC, I think Djikstra was complaining about an even earlier BASIC with even less structured control flow.)
But I fell very much for Rust in about 2021, and now definitely wouldn't write any more C. Rust has coherent answers to a lot of questions that, to my mind, should be in any C programmer's head.
Now, maybe it helps my CS course's first language was SML/NJ and of course Rust is basically an ML in a trench coat pretending to be a semi-colon language like C. But that CS course was at least half a decade after I began writing C, which was in turn after many years of BASIC (and somewhere in there a little bit of Z80 assembler, but man assembler sucks when the CPU is as limited as the Z80 was, you young people who have a fucking floating point multiply instruction don't know what you've got etc...)
To me, the veteran C programmer, Rust's implementation makes lots of sense, while at the same time it's type system appeals to the more principled Computer Scientist I was taught to be, and its tooling to the Engineer I became as an employee.
Two examples: Wrapping<i32> is exactly how a 32-bit signed integer actually works in any vaguely modern computer. The machine can do this, and so unsurprisingly on a real computer this is nice and fast, despite also being completely safe. But, Wrapping<i32> is a nice elegant type, Wrapping is a polymorphic type, which grants to integers the property of wrapping (modulo) arithmetic for their normal operations, and so i32 is just a type parameter. Beautiful, and yet also fundamentally exactly how the machine works so it's fast.
Second, Option<&T> is exactly the same implementation as a C-style pointer. But it has the same ergonomics as rich Maybe types from a language like ML. So you use it in an inherently safe way, with the compiler catching many common mistakes you could make because they don't make coherent sense in the type system - but at runtime it's exactly the same performance as the nasty C code you'd have written where those mistakes wouldn't be caught.
Rust had include_bytes! from Rust 1.0, include_bytes! is philosophically the same thing, given a filename, it gives you an immutable reference which lives as long as your program, to an array of bytes from the file -- &'static [u8; N]
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.
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!
https://softwareengineering.stackexchange.com/questions/3097...
I miss that... :)
That influx of people with the attitude of "I don't care how computers work, I just want to know enough to solve my problem" shifts the stereotypes around those language users and may erroneously put the fault of it onto the language itself. It certainly feels that way during hiring, where it seems like developers of vastly differing skill or aptitude tend to cluster heavily around certain "friendly" languages.
As for Dijkstra -- arrogance in computer science is measured in nanodijkstras.
Are you saying None is better for beginners?
The fact that the first coding I did was mIRC scripting however should terrify everyone hahaha
well, as long as we aren't working on embedded code for pacemakers
in that case, we'll just skip to the first person in the stack of resumes who didn't start with basic
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)
Eventually I got my VIC-20, then an Apple ][, then an Amiga.
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.
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.
(Still, I'd love to go back in time and tell my young self that I could use control characters instead!)
PS: pretty sure there was at least one BASIC that had a LOCATE command, or am I confusing programming languages?
PPS: well, duh! It was GW-BASIC that had LOCATE. No wonder I remembered the command, GW-BASIC was my first true love and the first language with which I actually programmed games.
> "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.
And I'm speaking as 10-year old me, who didn't yet understand programming languages: Commodore BASIC felt incomplete.
Original BASIC was actually developed with a JIT compiler, only the 8 bit home versions were purely interpreted, and mainframe BASIC already supported structured programming and AOT compilation by the time 8 bit home computers were taking over, e.g. VAX BASIC.
I think many of us that started on 8 bit as kids, and eventually used something else on 16 bit computers aren't aware of this.
https://www.mobygames.com/game/41499/chopper-rescue/
https://www.youtube.com/watch?v=rUyebYD5UO0
C64 BASIC had to be a step back, but that's where the sales were to be made. For example, in Atari 800 BASIC variables were not limited to two characters.
C64 BASIC was really PET basic from ~1976, very close to Microsoft's Altair BASIC.
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)
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.
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...
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...
--
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!
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...
% 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/ .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!
Maybe you could cheat: there are a fair few emulators of that era of machines that you can SSH into, drop the code into one of those and run as originally intended! Or access via the web by hooking shellinabox up to connect to the emulator's console. You'd need to add some layer of authentication if making this available on the public internet for friends to access though. Might be easier to setup than actually porting that old “minified” code (with single-character variable names, GOTO-a-plenty, & minimal comments) and implementing something to manage multi-user access to the same game instance.
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.
(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.)
One of the variants of the Football (American football) game called "FTBALL" is particularly intriguing; you will notice that the playable team is Dartmouth. 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 purpose was a huge mind blow at the time, and a major contributor to BASIC's enduring popularity.
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
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%:
2950 PRINT "TORPEDO TRACK:"
2960 LET X=X+X[1]
2970 LET Y=Y+X[2]
2980 IF X<.5 OR X >= 8.5 OR Y<.5 OR Y >= 8.5 THEN 3420
2990 LET V[4]=X
2991 LET V[5]=Y
2992 GOSUB 9000
Becomes... _2950: Console.WriteLine("TORPEDO TRACK:");
_2960: X = X + _X[1];
_2970: Y = Y + _X[2];
_2980: if (X < .5 || X >= 8.5 || Y < .5 || Y >= 8.5) goto _3420;
_2990: _V[4] = X;
_2991: _V[5] = Y;
_2992: _9000();I think it could be pretty fun to dump a Raspberry Pi 8GB (with all software installed) and a keyboard in front of him and start programming small games. I'm sure there is a way to use game programming to teach from scratch. I just need to find an introduction book and adapt it with game programming examples.
But one issue is that kids today are getting used to things like Roblox so I'm not sure whether they would enjoy programming simpler games. I think a "graduating" project could be an Ultima-I spinoff, or some 2.5d engine such as Wolf3D's, but simpler.
Edit: The game titled "Word" is very similar to Wordle.
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.
(1) https://github.com/EnterpriseQualityCoding/FizzBuzzEnterpris...
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.
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.
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.
Testing a few files, and it choked. E.g when compiling http://www.vintage-basic.net/bcg/amazing.bas, I got these errors:
- Duplicated definition
- Array not dimensioned
Not versed with older BASICs which predated QB, so probably I'll try the modern implementations instead.
When Sean Astin used a variant of BASIC to crack a security door in the second season of Stranger Things, I even wrote a blog post about it. I was just so excited to see BASIC again "in the wild."