Making Games with AI is Fun, and Slightly Annoying

May. 24, 2023



Here at Beebom, we cover a lot of AI related news and resources. You must have seen our articles aroundChatGPT plugins,GPT-4, and more. Naturally, then, I spend a lot of time looking at what AI can do, and yes, trying to incorporate AI into my workflow to see if it can make a drastic difference in my productivity at work. Recently, however, I wanted to try using AI for something other than work. I wanted to see if I can use ChatGPT for game development with AI.

Finding a Game to Build

Finding a Game to Build

The first step in building a game, is to figure out what exactly to build. Obviously, you can’t go about writing the code for a game without knowing what it is you’re coding for.

Thankfully, that sort of thing is easy for a tool like ChatGPT. You can just ask it to suggest games that you can build, and it can suggest (most of the time) everything from basic, simple to build games, to more complex and complicated games.

So, I asked ChatGPT to suggest some simple games I can build using HTML, CSS, and JavaScript. From that list, I chose to build “Whack-a-Mole”. Sounds like an easy game to build, with a simple enough logic.

At this point, someone who knows how to code can very easily build this game. However, I wanted to get ChatGPT to build the entire game for me, so I had to come up with prompts for it.

It wasn’t very difficult either. You can simply ask ChatGPT to write the code for the game, and since ChatGPT is context aware, it knows what you’re talking about and can write the code for it, as you can see in the screenshot below.

However, I quickly got annoyed with this, because ChatGPT is actually not that good at writing code.

The first iteration of the Whack-a-Mole game was an absolute disaster. I opened the file in Chrome and the game simply didn’t work. There were the mole holes on my screen, but no mole peeped through for me to whack and earn points.

Deciding to give up on manual labor entirely, I asked ChatGPT to put the entire HTML, CSS, and JavaScript code in one single file. Happily, it obliged. But obviously, the code wouldn’t work yet because there wassomeissue,somewhere.

For starters, and this isn’t exactly a bug, ChatGPT put the entire code in one file, but left out space for the JavaScript code. Fortunately, you can simply ask it to give you the rest of the code, and it helpfully spits out the entire HTML file, complete with the code.What do you mean “rest of the JavaScript code goes here…” chatGPT? Give me the code!

Since this is basically the original (non working) code, it doesn’t run. And since I couldn’t (and didn’t want to) figure out where exactly the problem was, I tried just telling ChatGPT that the code doesn’t work.

ChatGPT gave me a new, updated code. And it told me, very confidently I might add, that it has fixed the issue that was causing the code to not run.

However, upon testing, the same issue persisted. This time, I decided to tell ChatGPT what problem I was facing with the code. It quickly came up with an updated version of the code, and this time around, it was able to figure out the problem, fortunately.

The new code worked properly, and I had a game of Whack-a-Mole that I could play on my browser. That’s fun, right?

I did notice one weird thing. The game seemed to stop running after a few seconds. The moles simply didn’t peep through. Going through the code, I quickly realised that the game was hardcoded to run for 10 seconds.

That’s fine, but I wanted to let the player choose the duration of the game themselves. Instead of figuring out how to do this, I simply asked ChatGPT to do it for me.

With the new code, the game now has an input field where the player can enter the number of seconds for which the game needs to run, and then start the game.

True, the game doesn’t look like anything to write home about, and the UI is… usable, at best. However, it goes to show that ChatGPT can, with a lot of work, build a game for you from scratch.

After playing a few rounds of Whack-a-Mole, I decided to try and get ChatGPT to build something else as well. This time around, I settled on Hangman. Similar hijinks ensued in my attempts to get ChatGPT to give me a working code for the game, however, this time around, I had to be way more specific in my prompt to get the corrected code.

ChatGPT can, most of the time, identify bugs in code. However, from what I have experienced so far, it’s only good at finding issues with syntax. It couldn’t, for example, figure out before multiple tries that the problem with the code it wrote, was a simple case of converting uppercase characters to lowercase.ChatGPT always thinks it’s got the correct code… even when it doesn’t

From the point of view of syntax, the code was perfectly alright. However, the characters the player is guessing are in uppercase, and since the code was checking them against the pre-defined word — which is in lowercase — it simply never matched them correctly.

The cool thing is that ChatGPT even put in the code for displaying an image representative of the hangman. All I had to do was create the various stages of the hangman’s journey. In fact, I can even ask ChatGPT to tell me how to go about creating the images.

Sure, the quality of these images is quite abhorrent, but that’s because I didn’t want to be bothered with creating proper images in Photoshop, and decided to take screenshots instead.

Still, it’s impressive in what it can do, and you can, at least, get a barebones version of what you’re looking for to build upon and improve. If you were, however, wondering whether you will be creating full-on games for distribution, ChatGPT (and AI models in general) aren’t there; not yet.