Posts

Es werden Posts vom April, 2023 angezeigt.

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 first click on the button wouldn't do anything, because the first event would just add the correct listener. A really dumb mistake that shows the AI sometimes generates wild non

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 limb type.

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,  1.1f, .9f, 0.75f, .8f, .8f,  1f,   0.9f, 1.1f,         // r,  s,   t,   u,   v,   w,   x,  y,  z            1.1f, 1.2f, 1.1f, 1f, .8f, 0.7f,  1.3f, .8f, 1.1f           }; or protected void determineWeightAndSkill() {         String text = getWord().getText().toLowe

Anger and joy...

Anger. ChatGPT loses the overview of several classes It's easy to work with ChatGPT on small pieces of code: "write this", "change that" works nicely. However I noticed that when we're coming to something like 5 classes and you work on all of them, the AI gets confused. For example, I was working on two classes: Creature and Element. The two classes are completely unrelated. Still, when I first discussed Element with ChatGPT and then wanted a change in Creature it messed things up and recommended things like: "To do this, you can define a static traits object in the Creature class that maps each trait to a bit key. You can then define a getBitKey method in the Element class that returns the bit key for a given character." This is just nonsense.  And it reminded me a trying to create complex scenery in Stable Diffusion where it can't keep separate characters in a scene apart.  Now the question is: can I create a more structured approach wher

Creating buckets of letters with equal probability

Bild
Next task: deciding whether a word will be a monster, a weapon, an armor etc. I want to do this by picking the middle character of a word, and then, depending on that character, decide which kind of dungeon entity it will be. Therefore let's create a fixed number of buckets, one or two per kind, and assign letters to each bucket so that each bucket contains letters of the same overall likelihood to appear in the English language. Sounds complicated? Not for ChatGPT. First I let it come up with the letter probabilities: Now I need a constant array that contains the letter probabilities of the english language - the first element the probability of an "a", the 25th the one of a "z". Can you create this in JS? Output: const letterProbabilities = [   0.0817, // a   0.0149, // b   0.0278, // c   0.0425, // d   0.1270, // e   0.0223, // f   0.0202, // g   0.0609, // h   0.0697, // i   0.0015, // j   0.0077, // k   0.0403, // l   0.0241, // m   0.0675, // n   0.0751,

The heart of the game - getting the words out of a web page

Bild
A game that is about turning words on web pages into dungeons needs to start with a function that gets all the words in a web page, and sorts them by length - we want the fiercest dragons and the most powerful swords first. My Java class to do this job took me a few days and had nearly 500 lines; I created an HTML scanner myself that featured methods to e.g. skip over comments and HTML tags. As you'll see by the end of this blog entry, I'm too embarassed to share it here. So I went ahead and asked ChatGPT: Hi, in this session we are a team of expert software developers who want to create a web based game in Javascript. First we we need a function that takes an URL, and that reads the web page of the URL and determines a list of the words of text it contains, sorted by character count. Can you write this function? And it did. I then asked it to create a test web page (I'm lazy): can you now write a little test web page that tests the function, with a text field where a

How it started...

Intro - why this blog? This blog is mostly for people who know software development and would like to understand how ChatGPT can and will change the way we are developing software.  Warning: this is about real (Javascript, Java) code. Back then, in the old days,   I had developed an Android RPG I and a few hundred users found fun. In retrospective it was probably way too complicated for an app. The idea of the game was: turn any web page into a dungeon: words are turned into monsters and weapons - the longer the word the more powerful the monster or weapon. Vowels determine the elements of the monster and weapon, consonants define the behavior of the monster. I also used the web page to dynamically generate the dungeon - nothing you saw was random or pre-thought, all came from the web page.  That was the mighty home page of the game I did: web raid mobile . Reboot, simplified, in Javascript I still like the core idea of fighting complicated words like " butyrylcholinesterase"