Category: Other stuff

An interesting project- Converting BASIC Computer Games

An interesting project- Converting BASIC Computer Games

Basic Computer games bookYes it’s that book again, one I have mentioned a few times.  Now there’s a project to convert all of the games from the book into C#, Java, JavaScript, Python, Ruby and VB.NET. As with all Git sites, you can download all code from the site in a zip file or individual files. So far though its very early in the project and there’s only a .BAS file in each of the subfolders for each of the games in the book. If you fancy getting involved, pick a game, a language and start coding. Sadly there’s no desire for C or C++ but that still leaves C# .

I still have this book and its sequel (More BASIC Computer games!) but to be honest I wouldn’t have bothered with most of the games in either book. They are all very much of the era (1978) which was just on the cusp of the home computer revolution and so were mostly obsolete within seven or eight years, due mainly to the terminal I/O. They’re ok for learning programming and of course you could run them in a Linux terminal.

Learning a programming language is not so easy

Learning a programming language is not so easy

Never stop learning
Image by Gerd Altmann from Pixabay

When I started, back in the dark ages there weren’t many programming languages about. It was a choice of BASIC, Fortran, C, Pascal and Cobol or some obscure languages apl, lisp, snobol etc. At Uni I learnt BASIC in first year then Pascal. We touched on Cobol in one course, enough to put me off it for life. We also did one semester on assembly language for a 6800 CPU. That was fun and probably helped me to learn 6502 and Z80 a few years later.,

Back then once I started learning other languages, it was long before the web existed. Programming languages came with manuals – user guides, reference guides. So you could learn enough to get started and then dip into the reference guide as and when you needed.

But since the Web appeared, the manuals no longer exist as printed books. But what I’ve noticed is, it gets harder to acquire a new technology if you are not working in it fulltime. I learnt PHP and HTML twenty years ago and reinforced that learning by creating websites. But now technologies like Blazor and ASP.NET MVC are quite a bit more complicated.  I’m doing  Udemy course on Blazor with over 200 lessons (most about 5 minutes long) and have only got up to lesson 55. Finding the time is probably one of the hardest things.

C is probably one of the easiest programming languages to learn but any other language or complicated technology is going to take a lot longer. I think It should be easier. There is an immense amount of free material on the web including sites to pose questions (StackOverflow), low cost courses (Udemy), free videos (Youtube) and yet it doesn’t seem easier.  Back pre-web you had to pay for programming languages. But unless you are a student or have a lot of spare time to study, it can be slow learning new stuff.

 

Interesting number sequence

Interesting number sequence

Chess Set
Image by Clker-Free-Vector-Images from Pixabay

Here’s an interesting puzzle (well for some people). If I have the integers 4,5,6,7 and 8 and a special C function f so that f(4)=2, f(5) = 5, f(6)=10, f(7)=40 and f(8) = 92. What is the function f? And no it’s not a simple array containing the numbers 2,5,10,40,92 at positions 4-8!

I also checked the OEIS (Online Encyclopaedia of Integer sequences) and it’s not in there either. Years ago I was fooled by a integer sequence that was the maximum number of electrons in orbital shells but its definitely not that.

Here’s a minor clue. It is game related. Answer in a day or two.

PagedOut a technical programming magazine

PagedOut a technical programming magazine

PagedOut Issue 1 frontcoverIt’s not often that I recommend somebody else but when I see something that I think deserves it, I’m happy to. PagedOut is a free experimental (one article == one page) technical magazine about programming (especially programming tricks!), hacking, security hacking, retro computers, modern computers, electronics, demoscene, and other similar topics. That’s their description! It’s published by Gynvael Coldwind, an IT Security engineer at Google.

It isn’t game related and not totally C oriented. In fact there are currently only two issues out, downloadable as PDFs and the second one has half a dozen C articles but the first issue has none.  There’s a bit of C++, Python, Go and some other stuff including assembly and the content varies enormously and is mostly Linux oriented but there is a bit Windows as well.

The big thing is that each article is just one page long. That’s by design. They accept submissions from anyone, subject to their standards and review but it must fit in one page.

I’ve always had a bit of a hacker mentality going back to when I crashed a mainframe (twice) at University. I didn’t mean to honest….  Being naturally inquisitive I think has helped me as a professional programmer.

 

An uncensored alternative to GitHub

An uncensored alternative to GitHub

Digital cash
Image by WorldSpectrum from Pixabay

I use GitHub a lot, I’ll be the first to admit it but there have been recent cases where GitHub has censored projects because of the US DMCA law ((I’m in the UK so different laws apply here but GitHub is in the US and being owned by Microsoft is not going to ignore the law) so radicle offers a er radical alternative.

It uses Peer to Peer thus avoiding needing servers which can be seized.  People share a bit of their bandwidth and storage and act as anonymous servers; I suspect you don’t see or have any access to stuff stored on your computer. It uses digital cash so those with lot of bandwidth and storage can do more hosting and receive payment from those who are using it.  I’ve seen Ethereum mentioned for 2021 but I think it uses Electron having looked at the community pages.

Slightly ironically, the project is currently hosted on GitHub!  

Am I going to switch to it? Not yet but in the future, who knows?

Could Flash make a comeback?

Could Flash make a comeback?

Ruffle Flash EmulatorBack in the day (2011) I did a bit of Flash game development. It was a curious technology compared to what I was used to. It was originally a way of scripting graphics and other media but really took off when ActionScript, a programming language very much based on JavaScript was introduced.

Unfortunately the twin combination of insecurities in the Flash player’s on PC and refusal by Apple to allow it on iPhones killed it. It took a few years to die and HTML5/JavaScript became a slightly inferior replacement. There were 100s if not thousands of Flash games on websites like Kongregate.com. There are still many games there and on other similar aggregator sites.

But a lot of developers really enjoyed creating Flash games and there have been a few open source emulators. None in C, but at least one in C/C++ and more recently Ruffle (in Rust).  The image is a screenshot from one of the demo games.

What’s different now apart from still not running on mobile is that the “Flash” players are more secure and in this case use WebAssembly for browsers. WebAssembly is seen as the future of browser games and whether it’s by compilin g C/C++ or Rust programs directly into WebAssembly or by using Flash games and animations transformed via programs like Ruffle into WebAssembly, I suspect that the browser will become an increasingly important platform for WebAssembly games.

Talking of which as well as Emscriptem for turning C/C++ with SDL) into WebAssembly there is also Cheerp, an open source and commercial C/C++ compiler that produces WebAssemb;y. I really have no excuse for not producing a WebAssembly version of Asteroids!

