Here’s how the first ever “Snake” game was created using AI.

Sahil Junaidi
𝐀𝐈 𝐦𝐨𝐧𝐤𝐬.𝐢𝐨
4 min readJul 14, 2023

GPT-4, the highly awaited replacement to OpenAI’s ChatGPT already promises huge disruptions in the technology world. There has been a mixed reception ever since the launch of ChatGPT. An increasing number of jobs are now at risk of being automated.

A new study by the University of Pennsylvania, Open Research, and Open AI identified the potential of exposure of various jobs to large language models. Exposure here is a term used to determine whether the use of GPT or GPT-powered systems can cut down the time humans will need to do a job by half.

How the snake game was created using Artificial Intelligence (ChatGTP 4 in particular) and how you can do it too.

If, like Ammaar Reshi, you are curious about what GPT-4 can do or simply want to create your own classic game, below is a step-by-step guide outlined by Reshi on how he created his ‘Snake’ game. To start the trend, Reshi wrote;

“Can GPT-4 code an entire game for you? Yes, yes it can. Here’s how I created a snake game that runs in your browser using Chat GPT-4 and @Replit, with ZERO knowledge of Javascript all in less than 20 minutes.”

Firstly, Reshi asked “GPT-4 to provide code for a Snake game, with the relevant HTML, CSS, and Javascript required to make it run”. Surprisingly, the chatbot was able to provide Reshi with all he asked for. It took multiple responses for the bot to provide all of it. However, all Reshi had to do was say “continue” each time it stopped.

Once Reshi had all the required codes for the Snake game, he went over to @Replit and created an account. There, he began a new HTML, CSS, and JS project. Interestingly, all these can be done using a browser.

The next step was to copy the codes generated by GPT-4 and paste them into the relevant files within Replit and hit run. Reshi was able to play the game using the arrow keys.

However, Reshi discovered two issues with the game. “The snake would die after its first bite instead of growing, and it kept adding the score in increments of 2 instead of 1.” Reshi went back to GPT-4 and asked it to make the tweaks and it did.

Instead of just providing what Reshi asked for, GPT-4 followed it up with explanations. “I love that it followed up with explanations too — what a wonderful way to learn to code and actually understand why it’s doing the things it’s doing. GPT-4 is a decent teacher,” Reshi said.

Finally, Reshi was able to add a high score counter to the game to make it more competitive by asking GPT-4. Again, the chatbot was able to provide the required codes.

A day after the initial posting, Reshi was able to add sound to his game to make it more engaging. He said he intends to push further to see how much more he could do with GPT-4.

Conclusion

As Reshi pointed out, GPT-4 may likely not totally replace the need to learn how to code. Rather, it will supplement it. Having basic CSS knowledge is still paramount for programmers. GPT-4 will only make it easier for users to implement what they already know.

For example, Reshi knew that to create a snake game that would run on a browser he needed CSS, HTML, and JS codes. If he didn’t know the codes that he needed, he would still not be able to create a game using the chatbot.

Another lesson that can be gleaned from Reshi’s experience is that GPT-4 may not get what you want exactly the way you want it the first time. However, you can always go back and ask it to keep tweaking until you get the desired result.

Now that you know how to create games with GPT-4, which game will you attempt to create? Let us know in the comment box below.

--

--

Sahil Junaidi
𝐀𝐈 𝐦𝐨𝐧𝐤𝐬.𝐢𝐨

I write when I’m bored , Therefore the topics may be weird but you’ll catch on.