Star Trek-type strategy games, where you’re in command of the Enterprise, battle Klingons, and defend starbases on a map with limited resources, have been a staple of computers since the early 1970s, when all that was around were mainframes at universities and large businesses. There have been countless interpretations and variations ever since on every conceivable platform. It’s fun stuff, and as part of my own collection, I have quite a few boxed variations of such games, and certainly played with various BASIC language interpretations over the years.
In any case, what’s fascinating is that ChatGPT, an AI-like language model that produces text, is able to produce usable code for all types of programming languages, including classic BASIC, which was a staple of personal computers from the mid-1970s to mid-1990s. What’s most impressive is that not only can it generate one iteration of a program, but also keep iterating. For instance, here’s my first request, “Can you write a Star Trek game in BASIC?”:
10 REM Star Trek Game
20 REM by OpenAI Assistant
30 REM
40 REM Initialize variables
50 LET ship_energy = 1000
60 LET Klingons = 10
70 LET starbases = 5
80 REM
90 PRINT "Welcome to the Star Trek game!"
110 PRINT "You are in command of the USS Enterprise."
120 PRINT "Your mission is to destroy all Klingons in the galaxy."
130 PRINT "You have 1000 units of energy and 5 starbases to help you."
140 PRINT "Good luck, captain!"
150 PRINT
160 REM Main game loop
170 DO
180 PRINT "Enterprise status:"
190 PRINT "Energy: ";ship_energy
200 PRINT "Klingons remaining: ";Klingons
210 PRINT "Starbases remaining: ";starbases
220 PRINT
230 PRINT "What do you want to do?"
240 PRINT "1. Attack Klingons"
250 PRINT "2. Repair at a starbase"
260 INPUT "Enter your choice: ", choice
270 SELECT choice
280 CASE 1
290 PRINT "Enterprise attacks Klingons!"
300 LET ship_energy = ship_energy - 100
310 LET Klingons = Klingons - 1
320 PRINT "Energy remaining: ";ship_energy
330 PRINT "Klingons remaining: ";Klingons
340 CASE 2
350 PRINT "Enterprise docks at a starbase for repair."
360 LET ship_energy = 1000
370 LET starbases = starbases - 1
380 PRINT "Energy restored to 1000 units."
390 PRINT "Starbases remaining: ";starbases
400 END SELECT
410 LOOP UNTIL Klingons = 0
420 PRINT "Congratulations, captain! You have destroyed all Klingons in the galaxy."
430 END
ChatGPT describes the result:
This game uses a simple loop to allow the player to make choices and update the game state. The player can either attack Klingons or repair at a starbase, and the game will update the energy and remaining Klingons and starbases accordingly. The game ends when the player destroys all Klingons.
ChatGPT
Good stuff, but rather simpler than a typical Star Trek-like game. My follow-up prompt, which ChatGPT ran with, was, “Can you make the game more complex?”:
10 REM Star Trek Game
20 REM by OpenAI Assistant
30 REM
40 REM Initialize variables
50 LET ship_energy = 1000
60 LET Klingons = 10
70 LET starbases = 5
80 LET galaxy_map = 5
90 REM
100 PRINT "Welcome to the Star Trek game!"
110 PRINT "You are in command of the USS Enterprise."
120 PRINT "Your mission is to destroy all Klingons in the galaxy."
130 PRINT "You have 1000 units of energy and 5 starbases to help you."
140 PRINT "Good luck, captain!"
150 PRINT
160 REM Main game loop
170 DO
180 PRINT "Enterprise status:"
190 PRINT "Energy: ";ship_energy
200 PRINT "Klingons remaining: ";Klingons
210 PRINT "Starbases remaining: ";starbases
220 PRINT "Galaxy map pieces: ";galaxy_map
230 PRINT
240 PRINT "What do you want to do?"
250 PRINT "1. Attack Klingons"
260 PRINT "2. Repair at a starbase"
270 PRINT "3. Search for galaxy map pieces"
280 INPUT "Enter your choice: ", choice
290 SELECT choice
300 CASE 1
310 PRINT "Enterprise attacks Klingons!"
320 LET attack_success = INT(RND(1)*2)
330 IF attack_success = 1 THEN
340 LET ship_energy = ship_energy - 100
350 LET Klingons = Klingons - 1
360 PRINT "Attack successful! Klingons remaining: ";Klingons
370 ELSE
380 PRINT "Attack failed!"
390 END IF
400 CASE 2
410 PRINT "Enterprise docks at a starbase for repair."
420 IF starbases = 0 THEN
430 PRINT "No starbases remaining. Cannot repair."
440 ELSE
450 LET ship_energy = 1000
460 LET starbases = starbases - 1
470 PRINT "Energy restored to 1000 units."
480 PRINT "Starbases remaining: ";starbases
490 END IF
500 CASE 3
510 PRINT "Enterprise searches for galaxy map pieces."
520 LET search_success = INT(RND(1)*2)
530 IF search_success = 1 THEN
540 LET galaxy_map = galaxy_map + 1
550 PRINT "Map piece found! Map pieces remaining: ";galaxy_map
560 ELSE
570 PRINT "Search unsuccessful."
580 END IF
590 END SELECT
600 LOOP UNTIL Klingons = 0 OR galaxy_map = 0
610 PRINT "Congratulations, captain! You have completed your mission."
620 END
ChatGPT again described the result:
This version of the game includes several new features:
- The player can choose to search for galaxy map pieces in addition to attacking Klingons or repairing at a starbase.
- The player has a chance of success when attacking Klingons or searching for map pieces, determined by a random number generator.
- The player can only repair at a starbase if there are any remaining.
- The game ends either when the player destroys all Klingons or runs out of galaxy map pieces.
I hope this more complex version of the game is to your liking! Let me know if you have any questions or if you’d like to see any further modifications.
– ChatGPT
Impressive stuff indeed. I haven’t tested it yet and suspect that at least a few modifications would be needed to run on nearly any version of BASIC, but as a time-saver, educational tool, or merely as inspiration, this is good stuff.
For clarification, I asked ChatGPT what version of BASIC this is based on:
The version of BASIC used in the examples I provided is a general-purpose dialect of BASIC that is commonly used on a variety of platforms. It includes common BASIC commands and features such as PRINT, INPUT, IF-THEN statements, and looping constructs.
BASIC (Beginners’ All-purpose Symbolic Instruction Code) is a high-level programming language that was developed in the mid-1960s and has since been widely used for a variety of purposes, including education, game development, and general-purpose programming. There have been many different versions and dialects of BASIC over the years, each with its own set of features and capabilities.
The examples I provided should be compatible with most versions of BASIC, although there may be some minor variations depending on the specific dialect being used. If you are using a specific version of BASIC and encounter any issues with the code, please let me know and I’ll be happy to help you troubleshoot the problem.
– ChatGPT
Leave a Comment