8

Updating "101 Basic Computer Games" for 2022 and beyond - Coding Horro...

 2 years ago
source link: https://discourse.codinghorror.com/t/updating-101-basic-computer-games-for-2022-and-beyond/7927/20
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

It looks great. What is the plan? Should we fork the repo for each language? Or add a folder for each language version?

I wrote an article to convert an Apple ][ Basic game to Python: Convertendo um jogo escrito em Basic para Python - Parte I :: Nilo Menezes — Ex-junglecoders 9 (in Portuguese, please use chrome to have it in English, just the code is important for the example). What I did was to add the original basic program at the top of the new version, let it commented out and write the translated version just after. The result is a mix of Basic and Python.

For Rust, I wrote a few text console helpers here: [GITHUB] /lskbr/spacegames
And for Python, I have another library for console here: [GITHUB] /lskbr/colorconsole
I know Miguel Icaza implemented a super text console library for C#, but I don’t have the link. I’m not sure if it is a good fit, as it is probably more like ncurses, changing a lot from the basic programming model, but I may be wrong :smiley:

I think we can also write a readme.md for each translation commenting on the challenges on each of them.

Just rolling into this thread after seeing mention on Twitter. I grew up with these books and still have my copies, albeit in rough shape. Wouldn’t might taking a crack at transliterating a few of them!

Probably going to attempt Super Star Trek if no one else gets to it first. I remember trying to convert that over to Star Trek: The Next Generation on a C64.

One semi-random thought: It would be very cool if this repo were somehow usable & hackable as a Glitch project for in-browser tinkering.

I’m looking at converting BOXING over to Python. Since the aim is to teach, I’m wondering if it makes sense to encourage the student to write the programs in a order that makes sense. We don’t want to start with some random sub routine, do we? For instance, a Python port would start with a “if name == ‘main’:” block calling “play()”. The play function would then iteratively be filled in along with any other supporting functions and data structures. This would be in contrast to a BASIC program which is almost obligated to be written linearly (I’m looking at you line numbers). I bring this up, because I feel like capturing the spirit of the original material implies we consider how the student is to learn from typing these programs. It’d be a bit more like a Bob Ross painting than a dot matrix print out.

AdamDawes575:

Have you considered a way of allowing people to “register” for implementing a project in a particular language? Just to avoid duplication of effort.

Yeah I hadn’t actually considered that – but I have mixed feelings about letting people “sign up” as they might sign up, and not progress at all, or sign up for too many things over enthusiastically, and block others from progressing…

So I’m leaning toward the status quo at the moment. Stubs aren’t really desirable. If you have something finished, check it in!

At the very least, I can assure you no work will be lost – we can have multiple implementations in each language.

Does the use of modern language features in the place of some more round about code (e.g. The BASIC version Hangman uses an INT array to mark whether a letter has been used yet, while Python can do the same by adding letters to a set) extend to algorithms affecting behavior? I ask this, because the AI code for TicTacToe2 depends quite heavily on the non-structured GOTO (I can almost hear Dijkstra now) and translation is quite challenging. I believe I have a workable strategy, but wanted to know if replicating behavior perfectly is a requirement or if we slip in a different algorithm that does the same job (an analogue to array iteration vs set key lookup). I say this as my translation is quite convoluted. Alternatively, a successful translation may serve as an illustration of how stark the programming styles can be.

Chuckles I think I’d have an easier time translating this particular one to NES.

pironomy:

I ask this, because the AI code for TicTacToe2 depends quite heavily on the non-structured GOTO (I can almost hear Dijkstra now) and translation is quite challenging. I believe I have a workable strategy, but wanted to know if replicating behavior perfectly is a requirement or if we slip in a different algorithm that does the same job (an analogue to array iteration vs set key lookup). I say this as my translation is quite convoluted. Alternatively, a successful translation may serve as an illustration of how stark the programming styles can be.

Wow! This is so cool – and it’s exactly why I started this project! I don’t have a strong opinion on the actual approach you choose, but definitely capture all this in code comments, because it’s fascinating.

Heh. Good to know. I’ll definitely check it out.

I guess it all comes down to where the line is drawn. Doing a direct translation from BASIC to any structured, functional, and/or OOP language.(I’ve only contributed Python so far, but would be glad to do C++ as a well) requires making choices about how to replicate behavior in a fashion that makes sense for the target language. Doing decent translations between human languages requires a similar skill. For example, a lot of expressions are culturally based and make zero sense when translated word for word. If we are looking to replicate the behavior of the computer player in tic tac toe, then we’d presumably need to faithfully recreate the algorithm though.

So far my attempt reminds me of higher level language code disassembles I’ve seen where functions are named for their line numbers.

This is such an awesome idea, and I’m really glad to have been able to contribute a couple of conversions. I got started programming as a child by copying games exactly like these out of magazines.

My last conversion (Blackjack, C#) was made considerably more difficult because of clever tricks. I understand why they would have been used in the original language, but I didn’t see any value in preserving them, especially when modern languages have much simpler and clearer ways of achieve the same goal.

For example:
Line 2220 2 S(I)=Z(I)*(3*(-(P(D1,2)>=10))-1)

This appears in the routine where the dealer offers blackjack insurance after dealing themselves an ace face up. If the dealer’s concealed card (P(D1,2)) is worth 10, this statement resolves to Z(I)*2, where if it’s not, it resolves to Z(i)*-1.

This works because BASIC represents true as -1 and false as 0, and they can be used interchangeably with integers. Not only would converting this as is to C# preserve a confusing relic with little value, it would also be difficult. The language deliberately prevents mixing boolean expressions with mathematical operations because it is normally not intentional.

I am definitely in favour of replacing these constructs with modern language capabilities and the latest techniques.

This does lead me to a question… The hardest part of my last conversion was understanding the original game. Now that I’ve spent this effort, I think it could be helpful for me to share my notes. What’s the best way for me to do that? It would be ideal to mark up the original BAS file with GitHub comments, but I don’t think we can do that outside of a PR. What about an MD file in each game directory?

For what it’s worth, I’ve gotten a decent way toward translating Super Star Trek into JavaScript via the most stupidly literal means possible. Could have started from scratch but I kind of wanted to soak my head in the old code a bit.

bad3e5f9ad67c1ddf145107ce7032ac1d7b22563.svggithub.com

lmorchard/basic-computer-games 21

84-js-super-star-trek/84%20Super%20Star%20Trek/javascript

An updated version of the classic "Basic Computer Games" book, with well-written examples in a variety of common programming languages

A neat thing is that just tonight I managed to get it running in a browser-based terminal, albeit with some bugs to fix:

https://lmorchard.github.io/basic-computer-games/84%20Super%20Star%20Trek/javascript/index.html 23

Kind of disservice to Basic don’t you think. Why not translate the code to actual Basic languages in use today. Such as:

Freebasic
Oyxgen
PureBasic
Thinbasic
PowerBasic

All of the above are in active use and fully supported. Powerbasic today is as good a any C compiler of today.

Just to add another thought. BASIC in the old days was a procedural language. While most today use Object oriented languages, procedural coding is still in use and not obsolete. They are two totally two different styles. Translations to other languages if you must, will be much easier if one uses a procedural style of coding.

77138_2.png Chris_Boss:

Why not translate the code to actual Basic languages in use today.

I would argue VB.NET covers this, and it is a classic Microsoft BASIC to boot.

I think to have a ruleset everyone can agree on, we’re going to narrow this to the top 20 TIOBE languages 15 that are memory safe and scripting appropriate, right now by my reading…

Languages in TIOBE top 20 as of February 2021:

  1. C :x:
  2. Java
  3. Python
  4. C++ :x:
  5. C#
  6. Visual Basic
  7. JavaScript
  8. PHP :-1:
  9. SQL :-1:
  10. Assembly :x:
  11. R :-1:
  12. Groovy :question:
  13. Go :x:
  14. Ruby
  15. Swift :-1:
  16. Matlab :-1:
  17. Delphi / Object Pascal
  18. Classic VB :-1:
  19. Perl
  20. Objective-C :x:

The ones with red X are not memory safe and therefore not applicable:

:x: C, C++, Assembly, Go, Objective-C

By scripting appropriate I mean languages meant for classic BASIC style I want to run a generalized, all purpose script at the command line style programming:

:-1: PHP, SQL, R, Swift, Matlab, Classic VB

That leaves us with 8 languages:

Java, Python, C#, VB.NET 1, JavaScript, Ruby, Delphi / Object Pascal, Perl

Groovy is a superset of Java, based on my research, so I’m consolidating that one into just Java. This also applies to other “clone” languages, we’re going with the language that is in the TIOBE top 20, even if the clone (or superset) language is compatible.

Hey Jeff,

When you say that PHP isn’t scripting appropriate, I don’t really see how it can’t run a generalized, all purpose script at the command line.
Mind you I don’t want to have PHP included, I’m just a bit thrown by your claim.
PHP CLI is as powerful as Python and has been used to do some async programming, even if I haven’t looked at the code to see how hacky it is :wink:
But again, disclaimer: I’m not pushing for it to be included!!! I REPEAT, not pushing for it to be included!

Cheers,
Gus


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK