Posts

Would like to try out the new "function" feature of the ChatGPT API.. BUT...

Bild
 Development slowed down to a crawl... Damn you, Lilith !

My game works! But doesn’t.

 Nowhere done yet, but the game loop that  Once Initialises game UI and sends initial prompt to remote ChatGPT 3.5 that explains its job controlling the NPCs Enables controls for player to do an action Processes player action Creates prompt describing the situation, the last player move, the reaction of the game to last GPT move suggestion Communicates with remote ChatGPT to get an action Process NPC action Works! 95% of the code is written by ChatGPT 4, and in working with it I got halfway den cent JS skills. Wouldn’t say I’m good but I understand many concepts now that I didn’t get before, particularly the “spontaneously return complex structures in a function/method”, the asynchronous stuff (basic) and the functional stuff (basic). But GPT 3.5 IS JUST SO DAMN STUPID. I was hoping for a mode in which it replies with wrong answers, and the game updates it with “that was wrong” and the next time it gets it right. Far from it. Will spend happy hours tuning my prompt. Probably w...

ChatGPT as a teacher

Bild
Today I came to the conclusion that without a good understanding of asynchronous programming in Javascript, I cannot hope to come up with a game that uses asynchronous events for all player interaction and other asynchronous events to talk to a remote ChatGPT for NPC actions. My code was a mess, and even more important, after 3 refactorings of my game.js class following ChatGPT's suggestions, my mind was a mess as well. And (see other posts) I don't think that handing ChatGPT the control over the overall concepts, design, architecture, is a good idea. So I asked it to explain asynchronous JS programming to me. And it did. Quite exceptionally. See, in normal life you can learn something like this in several ways: You can read a book. I actually have a good JS book. A very, very tedious affair. I have 30+ years of serious programming experience (not counting my "geek teenager programs the heck out of his Sharp MZ-80A with 48K RAM and 1K ROM" time here). A JS book is 95...

Quite good for one hour...

