Progamming with Chatgpt 4/ copilot

The place for codemasters or beginners to talk about programming any language for the Spectrum.
Post Reply
User avatar
bluespikey
Manic Miner
Posts: 954
Joined: Tue Jun 30, 2020 3:54 pm

Progamming with Chatgpt 4/ copilot

Post by bluespikey »

So I've spent this lunch seeing how Bing Copilot (Apparently ChatGPT V 4) has come on with Spectrum basic. And.... it looks good.

Back in the day there was a type-in in one of the mags called Beach Comber. Simple stuff, but I proudly showed it off to everyone. So I thought I'd try to recreate it. And Copilot did a fine job of the code. It knew that the cursors were keys 5,6,7 and 8. It knew the dimensions of the Spectrum screen. It needed to be prompted to put If..Then conditions all onto one line seperated by colons, and that its 'goto' and not 'go to'. Also I couldn't convince it that comments had to be rem lines and not semi-colons. Otherwise, top stuff. I really will be out of a job in a few years.

Prompts :
Spoiler
Can you please write me a program which has an asterisk in the middle of the screen. If I press one of the Spectrum's cursor keys, then the asterisk moves in that direction.
can you add code so that the player cannot move outside the bounds of the screen?
there is also a line of dashes that run horizontally across the screen . this line starts at the top of the screen, and then moves down the screen until 3/4 of the way down. it then reverses and moves back up to the top of the screen, before moving down again . It moves all the time and does not wait for player input. Can you add this to the code please?
thankyou. The players score starts at zero, and is shown at the top of the screen.. there is a gold coin on the screen which is represented by the letter 'O'. It appears at a random spot. If the player moves over the coin, the coin reappears at a random place on the screen, and the players score increases by one.
hi. thats almost correct. In sinclair spectrum basic, if you have a if statement that is true, all the statements that are carried out must be on the end of the line seperated by a colon.
hi. the line currently moves up and down the screen. Can you also set it so that it reverses each turn with a 1 in 20 chance?
Can you only show the location of the coin if it is below or equal to the line. If it is above the line then do not show it.
If the player is above the line , then the game should end. A message should say "Game over!" and the player's score should be printed. The code can then stop.
hi. in sinclair basic, comments begin with a rem statement and not a comma
can you give me the code without commens please?
last thing. On line 210, the basic command "go to" is one word, so should be goto.
And heres the output code :
Spoiler
10 LET x=15: LET y=11
20 LET lx=0: LET ly=0
30 LET dir=1
40 LET score=0
50 LET cx=INT (RND*32)
60 LET cy=INT (RND*24)
70 PRINT AT 0,0; "Score: "; score
80 PRINT AT y,x;"*": PRINT AT ly,lx;"--------------------------------"
90 IF ly<=cy THEN PRINT AT cy,cx;"O"
100 PAUSE 5
110 IF INKEY$="7" AND y>0 THEN LET y=y-1
120 IF INKEY$="8" AND x<31 THEN LET x=x+1
130 IF INKEY$="6" AND y<23 THEN LET y=y+1
140 IF INKEY$="5" AND x>0 THEN LET x=x-1
150 IF ly=17 OR ly=0 THEN LET dir=-dir
160 IF RND < 0.05 THEN LET dir=-dir
170 LET ly=ly+dir
180 IF x=cx AND y=cy THEN LET score=score+1: LET cx=INT (RND*32): LET cy=INT (RND*24)
190 IF y<ly THEN PRINT "Game over! Your score is: "; score: STOP
200 CLS
210 GOTO 70
The output tap file can be found at https://filebin.net/tr67g190l6jx7w1z/beachcomber.tap

Now.... It doesn't quite work for some reason. The IF Statements on lines 90, 150 and 190 never seem to become true, whereas 160 and 180 do. But I'm out of lunch hour to check why, but its probably minor.
User avatar
Morkin
Bugaboo
Posts: 3277
Joined: Mon Nov 13, 2017 8:50 am
Location: Bristol, UK

Re: Progamming with Chatgpt 4/ copilot

Post by Morkin »

I couldn't access the program from the link.

I did ask ChatGPT to correct it though :lol:
Spoiler
There are a few issues in your ZX Spectrum BASIC program that need to be addressed to make it work properly:

Missing Line Numbers: The line numbers in ZX Spectrum BASIC are essential for control flow. Without them, the program cannot jump to specific lines using GOTO or GOSUB. Ensure that all lines have line numbers.

PRINT AT Syntax: In ZX Spectrum BASIC, the syntax for the PRINT AT statement is PRINT AT <row>,<column>; <expression>. You have reversed the row and column parameters in lines 70 and 80.

PAUSE Command: The PAUSE command in ZX Spectrum BASIC requires the number of frames to pause, not milliseconds. Assuming a frame rate of 50 frames per second, you can adjust the value accordingly. You might want to use something like PAUSE 2 for a short pause.

