![]() |
Forum Index : Microcontroller and PC projects : ChatGPT speaks MMBasic
Page 1 of 2 ![]() ![]() |
|||||
Author | Message | ||||
Martin H.![]() Guru ![]() Joined: 04/06/2022 Location: GermanyPosts: 1193 |
I tested the New release of Chatgpt. I Ask if it can program a Zork-Like Textadventure in MMBasic. 'by chatgpt DIM rooms$(20), descriptions$(20) DIM inventory$(20), inventoryCount AS INTEGER DIM playerRoom AS INTEGER DIM command$, verb$, obj$ DIM items$(10), itemLocations(10) AS INTEGER DIM lightSource AS INTEGER, score AS INTEGER, grueActive AS INTEGER ' Define rooms rooms$(0) = "Entrance Hall" descriptions$(0) = "You are in an old entrance hall. There is a door to the north." rooms$(1) = "Dark Corridor" descriptions$(1) = "A dark, damp corridor. It smells musty. There is a door to the south and stairs to the east." rooms$(2) = "Basement" descriptions$(2) = "A damp basement with an old chest. The stairs lead back west." rooms$(3) = "Cave Entrance" descriptions$(3) = "A rocky entrance to a deep cave. The air feels heavy." rooms$(4) = "Underground River" descriptions$(4) = "A fast-flowing river blocks the way. You might need a boat." rooms$(5) = "Treasure Chamber" descriptions$(5) = "A hidden chamber filled with ancient treasures." rooms$(6) = "Twisting Maze" descriptions$(6) = "A confusing maze of passages. You hear strange noises." rooms$(7) = "Deep Cavern" descriptions$(7) = "A cavern shrouded in darkness. Something is here..." ' Define items items$(0) = "KEY": itemLocations(0) = 2 ' Key is in the basement items$(1) = "CHEST": itemLocations(1) = 2 ' Chest is in the basement items$(2) = "LANTERN": itemLocations(2) = 0 ' Lantern is in the entrance hall items$(3) = "BOAT": itemLocations(3) = 4 ' Boat is at the underground river items$(4) = "GOLD": itemLocations(4) = 5 ' Gold is in the treasure chamber playerRoom = 0 inventoryCount = 0 lightSource = 0 grueActive = 1 score = 0 DO CLS PRINT "Location: "; rooms$(playerRoom) ' Check if the room is dark and Grue is active IF playerRoom = 7 THEN IF lightSource = 0 THEN PRINT "It is pitch black!" PRINT "A sinister presence is near..." PRINT "You have been eaten by a Grue!" EXIT DO END IF END IF PRINT descriptions$(playerRoom) ' Show items in the current room FOR i = 0 TO 4 IF itemLocations(i) = playerRoom THEN PRINT "You see: "; items$(i) NEXT i PRINT "What do you want to do?" INPUT command$ command$ = UCASE$(command$) ' Parse input verb$ = LEFT$(command$, INSTR(command$, " ") - 1) obj$ = MID$(command$, INSTR(command$, " ") + 1) SELECT CASE verb$ CASE "GO" SELECT CASE obj$ CASE "NORTH": IF playerRoom = 0 THEN playerRoom = 1 CASE "SOUTH": IF playerRoom = 1 THEN playerRoom = 0 CASE "EAST": IF playerRoom = 1 THEN playerRoom = 2 CASE "WEST": IF playerRoom = 2 THEN playerRoom = 1 CASE "DOWN": IF playerRoom = 2 THEN playerRoom = 3 CASE "CROSS": IF playerRoom = 4 AND lightSource = 1 THEN playerRoom = 5 CASE "MAZE": IF playerRoom = 3 THEN playerRoom = 6 CASE "CAVERN": IF playerRoom = 6 THEN playerRoom = 7 CASE ELSE: PRINT "You can't go that way." END SELECT CASE "TAKE" FOR i = 0 TO 4 IF items$(i) = obj$ AND itemLocations(i) = playerRoom THEN inventory$(inventoryCount) = obj$ inventoryCount = inventoryCount + 1 itemLocations(i) = -1 ' Remove item from room PRINT "You take the "; obj$; "." IF obj$ = "GOLD" THEN score = score + 10 IF obj$ = "LANTERN" THEN lightSource = 1 EXIT FOR END IF NEXT i CASE "OPEN" IF obj$ = "CHEST" AND playerRoom = 2 THEN PRINT "You open the chest and find an old letter." ELSE PRINT "You can't open that." END IF CASE "INVENTORY" PRINT "You are carrying:" IF inventoryCount = 0 THEN PRINT "Nothing." FOR i = 0 TO inventoryCount - 1 PRINT inventory$(i) NEXT i CASE "SCORE" PRINT "Your current score: "; score CASE "QUIT" EXIT DO CASE ELSE PRINT "Unknown command." END SELECT PAUSE 500 LOOP PRINT "Game over." The aim of the game is to find and collect all the treasures while navigating your way through the maze, solving puzzles and escaping dangers such as the Grue. Edited 2025-03-29 00:48 by Martin H. 'no comment |
||||
Geoffg![]() Guru ![]() Joined: 06/06/2011 Location: AustraliaPosts: 3269 |
If that is straight out of Chatgpt, I'm impressed. It even used comments. It seems that it has read the manual and understood the details, something that that is not that easy for us mere humans. Geoff Geoff Graham - http://geoffg.net |
||||
lizby Guru ![]() Joined: 17/05/2016 Location: United StatesPosts: 3310 |
This is impressive. Can you say exactly what you told ChatGPT to get this output? I'm interested in trying it in https://huggingface.co/Qwen/Qwen2.5-Coder-32B to see how that performs. How did you get it to understand MMBasic syntax, or did it just work? And how did you get it to know the details? PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed |
||||
Mixtel90![]() Guru ![]() Joined: 05/10/2019 Location: United KingdomPosts: 7504 |
Just as important, does it work? Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
Martin H.![]() Guru ![]() Joined: 04/06/2022 Location: GermanyPosts: 1193 |
Lance, that involved several steps and a slightly longer chat This is how i started the chat: In the beginning ChatGPT had programmed a very simple but working version of the adventure with 4 rooms and only the possibility to run in 4 directions. I then asked it to add more details to get closer to the original. I never played Zork myself, so it was always just a question and answer along the lines of “are there any items in the game, please include them in the program" etc. Edited 2025-03-30 04:00 by Martin H. 'no comment |
||||
lizby Guru ![]() Joined: 17/05/2016 Location: United StatesPosts: 3310 |
Depends on the meaning of "work". I've never played this game. I copied it to a Raspberry Pi and ran it in MMB4L. I could go east, take lantern, open chest, take letter, go west, go south--but there seemed no option to go to anywhere other than those three rooms. It didn't crash and it ran--but didn't seem to allow completion. I may well have missed something. PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed |
||||
Martin H.![]() Guru ![]() Joined: 04/06/2022 Location: GermanyPosts: 1193 |
No I don't think you've missed anything, it's just the framework of a program, there's no real ending and so on. 'no comment |
||||
stef123 Regular Member ![]() Joined: 25/09/2024 Location: United KingdomPosts: 83 |
Im trying to train an existing DS-Coder-Model on the PicoMite-Syntax, but its quite hard. As far as i can tell, they dont understand the manual at all, so even ChatGPT doesn't. This is also caused by the formatting of the User manual, where not every command has its own strict explanation, but where commands and their explanations are merged, so LLMs or Trainjng models cannot differentiate the commands out from their explanations. I had to do this manually by making a two-column table with command and explanation being separated. You have to consider that LLMs, especially for Coding, live from practical examples in Form of Code, not User manuals, because LLMs do only repeat what they have been teached - they cannot learn by themselfes - and they need tons of examples. LLMs do not have the slightest amount of Intelligence, altrough it might look so for the User. In fact they are well organized Databases. What ChatGPT has written down is a Program in a more modern, but still general Basic dialect (like QB64, Powerbasic etc), not strictly MMBasic. A training success would require that as much code as possible should be offered online, but i guess the amount of Code written im MMBASIC/PicoMite is generally too small, compared to Python or C++. Edited 2025-03-30 04:39 by stef123 |
||||
lizby Guru ![]() Joined: 17/05/2016 Location: United StatesPosts: 3310 |
Given this output, can you say something like "Only the first 3 rooms have exits. If a room is not a dead end, it must have at least two exits. Please try again making sure that all rooms can be reached."? PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed |
||||
lizby Guru ![]() Joined: 17/05/2016 Location: United StatesPosts: 3310 |
Can you post this table? PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed |
||||
stef123 Regular Member ![]() Joined: 25/09/2024 Location: United KingdomPosts: 83 |
s12.zip Here you go, but its not finished yet and covers only the "basic" commands. Its in Openoffice Format. Any help from anyone is very appreciated to make it complete. Means: If you see in the first column for example "command or command or command", just separate them (in this case) into three separate rows and copy the given explanation into the now empty explanation fields of the newly created rows- or better, adjust the explanation so that it fits to the command. But please keep commands and their explanations in a single row. Also please try to adjust like commands DEFINEFONT #Nbr hex [[ hex[…] hex [[ hex[…] END DEFINEFONT and their explanations. As good as it is for us, but its quite hard for an LLM to determine / understand hex [[ hex[…] hex [[ hex[…] and assign it to the explanation. In addition check out if all command parameters are also being explained, or adjust them. Also vital would be adding the functions explained later in the manual in the same manner, and the GUI Commands of the separate manual. I cannot guarantee the outcome when feeding an LLM with this data (anyone can try this too by installing for example https://github.com/h2oai/h2o-llmstudio and try to train a given model with this table), but it would give us all at least something usable. As being said, it wont generate code out of it and if, then only very bad one. It needs explanations in code form for each command, at best complete programs, -with clear comments behind each code line-. Unfortunaly, i have not the slightest idea about how to train a model on existing code. I guess this has to be done with things like TensorFlow and Co in Python. Edited 2025-03-30 06:43 by stef123 |
||||
lizby Guru ![]() Joined: 17/05/2016 Location: United StatesPosts: 3310 |
@stef123 -- Thank you for posting this table of commands from the PicoMite Manual. It's a monumental task. I would be more inclined to start (with Geoff's permission) with the significantly less complex MMBasic for DOS or even (with Tom's permission) with MMB4L. But it's your project, and I don't know exactly what you want to do with it. For me, it's a learning exercise. As a retired person, everything I do in this vein is play. PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed |
||||
lizby Guru ![]() Joined: 17/05/2016 Location: United StatesPosts: 3310 |
Here it is. Can't guarantee that it's in the format most suitable to your needs. Much more complicated than for MMBasic for DOS. It required a lot of fiddling with the text after going through a program which did most of the formatting successfully. I got to review many of the new functions which I have never looked at before. PicoMite functions table.zip PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed |
||||
lizby Guru ![]() Joined: 17/05/2016 Location: United StatesPosts: 3310 |
Ok, I had a long session today with ChatGPT and Zork. I've never use ChatGPT--I signed up for the yearly subscription. I started asking if it knew the BASIC language, and what flavors. It said it knew FreeBASIC (among others). I asked what FreeBasic commands it knew and what functions. It replied with this: PRINT, INPUT, IF...THEN...ELSE...END IF, WHILE...WEND, SUB, FUNCTION...END FUNCTION, DIM, TYPE (struct), (Arrays), PRINT USING. What built-in functions in FreeBasic are there? Mathematical Functions Abs(x): Returns the absolute value of x. Sqr(x): Returns the square root of x. Sin(x), Cos(x), Tan(x): Trigonometric functions. Log(x): Returns the natural logarithm of x. Exp(x): Returns e raised to the power of x. Rnd(): Returns a random number between 0 and 1. Int(x): Returns the integer part of x. String Functions Len(s): Returns the length of string s. Mid(s, start, length): Extracts a substring from s. LCase(s) and UCase(s): Converts a string to lowercase or uppercase. InStr(string1, string2): Returns the position of the first occurrence of string2 in string1. Trim(s): Removes leading and trailing whitespace from s. File Handling Functions Open: Opens a file for reading, writing, or appending. Close: Closes an open file. EOF(file number): Returns true if the end of the file is reached. Input#: Reads formatted data from a file. Print#: Writes formatted data to a file. Type-related Functions Typeof(var): Returns the data type of the variable var. CStr(var): Converts var to a string. CInt(var): Converts var to an integer. Miscellaneous Functions Sleep(milliseconds): Pauses the program for a specified number of milliseconds. GetTime: Returns the current system time. GetDate: Returns the current system date. I asked if it knew Zork and it said it did. I asked it to make a FreeBasic Zork game. I ran it in MMB4L. Through many iterations I asked it to replace FreeBasic syntax with MMBasic, and to fix certain errors, like DIM statements within a DO loop, the keyword "Shared", and "LIKE" for INSTR. When it finally got to where it would run without error, we got into the program logic. Not all 7 rooms were reachable. The room text didn't say where the exits were. The exits and entrances were not reciprocal--e.g., west from room 3 to room 4 was not mirrored with east from room 4 to room 3. It fixed that. When navigation was complete, it lacked Grue and it lacked a completion status. I asked it to add those. It used LIKE to find matches of items and I asked it to replace those with INSTR. I manually fixed 4 lines which were continuations of a single command--ending in "_". I navigated everywhere and picked up all the items, avoided Grue and was told I was successful. But it's now nearly 11pm, and I'm too weary to go on. Here's the program at this point. ' Simple Text Adventure Game in FreeBASIC Option Base 1 Dim currentRoom As Integer Dim inventory As String Dim rooms(7) As String Dim connections(7, 4) As Integer Dim action As String Dim item As String Dim direction As String Dim nextRoom As Integer Dim grueEncountered As Integer ' Room descriptions with exits rooms(1) = "You are in a dimly lit chamber. There is a door to the north leading to Room 2." rooms(2) = "You enter a bright room filled with treasure. There's a shimmering gold coin here. Exits: south to Room 1, east to Room 3." rooms(3) = "You find yourself in a dark cave. A faint light flickers to the east. Exits: west to Room 4, south to Room 2." rooms(4) = "You are in a library filled with dusty books. There's a magical scroll on a table. Exits: east to Room 5, west to Room 3." rooms(5) = "You step into a garden with beautiful flowers. A rusty key lies on the ground. Exits: west to Room 4, east to Room 6." rooms(6) = "You are in a grand hall with a large chandelier. An old lamp sits on a pedestal. Exits: west to Room 5, east to Room 7." rooms(7) = "You've reached the throne room. A mysterious potion rests on the throne. Exits: west to Room 6." ' Room connections connections(1, 1) = 2 ' North to Room 2 connections(1, 2) = 0 ' East connections(1, 3) = 0 ' South connections(1, 4) = 0 ' West connections(2, 1) = 0 ' North connections(2, 2) = 3 ' East to Room 3 connections(2, 3) = 1 ' South to Room 1 connections(2, 4) = 0 ' West connections(3, 1) = 0 ' North connections(3, 2) = 0 ' East connections(3, 3) = 2 ' South to Room 2 connections(3, 4) = 4 ' West to Room 4 connections(4, 1) = 0 ' North connections(4, 2) = 5 ' East to Room 5 connections(4, 3) = 3 ' South to Room 3 connections(4, 4) = 0 ' West connections(5, 1) = 0 ' North connections(5, 2) = 6 ' East to Room 6 connections(5, 3) = 4 ' South to Room 4 connections(5, 4) = 0 ' West connections(6, 1) = 0 ' North connections(6, 2) = 7 ' East to Room 7 connections(6, 3) = 5 ' South to Room 5 connections(6, 4) = 0 ' West connections(7, 1) = 0 ' North connections(7, 2) = 0 ' East connections(7, 3) = 6 ' South to Room 6 connections(7, 4) = 0 ' West If True = 0 Then True = 1 ' Main game loop currentRoom = 1 inventory = "" grueEncountered = False While True Cls ' Check for Grue in the dark cave (Room 7) If currentRoom = 7 And Not instr(inventory, "old lamp") Then grueEncountered = True Print "A Grue appears from the shadows! You have been eaten by the Grue!" End End If ' Print the room description Print rooms(currentRoom) ' Check for items Select Case currentRoom Case 2 Print "You see a shimmering gold coin." Case 4 Print "You see a magical scroll on the table." Case 5 Print "You see a rusty key on the ground." Case 6 Print "You see an old lamp on the pedestal." Case 7 Print "You see a mysterious potion on the throne." End Select ' Check win condition using Instr nItems=5 If Instr(inventory, "gold coin") = 0 then nItems=nItems-1 If Instr(inventory, "magical scroll") = 0 then nItems=nItems-1 If Instr(inventory, "rusty key") = 0 then nItems=nItems-1 If Instr(inventory, "old lamp") = 0 then nItems=nItems-1 If Instr(inventory, "mysterious potion") = 0 then nItems=nItems-1 if nItems=5 then Print "Congratulations! You have collected all the items and won the game!" End End If Print "What do you want to do? (north, east, south, west, take [item], inventory, quit)" Input action ' Handle input If action = "quit" Then End ElseIf mid$(action, 1, 4) = "take" Then item = mid$(action, 6) If currentRoom = 2 And item = "coin" Then inventory = inventory + "gold coin, " Print "You took the gold coin." ElseIf currentRoom = 4 And item = "scroll" Then inventory = inventory + "magical scroll, " Print "You took the magical scroll." ElseIf currentRoom = 5 And item = "key" Then inventory = inventory + "rusty key, " Print "You took the rusty key." ElseIf currentRoom = 6 And item = "lamp" Then inventory = inventory + "old lamp, " Print "You took the old lamp." ElseIf currentRoom = 7 And item = "potion" Then inventory = inventory + "mysterious potion, " Print "You took the mysterious potion." Else Print "You can't take that." End If ElseIf action = "inventory" Then Print "You have: "; inventory Else Select Case action Case "north": direction = "north" Case "east": direction = "east" Case "south": direction = "south" Case "west": direction = "west" Case Else: direction = "" End Select If direction <> "" Then ' nextRoom = connections(currentRoom, direction = "north" * 1 + direction = "east" * 2 + direction = "south" * 3 + direction = "west" * 4) dirNum=(direction = "north") * 1 + (direction = "east") * 2 dirNum=dirNum + (direction = "south") * 3 + (direction = "west") * 4 nextRoom = connections(currentRoom, dirNum) If nextRoom > 0 Then currentRoom = nextRoom Else Print "You can't go that way." End If End If End If Pause 1000' Pause for a moment Wend It is possible to navigate to a win, and also to get eaten. It was an interesting first pass. Not ready for prime time (and not MMBasic). This was with GPT-4o mini. I think I can select a bigger model. It got lots of details wrong, and needed lots of prompting, but it produced about 95% of 168 lines in a playable game. ~ Edited 2025-03-31 13:44 by lizby PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed |
||||
PeteCotton![]() Guru ![]() Joined: 13/08/2020 Location: CanadaPosts: 527 |
That is very interesting and enlightening. While I am a huge fan of the potential of AI, I can't help but notice that it is coding based on IF - THEN - ELSE logic rather than building an efficient logic engine for the game at hand. It doesn't matter for a short adventure like this, and to be honest, probably doesn't matter with a big adventure with the unlimited ram we have now. But it will be an interesting step forward when the AI can recognise that breaking away from simple logic steps and implementing some sort of interpreter/game engine is more efficient. And I'm not talking about Z-machine (used by Infocom adventures)- that was already invented, I'm saying that the AI comes up with it's own efficiencies. And when it does that, how does it balance efficiency vs readability. It might come up with it's own version of Z-Machine, but it is so heavily optimised that a human can't easily use/debug it. It will be interesting to watch it develop. |
||||
Mixtel90![]() Guru ![]() Joined: 05/10/2019 Location: United KingdomPosts: 7504 |
Not all exits are reciprocal in Zork (or Adventure / Colossal Cave). It can make mapping interesting. :) Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
lizby Guru ![]() Joined: 17/05/2016 Location: United StatesPosts: 3310 |
Although I had heard of it, I had zero experience with Zork before this thread. Do you mean that in actual game instances, it is possible to have one-way passages? PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed |
||||
JohnS Guru ![]() Joined: 18/11/2011 Location: United KingdomPosts: 3998 |
Some of the games do have one-way (e.g. you fall down a drop you can't climb back up) but I think he meant the other thing: there are rooms where you enter from a direction but to go back you don't say the opposite direction (presumably the passage bends somewhat). So, maybe you get in by East but back would not be West but some other direction. John |
||||
lizby Guru ![]() Joined: 17/05/2016 Location: United StatesPosts: 3310 |
That's a good point. I imagine that it would be the job of the designer to specify data structures and logic engine in detail. I image that large programs will essentially be a black box. The designer gives it a modified Turing test: do the inputs result in the expected outputs. PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed |
||||
Mixtel90![]() Guru ![]() Joined: 05/10/2019 Location: United KingdomPosts: 7504 |
Zork is far more advanced than the original Colossal Cave / Adventure / ADVENT game. It has quite an advanced command parser and a very good vocabulary. It may be better to ask for something similar to Colossal Cave but smaller. You should get simple one or two word commands then. Colossal Cave is the home of "a maze of twisty little passages, all alike" and it's close relative "a maze of twisty little passages, all different". :) Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
Page 1 of 2 ![]() ![]() |
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |