Play endless versions of AI-generated Pong on the go



There is currently a file Much interest in AI tools designed to help programmers write programs. github copilot and amazon CodeWhisperer Application of deep learning techniques It was originally developed to generate natural language text By adapting it to generate the source code. The idea is that programmers can use these tools as a kind of autocomplete on steroids, using prompts to produce pieces of code that developers can incorporate into their programs.

Looking at these tools, I wondered: can we take the next step and take the human programmer
out of the loop? Can a working program be written and published on demand with the touch of a button?

In my day job, I write embedded software for microcontrollers, so I immediately thought of a handheld device as a demo platform. The screen and some controls will allow the user to order and interact with simple AI-generated programs. Thus the idea of ​​infinity was born
pong.

I chose
pong For a number of reasons. The gameplay is simple, Famous explanation of the original 1972 Atari pong The arcade cabinet is in the triumph of brevity: “Avoid losing the ball to get a high score.” All you need to play is an up button and a down button. As with many classic Atari games created in the 70’s and 80’s, pong It can be written in relatively few lines of code, and has been done as a programming exercise many times. This means that the source code repositories ingested as training data for AI tools are rich in it pong examples, which increases the likelihood of obtaining applicable results.

I used 6 USD
Raspberry Pi Pico W As the core of my mobile device – built-in wireless allows direct connection to cloud-based AI tools. For this I installed $9 1.14 Pico LCD display unit. 240 x 135 color pixels are enough for pongand the unit integrates two buttons and a two-axis precision joystick.

My choice of programming language for Pico was
micropython, because it’s what I usually use and because it’s interpreted language code that can run without the need for a computer-based compiler. The AI ​​coding tool I used was this OpenAI Codecs. OpenAI Codex can be accessed via An API that responds to queries using the HTTP web formatwhich is easy to create and send with a Requests And Ogson Available libraries for MicroPython. Use of the OpenAI Codex API is free during the current trial period, but registration is required and queries are limited to 20 per minute – still more than enough to accommodate even the most fanatical pong jockey.

LCD screen with joystick on the left side and two buttons on the right side, microcontroller, USB cable.
Only 2 units of hardware are required – Raspberry Pi Pico W [bottom left] It provides computing power and a breadboard 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 a new version of pong It is ordered by pressing a button and when it sends a prompt to OpenAI Codex, receives the results and starts the game. The container software also sets up a hardware abstraction layer, which handles the physical communication between the Pico and the LCD controller/controller.

The most important component of the whole project was creating a prompt that gets sent to OpenAI Codex every time we want it to output a new version of
pong. A prompt is a piece of plain text with the simplest structure of the source code – a few lines defining a structure common to many video games, i.e. a list of libraries we want to use, a call to handle events (such as keystrokes), and a call to update the state of the game based on those events, and a call to display the updated status on the screen.

The returned code produces an actionable file pong The game is about 80 percent of the time.

How to use these libraries and populate calls is up to the AI. The key to converting this general structure into a
pong The game is the comments are built in – optional in source code written by humans, and really useful for prompts. 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 correction attributes.” [sic]. Pong: This chapter represents the game itself. It has two paddles and a ball. It knows how to check if the game is over.” (My container and immediate code are Available at Hackaday.io) (go to the Hackaday.io To play an infinite number of Bonng games with Raspberry Pi Pico W; My container and spot code on the site.)

What comes from the AI ​​is about 300 lines of code. On my early attempts the code failed to render the game due to the version of MicroPython
framibuvir The library that works with my module is different from the windowing libraries that OpenAI Codex is trained on. The solution was to add the descriptions of the methods my library uses as quick comments, eg: “def rectangle (self, x, y, w, h, c)”. Another problem was that many of the training examples use global variables, whereas the initial variables you provided were defined as attributes that were defined to live within individual classes, which is generally a better practice. I eventually had to give up, go with the flow, and declare my variables as global.

Nine example clips
Pong variations generated by the OpenAI Codex vary widely in ball and paddle size, color, and how the results are displayed. Sometimes the code would result in an unplayable game, such as in the bottom right corner, where the player’s paddles were placed on top of each other.James Provost

The code that comes from my existing routers produces a working file
pong The game is about 80 percent of the time. Sometimes the game doesn’t work at all, and sometimes it produces something that works but not quite pong, such as when he allows the paddles to be moved left and right as well as up and down. Sometimes there are two human players, other times you play against the machine. Since it is not specified in the prompt, Codex takes either option. When you play against the machine it is always interesting to see how Codex has implemented this part of the code logic.

So who is the author of this code? Certainly there
legal disputes arising fromie how that code should be licensed, since much of the training suite is based on open source software that imposes specific license terms on the code it is derived from. But licenses and ownership are separate from authorship, and as far as the latter is concerned, I believe it belongs to the programmer who uses the AI ​​tool and checks the results, as if you create artwork with a company-produced drawing program and use brushes and filters.

For my project, the next step is to look at more complex games. Hit pass 1986
Arkanoid Upon request, anyone?



Source link

Related Posts

Precaliga