Game Over Condition: You are checking if the player's position (y) is less than the position of the obstacle (ly). This condition doesn't make sense for a typical game over scenario. It seems you want to end the game when the player hits the obstacle. You should check if the player's position (x, y) matches the obstacle's position (cx, cy) instead.

Random Number Range: The random number generation for cx and cy should generate numbers within the screen boundaries (32 columns and 24 rows).

Displaying Score: Line 70 should be placed after the CLS command in line 200 to ensure that the score is not cleared from the screen.

Here's the corrected version of your program:
Spoiler

Code: Select all

10 LET x=15: LET y=11
20 LET lx=0: LET ly=0
30 LET dir=1
40 LET score=0
50 LET cx=INT (RND*32)
60 LET cy=INT (RND*24)
70 PRINT AT 0,0; "Score: "; score
80 PRINT AT y,x;"*": PRINT AT lx,ly;"--------------------------------"
90 IF ly<=cy THEN PRINT AT cy,cx;"O"
100 PAUSE 2
110 IF INKEY$="7" AND y>0 THEN LET y=y-1
120 IF INKEY$="8" AND x<31 THEN LET x=x+1
130 IF INKEY$="6" AND y<23 THEN LET y=y+1
140 IF INKEY$="5" AND x>0 THEN LET x=x-1
150 IF ly=17 OR ly=0 THEN LET dir=-dir
160 IF RND < 0.05 THEN LET dir=-dir
170 LET ly=ly+dir
180 IF x=cx AND y=cy THEN LET score=score+1: LET cx=INT (RND*32): LET cy=INT (RND*24)
190 IF x=cx AND y=cy THEN LET score=score+1: LET cx=INT (RND*32): LET cy=INT (RND*24)
200 IF y=ly AND x=cx THEN PRINT "Game over! Your score is: "; score: STOP
210 CLS
220 GOTO 70
My Speccy site: thirdharmoniser.com
User avatar
ParadigmShifter
Manic Miner
Posts: 671
Joined: Sat Sep 09, 2023 4:55 am

Re: Progamming with Chatgpt 4/ copilot

Post by ParadigmShifter »

bluespikey wrote: Tue Mar 19, 2024 1:59 pm and that its 'goto' and not 'go to'.
Image

?

EDIT: Maybe it is GOTO with the 128 editor or something? I dunno, never had a 128K. It was GOTO on ZX81 though. I think the QL had the spaces in GO TO and GO SUB also
User avatar
patters
Manic Miner
Posts: 471
Joined: Thu Apr 11, 2019 1:06 am

Re: Progamming with Chatgpt 4/ copilot

Post by patters »

bluespikey wrote: Tue Mar 19, 2024 1:59 pm Now.... It doesn't quite work for some reason.
Your job will remain safe for some time I'm sure. :lol:
User avatar
Einar Saukas
Bugaboo
Posts: 3145
Joined: Wed Nov 15, 2017 2:48 pm

Re: Progamming with Chatgpt 4/ copilot

Post by Einar Saukas »

bluespikey wrote: Tue Mar 19, 2024 1:59 pm I really will be out of a job in a few years.
Unless you are one of those programmers whose code DO work :)
User avatar
+3code
Manic Miner
Posts: 434
Joined: Sat Mar 19, 2022 7:40 am

Re: Progamming with Chatgpt 4/ copilot

Post by +3code »

ParadigmShifter wrote: Tue Mar 19, 2024 3:06 pm EDIT: Maybe it is GOTO with the 128 editor or something?
No, in 128 is the same as in 48, GO TO (with space). You can type it without space, but the editor adds it.
mrcook
Drutt
Posts: 46
Joined: Tue Jun 09, 2020 7:31 pm

Re: Progamming with Chatgpt 4/ copilot

Post by mrcook »

Reminded me of this chap on YT:
User avatar
arjun
Microbot
Posts: 151
Joined: Sat Sep 19, 2020 7:34 am
Location: India
Contact:

Re: Progamming with Chatgpt 4/ copilot

Post by arjun »

bluespikey wrote: Tue Mar 19, 2024 1:59 pm
Spoiler
Can you please write me a program which has an asterisk in the middle of the screen. If I press one of the Spectrum's cursor keys, then the asterisk moves in that direction.
can you add code so that the player cannot move outside the bounds of the screen?
there is also a line of dashes that run horizontally across the screen . this line starts at the top of the screen, and then moves down the screen until 3/4 of the way down. it then reverses and moves back up to the top of the screen, before moving down again . It moves all the time and does not wait for player input. Can you add this to the code please?
thankyou. The players score starts at zero, and is shown at the top of the screen.. there is a gold coin on the screen which is represented by the letter 'O'. It appears at a random spot. If the player moves over the coin, the coin reappears at a random place on the screen, and the players score increases by one.
hi. thats almost correct. In sinclair spectrum basic, if you have a if statement that is true, all the statements that are carried out must be on the end of the line seperated by a colon.
hi. the line currently moves up and down the screen. Can you also set it so that it reverses each turn with a 1 in 20 chance?
Can you only show the location of the coin if it is below or equal to the line. If it is above the line then do not show it.
If the player is above the line , then the game should end. A message should say "Game over!" and the player's score should be printed. The code can then stop.
hi. in sinclair basic, comments begin with a rem statement and not a comma
can you give me the code without commens please?
last thing. On line 210, the basic command "go to" is one word, so should be goto.
"hi", "please" and "thank you" to an AI who doesn't have emotions? You are a real polite person. Thank You!
User avatar
R-Tape
Site Admin
Posts: 6409
Joined: Thu Nov 09, 2017 11:46 am

