PHP generated code by ChatGPT for a political game

PHP Code Generation Using Artificial Intelligence (ChatGPT)

Let’s continue my story with game generation using AI. This time I tried PHP language.

I asked ChatGPT to “generate simple political game with 5 variables”.

ChatGPT generated two files:

  1. a static file with HTML form with name and affiliation used as index.html (without saying so),
  2. and one PHP file containing the game logic with 3 events to decide each turn and repeat.

The starting HTML form allowed player to choose their name and political affiliation – Democrat, Republic, Independent were included. So clearly it’s strongly US influenced here. This would submit to dynamic PHP file with the game logic.

The game logic would contain PHP code for rounds and static HTML form to proceed with a decision between three options. These options included making a controversial decision, holding a fundraising event and holding a town hall metting

The game logic had flaws and it wouldn’t work at first.

It didn’t work as:

  • instead of respecting player’s decision it would proceed with a randomly generated option number
  • it didn’t keep the state of variables properly (funds, approval, votes) as hidden fields in the form

After fixing these it somehow worked. But of course the game was dull as no scoring system or game overs were included.

Have a comment? Join discussion on Mastodon as a reply to: