Play infinite AI-generated versions of Pong anywhere

Today is a day strong interest in AI tools designed to help programmers write software. on GitHub co-pilot and Amazon’s Code Whisperer applying deep learning techniques originally developed to generate natural language texts adapting to create the source code. The idea is that programmers can use these tools as a sort of auto-completion on steroids, using prompts to produce code snippets that developers can integrate into their own software.

Looking at these tools, I wondered: could we take the next step and hire a human programmer?
out of the loop? Can a work program be written and deployed on demand at the touch of a button?

In my day job, I write embedded software for microcontrollers, so I immediately thought of a standalone handheld as a demo platform. A screen and some controls would allow the user to command and interact with simple AI-generated software. And thus the idea of ​​infinity was born

i choose
Pong for various reasons. It’s easy to play, famously featured in Atari’s 1972 original Pong arcade cabinet in a triumph of brevity: “Avoid losing the ball to get a high score.” Up and down button is all it takes to play. As with many classic Atari games from the 1970s and 1980s, Pong it can be written in relatively few lines of code, and has been implemented as a programming exercise many, many times. This means that the source code repositories that are ingested as training data for AI tools are rich Pong examples, increasing the likelihood of achieving viable results.

I used US$6
Raspberry Pi Pico W as the core of my handheld device; Built-in wireless enables direct connection to cloud-based AI tools. I mounted this $9 Pico LCD 1.14 display module. That’s enough for its 240 x 135 color pixels Pongand the module integrates two buttons and a two-axis micro joystick.

I chose my programming language for Pico
MicroPython, because it’s what I usually use and it’s an interpreted language code that can be executed without the need for a computer-based compiler. The AI ​​coding tool I used was this OpenAI Codex. The OpenAI Codex can be accessed An API that answers queries using the web’s HTTP formatwhich are easy to build and ship requests and ujson Libraries available for MicroPython. The OpenAI Codex API is free to use during the current beta period, but registration is required and queries are limited to 20 per minute; however, it is enough to accommodate even the most fanatical. Pong jockey

An LCD screen with a joystick on the left side and two buttons on the right side, a microcontroller and a USB cable.
Only two hardware modules are required: a Rasperry Pi Pico W (bottom left), which supplies the computing power, and a plug-in board with a display and simple controls (top left). Nothing else is needed except a USB cable for power supply.James Provost

The next step was to create a container program. This program is responsible for detecting when a new version is available Pong is requested via a button, which then sends a prompt to the OpenAI Codex, receives the results, and launches the game. The container program also implements a hardware abstraction layer that manages the physical connection between the Pico and the LCD/control module.

The most critical element of the whole project was creating the prompt that is sent to the OpenAI Codex whenever we want to push a new version.
Pong. The prompt is a piece of plain text with no skeleton of source code: a few lines that describe a structure common to many video games, namely a list of libraries we want to use and a call to process events (such as key presses). ), a call to update the game state based on those events and a call to display the updated state on the screen.

The returned code creates an executable Pong game about 80 percent of the time.

How to use those libraries and complete the calls is up to the AI. The key to turning this generic structure into a
Pong the game is embedded comments; is optional in human-written source code, really useful in queries. The comments describe the gameplay in plain English; for example, “The game has the following classes… Ball: This class represents the ball. It has position, speed, and debugging attributes (sic). Pong: This class represents the game itself. It has two paddles and a ball. It knows how to check when the game is over.” (These are my container and invite code Available at (Go to play an infinite amount Pong games with Raspberry Pi Pico W; my container and invite code are on the site.)

What comes back from the AI ​​is about 300 lines of code. In my first attempts the code would fail to display the game because it’s the MicroPython version
framebuffer The library that works with my module is different from the framebuffer libraries that the OpenAI Codex was trained on. The solution was to add the descriptions of the methods used by my library as prompt comments, for example: “def rectangle(self, x, y, w, h, c).” Another problem was that many of the training examples used global variables, whereas my initial prompt defined variables as attributes with scope to live in individual classes, which is generally a better practice. I finally had to give up, go with the flow and declare my variables as global.

Nine example screenshots
The variants of Pong created by the OpenAI Codex vary greatly in the size and color of the balls and paddles and how the scores are displayed. Sometimes the code results in an unplayable game, for example in the lower right corner where the players’ paddles are stacked on top of each other.James Provost

The code that returns from my current prompt creates an executable
Pong game about 80 percent of the time. Sometimes the game doesn’t work at all, and sometimes it creates something that runs but isn’t quite there. Pong, for example, when the paddle allows you to move left and right in addition to up and down. Sometimes there are two human players, and sometimes you play against the machine. Since it is not specified in the questionnaire, the Codex assumes one of two options. When you play against the machine, it’s always interesting to see how Codex has implemented that part of the code logic.

So who is the author of this code? There are, without a doubt
resulting legal issues, for example, how that code should be licensed, since much of the training suite is based on open source software, which imposes specific licensing terms on the code derived from it. But licensing and ownership are separate from authorship, and as for the latter, I think it belongs to the programmer who uses the AI ​​tool and checks the results, just like if you created a piece of art with a painting program made by a company and they used their own brushes and filters.

As for my project, the next step is to explore more complex games. The 1986 arcade hit
Arkanoid request, anyone?

Source link

Leave a Comment