Re: Progamming with Chatgpt 4/ copilot

Post by R-Tape »

arjun wrote: Wed Mar 20, 2024 6:57 am "hi", "please" and "thank you" to an AI who doesn't have emotions? You are a real polite person. Thank You!
The TX130-X Orderbringer™ will remember this kindness in 20 years time and not crush bluespikey's skull under its wheels.
firelord
Manic Miner
Posts: 557
Joined: Wed Nov 03, 2021 10:57 am
Location: Greece - Thessaloniki

Re: Progamming with Chatgpt 4/ copilot

Post by firelord »

My experience with ChatGPT (the free version) is that it outputs good code BUT output always seem to be 80-90% correct. "It tasted almost, but not quite, entirely unlike tea" .
If I tell it to correct one thing it breaks another. It's behaviour seems so consistent that I think it might be on purpose (maybe the paid version does no have this issue). Three months ago I would have said 80% but now it seems to create better code.
Is it just me or anyone else thinks the same?

Btw, I discovered an AI story generator that seems "unlocked" .It can write !(polically correct) stuff - which ChatGPT does not allow. It
User avatar
bluespikey
Manic Miner
Posts: 954
Joined: Tue Jun 30, 2020 3:54 pm

Re: Progamming with Chatgpt 4/ copilot

Post by bluespikey »

firelord wrote: Wed Mar 20, 2024 7:51 am
If I tell it to correct one thing it breaks another. It's behaviour seems so consistent that I think it might be on purpose (maybe the paid version does no have this issue). Three months ago I would have said 80% but now it seems to create better code.
Is it just me or anyone else thinks the same?
Yeah, thats my main thought on this. A few months back it seemed to throw in generic Basic commands, and didn't specify Spectrum basic. Now it does, and is aware of screen constraints and cursor keys etc. And this is only still the beginning....
arjun wrote: Wed Mar 20, 2024 6:57 am "hi", "please" and "thank you" to an AI who doesn't have emotions? You are a real polite person. Thank You!
Roko's Basilisk (https://en.wikipedia.org/wiki/Roko%27s_basilisk) will be kind to me.
firelord
Manic Miner
Posts: 557
Joined: Wed Nov 03, 2021 10:57 am
Location: Greece - Thessaloniki

Re: Progamming with Chatgpt 4/ copilot

Post by firelord »

bluespikey wrote: Wed Mar 20, 2024 9:02 am Yeah, thats my main thought on this. A few months back it seemed to throw in generic Basic commands, and didn't specify Spectrum basic. Now it does, and is aware of screen constraints and cursor keys etc. And this is only still the beginning....
I'm not talking only about Spectrum basic, I'm talking about all languages. I have 80% correct output on bash,python and javascript (which I think it became 90% recently). The last 10-20% I usually end up doing it myself .
AndyC
Dynamite Dan
Posts: 1409
Joined: Mon Nov 13, 2017 5:12 am

Re: Progamming with Chatgpt 4/ copilot

Post by AndyC »

Ultimately ChatGPT (and all LLMs) is essentially predictive text on steroids. It's very, very good at generating plausible looking text but it never actually understands what it is doing. It's why it might get a long way to producing vaguely correct code, especially in boilerplate scenarios, but it'll almost certainly never reach the point where edge case behaviour is 100% correct every time.
User avatar
Joefish
Rick Dangerous
Posts: 2059
Joined: Tue Nov 14, 2017 10:26 am

Re: Progamming with Chatgpt 4/ copilot

Post by Joefish »

With Z80 it seems to fail to grasp the very precise rules whereby you can perform certain tasks on certain registers, but not every task on every register, as you usually can with variables in a higher-level language. It also seems to throw-in the odd instruction from other assembly languages (like MULT) when it feels like it, even after being told not to. Although a dearth of examples of Z80 compared to all those help and tutorial pages for modern programming languages will have a big effect on it.

Because of the way it's learned - by devising its own patterns and connections across a mass of sources - I don't think it's ever had to learn very specific rules. Hence its operators struggling with trying to stop it spouting lunatic racist conspiracy theories when it's been reading nothing but internet posts its entire existence.

Or like people can speak grammatically correct sentences without being able to explain on demand all the underlying rules they're using, yet when told they're breaching one rule find it almost impossible to then incorporate that into how they speak (people who will always say 'pacific' instead of 'specific' or 'should of' no matter how hard you beat them).
Post Reply