Adding an SSL Cert

Adding an SSL Cert

SSL connectionThese days, if you have a website or even a game server then you probably should have an SSL (or TLS to be more precise) certificate. Have you heard of telnet? It’s an old protocol that allows you to connect to a remote computer and issue commands. Do you know why you don’t hear of it any more? Because it was designed for an era where hackers didn’t spend all their time attempting to compromise computers. Telnet, like FTP has a flaw. Passwords and login details are sent in the clear. Not hashed, or encrypted.

Why don’t I use SSH to connect to it? I do. SSH has more functionality than SSL and is very good for encrypting remote connections. SSL needs a certificate, whereas SSH doesn’t but many think you should use a SSH certificate as a substitute for username/password and I intend to. If you’re not sure of the technical differences between SSL and SSH, this article isn’t a bad place.

So today I paid for an SSL certificate. I’d pointed a domain I had handy to the vps a few days ago, to give DNS a chance to settle, (24 hours max but usually much less) paid £20 for five years of SSL cert and installed it today. Thankfully, virtualmin which I use for configuring the server makes it straightforward to request a SSL by generating the CSR (Certificate Request an Private Key) . This blog uses an SSL cert from the same place (CheapSSL). Despite the low price the certificates are very good.

Although the world won’t see what the cert is protecting, you almost have to have them nowadays. This is for the connection between smartphone and server. As I found today, Apple is ramping up security and Google is doing the same. I have iOS 14 on my iPhone (upgraded yesterday) and it refused to connect to WiFi in my local coffeeshop. Their certificate doesn’t expire for another month but I suspect it is now over 398 days old. As far as Apple is concerned, that certificate is past its use by date. This is Apple’s new policy since earlier this year. My wife’s iPhone, still on iOS 13 connected quite happily.

For those who have bought a multi-year certificate as I have today, it just means you have to generate another CSR and install a newer certificate once every 400 days or so. I’ve started taking screenshots of the details so I get them correct! I believe Google is moving to this 398 day maximum as well.

So the commands from smartphone to game server are now sent over https and encrypted in flight as are the results. It’s one less thing to worry about.

 

 

My code is buried in the Arctic!

My code is buried in the Arctic!

Svalbard taken from a cruise ship in 2015It’s true. Well my code and that of thousands of others on Svalbard, a set of islands halfway between Norway and the North pole. I’ve actually been to Svalbard on a cruise a few years back. It was cold and a bit damp. That’s one of a bunch of photos I took.

GitHub shipped 21 terabytes to be stored in long term storage under the ice. It should be good for a few hunded years at least so thats my backups taken care of. I wish!

Normal blogging will be resumed tomorrow. Hey after 200 posts I’m allowed a semi-off topic post once in a while!

Changing your default Font

Changing your default Font

This is one of those subjective things. Do you use the default font in text editors or do you switch to a programmer’s font when the option is possible?

For example in Visual Studio, you can select any font you want. The Monotype fonts (i.e. fixed width) are shown bold.

JetBrains, the people behind the Resharper tool for C#, Intellij Idea (the editor used in Android studio) and the Kotlin programming language have given away a new programmers font.

After downloading the font zip file, open it and unzip the multiple versions of the font. There’s 14 variations (extralight, italic etc) and also web versions that you can use in a website. I just took the regular and installed it in Windows. If you Preview the font then you get the option to install it.

In Visual Studio you have to go to Project Options then Font and Colors and select the font. After that you have to close Visual Studio and reopen it.

One interesting thing is that this font supports ligatures.  These are special characters that replace things like !=. Here’s what that looks like after installing this font.

Visual Studio Font with ligatures

Of course if you don’t like JetBrains Mono or want to try others programmer’s fonts, here’s an article with eleven listed.

It’s not just Visual Studio that this works with, you can change the font in Visual Studio Code and others.

A simple Rock, Paper, Scissors game

A simple Rock, Paper, Scissors game

Rock, Paper, Scissors
Image by OpenClipart-Vectors from Pixabay

One of the easiest games to program is Rock, Paper, Scissors. All you are doing is a simple comparison, but programming it so the computer player can win more games than the player is not quite so easy.

The easiest strategy is always guess paper as Rock is apparently the most often chosen. That might work for the first couple of games but after that… A better strategy is count what the player plays each time to try and detect a bias. Guess randomly but make the %age of guesses favour the move that defeats the players most common move. If the player pays paper 50% of the time, guess scissors 50% of the time.

Then there’s variations on this, try and analyse past moves to give an edge. That could get quite complicated. You have to program it for pattern recognition. If the player favours scissors after losing with rock etc.

Here is a simple implementation of RPS in C.