Bild
With ChatGPT's help, today I created everything needed for chatting back and forth between human-controlled player and ChatGPT-controlled NPC. The human can click on a "chat" button which will unhide a text input field and a submit button, both nicely styled; clicking on the button again will hide it again. Another new section contains about 3 lines of scrollable chat from the NPCs.  I had to start a new session though; the long session I've been using for days now got extremely slow - the stuff I was typing appeared with something like one character per 3 seconds, while I was typing. No clue what was wrong; creating a new session made things fast again. Also, the new session was getting confused, mixing up names of HTML elements, forgetting what it had created etc.; this might be related with me getting confused a bit. The AI generated stuff so fast that I forgot a method it had generated. I then told it I need this function, it generated one that looked wrong (wrong...

Pathfinding and A*

If I want my NPCs to move towards the player on a nxm grid, and the grid can contain trees that the NPC cannot pass, I need an algorithm that finds the shortest path to the player. I gave this as a problem to ChatGPT: In class level I would like to have a new method shortestPath that finds out the shortest path that an NPC on coordinate startX, startY has to take to reach coordinate endX, endY, avoiding any squares where the top levelObject cannot be traversed. The result should be a list of coordinates starting with startX, startY and ending with endX, endY where each coordinate can be reached horizontally, vertically or diagonally from the previous one. To which it responded with: This sounds like a pathfinding problem, which can be solved using various algorithms such as A*, Dijkstra's Algorithm, or Breadth-First Search. Since you want to allow diagonal movement as well, A* would be a good choice here. However, please note that implementing such algorithms in a complex env...

Better prompt reveals massive differences between ChatGPT-3.5 and ChatGPT-4

After refining my prompt (in case you're interested you find it at the end of this blog entry), things are starting to look more bright. Embarassing moment: I told ChatGPT that there is a weapon lying around next to it, and also told it that this NPC wants to use tools like weapons, but I included neither an action to move closer to a tool nor to pick up a tool. Bummer. Added these and got these replies from ChatGPT: Prompt: The NPC is currently positioned 6 steps away from the player. The Player is not adjacent to the NPC. The NPC is a Fierce Warrior with traits: extraverted, conscientious. He is very eager to pick up new tools. He cautiously approaches the player. Depending on his character he attacks or chats. Sometimes he talks. He is generally not interested in giving away or receiving tools.. The NPC is currently carrying 0 out of 100 weight units. The closest tool is a weapon located 1 steps away. What is your response? Please provide action key, parameter if needed, and a b...

Prompting gone horribly wrong

Now this went differently than expected. I was doing my best to create a prompt that is so clear that the AI knows it has to answer with one of the 8 actions the game will be able to interpret. But it's not a dumb "I do what you want" AI. It's ChatGPT (using 3.5 turbo because it's way cheaper than 4.0). My clever initial prompt to explain the session's rules (actually I had ChatGPT4.0 rework it for clarity and brevity): You are in a turn-based RPG controlling multiple NPCs, while the human player controls their character. The game has various scenes with a grid layout. The player and NPCs take turns performing actions. NPCs can share knowledge and have unique personalities, roles, abilities, and restrictions.     Possible actions:     1. MOVE_CLOSER: Move one step towards the player if unoccupied.     2. MOVE_AWAY: Move one step away from the player if unoccupied.     3. DO_NOTHING: Remain idle.     4. TALK: Spea...

Using ChatGPT to code calling ChatGPT to be my opponent

Now for the really fun / challenging / possibly dumb part: after thinking how the combat mechanics should work I noticed that it might be cool to leave that to ChatGPT. So after some interactive experimentation where ChatGPT surprised me with thoughtful replies on what it would do I went ahead and constructed this prompt (and had it simplify by... guess who):  `You are in a turn-based RPG controlling multiple NPCs, while the human player controls their character. The game has various scenes with a grid layout. The player and NPCs take turns performing actions. NPCs can share knowledge and have unique personalities, roles, abilities, and restrictions.     Possible actions:     1. MOVE_CLOSER: Move one step towards the player if unoccupied.     2. MOVE_AWAY: Move one step away from the player if unoccupied.     3. DO_NOTHING: Remain idle.     4. TALK: Speak to the player if adjacent, with your chosen text. ...

First crappy dungeon painting done, now off to the real stuff

Bild
Okay, after getting stable diffusion to generate all kinds of stuff for me, I've got a first crappy-looking dungeon, with 90% of the code written by ChatGPT. But hey, it is a full dungeon level with weapons and armor and a NPC in it! And drawing stuff on top of other stuff! In the end, debugging was painful, damn Javascript. At some point some subclass returned not a DrawingObject(URL) but the URL itself. A strongly typed language would just have seen that. Oh well. Now for the fun part - getting ChatGPT to be the player's opponent in the game. But that's for next update.  

Sometimes ChatGPT is nearly creepy in its level of understanding

TL;DR:  when helping to write code, ChatGPT is well aware of the meaning of the class you are writing, and will e.g. implement isTraversable() for a wall to return false, for a floor to return true, because it knows what walls are, what you do with walls in an RPG etc. Today I wanted it to create simple classes for representing level entities like walls and floors. So I first asked it to create a DrawingObject that pretty much only represents an image URL, and then a LevelObject that knows how to be drawn with a DrawingObject, and has a method "isTraversable()" This is my prompt: note that I didn't say anything about the purpose of isTraversable() okay, now I need a couple of JS classes. First a simple class "LevelObject" that has a method isTraversable() that throws a "need to be implemented by subclasses" error like the one you did before, a method getDrawingObject() that returns null And it created the JS class. I then wanted it to change it slig...

Rendering on a canvas

Bild
Yesterday was a great day working with ChatGPT4. I am very happy to have invested those $20 into that plus license - availability and speed are amazing.  Now that I spent some time creating first, shabby versions of player, monsters, NPCs, trees, walls, stone floor, it's time to do a first simple rendering.  Nicely, ChatGPT remembers your conversation if you click on it, so I started over where I left a week ago and asked: can we continue this conversation? Now I have all the images ready to continue; I would like to first start with the code to draw on the Canvas. can you show me an example: assume I have to coordinates xmax and ymax, and I want to draw a grid of 0..xmax-1 by 0..ymax-1 . I have a class called Level with a method getDrawingObjectsAt(x,y) that returns a sorted list of DrawingObject objects that need to be drawn on this coordinate after each other. A DrawingObject has a method getImage() that returns an image URL pointing to a .png file. Can you show me the code...

Timeout

Bild
Switching AIs from ChatGPT to stable diffusion as I need a number of images for warriors, guards, peacekeepers, traders, cowards, to populate my dungeon. And a hero of course. Working with SD 15 model (the RPG model wasn't so impressive). The Elden Ring Lora and the extension to remove backgrounds are very helpful, and controlnet helps me have everybody have the same stance. Won't try animation for the first attempt. Still quite a bit to do - 5 different elements x about 8 different types of NPC/monster x create 100 images to select the best from = 3000 images to be generated. Here's a few. Need to be scaled and cleaned up still.

Why you should ALWAYS and THOROUGHLY review ChatGPT's code

TL;DR: sometimes ChatGPT does stupid coding mistakes. And if you ask it to correct them, sometimes it has no clue about the root cause and tries to hack around it, which is not what you want.    Came across a fun issue when creating the second HTML page. In the first page, a tiny bit of its JS code was stupidly wrong, and I didn't notice it: It added an event listener to the button to proceed to the next page, and for mysterious reasons added a listener to add a listener, instead of adding a listener.   startButton.addEventListener("click", function() {       startButton.addEventListener("click", function() {           ... do stuff ..           // Navigate to the next screen, e.g.:           window.location.href = "levelconfirmation.html";       });     }); As a result, the f...

ChatGPT as UX designer / HTML coder

Bild
TL;DR: ChatGPT can be fairly creative if you let it. The question is when to give it this kind of freedom and when will this just create crap? For designing simple HTML pages with some Javascript for the interaction of elements it is almost perfect.   Like pretty much every computer scientist, I suck at creating beautiful UIs. There is a reason that UX designers have studied design and have different skills. So for my little RPG I hopefully convinced ChatGPT that it is an excellent UX designer and HTML coder. Let's see if it can create responsive, good looking start screens for my game... We both started full of enthusiasm and I promptly ran into the "if the prompt is too complicated it will just error out" issue. (could be also random issues, right now ChatGPT is erroring out often). So I came up with a more focused, task-oriented prompt that gave ChatGPT less freedom and a very clear list of things to do. Here it is: Background: the game is about turning web pages into ...

Documenting code is a cool ChatGPT skill

TL;DR ChatGPT creates excellent JSDoc comments that explain method purpose, parameters and return values. Can't help to think: if a comment can be automatically and reliably generated by an AI, it shouldn't be part of the code but generated on demand when needed.  (please note: I'm a JS newbie, sometimes I'm easy to amaze) So I thought why not give ChatGPT the task to write good comments for the method I had asked it to create. So I took a class and a method and asked it to create a comment.  And it did. Here's an example: /**    * Equips a tool from the creature's bag to a specified limb.   * @param {Tool} tool - The tool to be equipped on the limb.   * @param {number} limbIndex - The index of the limb in the creature's limbs array.   * @returns {boolean} - Returns true if the tool was successfully equipped on the limb, and false if the tool was not found in the bag,   * the limb already has a tool equipped, or the tool is not compatible with the...

Overwhelming ChatGPT with a lengthy wish? Inventory management

Bild
TL;DR: Learned two things today: 1. when you confront ChatGPT with a too complicated request you just get a technical error. 2. ChatGPT is really good at explaining how the code works that it generates, incl. simple to understand code snippets. Now this was underwhelming: Me: Assume I have a class Creature that represents a Creature (a monster, a NPC, a player) in a role playing game. This creature needs to have a bag in which it carries stuff. It also has the following limbs: head, arms, body, feet, and it has two hands. Also I have a class Tool that can be any tool that can be put into a bag, and from the bag moved to a limb or to a hand. A limb and a hand can only hold maximum 1 tool. If I move a tool from bag to limb or hand, and there is a tool there already, the former tool will automatically move to the bag. Can you create code for methods a) to put a tool in the bag b) to take a tool out of the bag and assign it to a limb. If the limb holds another tool, this is put into the...

Creating unit tests: is the glass half empty or half full

You can ask ChatGPT to create unit tests for a class. Just paste the class code into the prompt and ask it to create unit test. It will then create a good start for a unit test that will fail 100%. ChatGPT 4 does understand the concept of a unit test. It understands what to test for a class that has this and that member and this and that method. Not perfectly well but usable as a great starting point. However, ChatGPT is no human who understands what the class is supposed to do. It is a large language model and it tries to make sense of the class in terms of the words you're using for members and such, often with hilariously wrong test data. I still find it useful, it generates all the right method calls and correct syntax and even descriptions what the test does. All you need to do is to change what the test data you feed in and result really should be. So for me the glass is half full. ChatGPT makes my writing unit tests faster by maybe a factor of 2.

A first summary and recommendations after a few days of work

I notice I'm diving to deep into details about the game I'm converting to Javascript with ChatGPT.Maybe much is not so interesting for you, dear reader. So here's a summary without such details, along with a few recommendations for working with it that might help you when doing the same. Working on modular and independent classes is magic ChatGPT is extraordinarily good at working on single classes that don't have too many dependencies to other classes. Tasks like creating new methods, either by converting a method from Java to Javascript, or by understanding a specification text and implementing it, are perfect for ChatGPT. On these tasks it performs on a superhuman level. With the AI, I got stuff done in Javascript (where I'm a beginner) in 1/10th of the time that I get similar stuff done in Java (where I'm an expert).  Limitation: it doesn't really think and comes up with patterns / algorithms that do the job but don't perform perfect and can be optim...

Creating a new superclass for two classes

I noticed that my classes of creatures and tools need a common superclass that holds the DungeonEntityInfo it stems from, and the element count. In my game, vowels are turned into elements of the chinese philosophy - wood, water, fire, metal, earth, and the elements play a vital role in combat and also in naming stuff. Everything has elements. So the class that counts elements needs to go there. I gave this little refactoring task to ChatGPT, and it pulled it off quite nicely, but not totally correct. See below for details. A few observations: it asks me to import ElementCounter in my subclasses as well as in the new base class, which is not right - the ElementCounter only needs to be known by the new base class that uses it; the subclasses need to import the new base class instead. Small error. One of the two classes, Creature, had an accessor for a member I'm pulling up to the new super class, the other doesn't. Still, ChatGPT asks me to remove it from both classes (classes i...

Converting (simple) stuff from Java to Javascript

Now ChatGPT and I are creating the class I am using for swords and armor and stuff. All these use three factors: an efficiency which is derived from the level of the tool, and a weight and a skill that are derived from the letter that the tool represents - different characters influence weight and skill differently. An 'h' weighs less than an 'x', obviously. Now I got daring and created the class in 3 steps, each time feeding ChatGPT bits of the java class of my old app like: private static float[] weightFactorsForLetters = new float[] {         // a,  b,   c,   d,   e,   f,   g,  h            1f,  0.8f, 1.2f, 0.8012f, 1f,   1.1f, 1.2f, 0.6f,         // i,  j,   k,   l,   m,   n,   o,   p,  q,            1f...