+OLD CS1 Posted September 13 Share Posted September 13 4 hours ago, Artoj said: does chatgpt scan through content? Does it use material on my blog as a source for its input? Yes. 1 Quote Link to comment Share on other sites More sharing options...
moocowmoo Posted Tuesday at 08:32 AM Share Posted Tuesday at 08:32 AM (edited) Here's a quick attempt of using ChatGPT o1-preview to write a snake game in BASIC. I pasted in a copy of the BASIC reference card that came with the TI at the beginning of the conversation. The full conversation is here: https://chatgpt.com/share/66fbb457-33b0-8005-b3cd-09a1a1a60e30 10 CALL CLEAR 15 CALL SCREEN(5) 16 REM Set background color to Dark Blue 20 CALL COLOR(2,16,5) 21 REM Set characters to White on Dark Blue 30 PRINT TAB(9);"***** SNAKE GAME *****" 40 PRINT 50 PRINT TAB(5);"PRESS ANY KEY TO START" 60 CALL KEY(0,K,S) 70 IF S=0 THEN 60 80 GOTO 100 100 REM Initialize Game Variables 101 CALL CLEAR 110 CALL SCREEN(3) 111 REM Set background color to Medium Green 120 CALL COLOR(2,16,3) 121 REM Set characters to White on Medium Green 130 DIM X(100) 131 DIM Y(100) 140 LENGTH=5 141 REM Initial length of the snake 150 SCORE=0 160 DIRECTION=4 161 REM Initial direction: Right (1=Up, 2=Down, 3=Left, 4=Right) 170 RANDOMIZE 171 REM Initialize random number generator 190 REM Initialize Snake Position 191 FOR I=1 TO LENGTH 200 X(I)=12 201 REM Start in the middle row 210 Y(I)=20-I 211 REM Start columns 220 CALL HCHAR(X(I),Y(I),79) 221 REM Draw the snake body using ASCII code 79 ('O') 230 NEXT I 240 REM Generate First Food 241 GOSUB 800 250 REM Main Game Loop 251 GOSUB 1000 252 REM Read user input 260 GOSUB 2000 261 REM Move snake 270 GOSUB 3000 271 REM Check for collisions and food 280 CALL SOUND(-50,110,0) 281 REM Short delay for game speed 290 GOTO 250 1000 REM Subroutine to Read User Input 1001 CALL KEY(0,K,S) 1010 IF S=0 THEN 1060 1020 IF K=69 THEN 1100 ELSE 1030 1030 IF K=88 THEN 1110 ELSE 1040 1040 IF K=83 THEN 1120 ELSE 1050 1050 IF K=68 THEN 1130 ELSE 1060 1100 NEWDIRECTION=1 1101 REM Up 1102 GOTO 1140 1110 NEWDIRECTION=2 1111 REM Down 1112 GOTO 1140 1120 NEWDIRECTION=3 1121 REM Left 1122 GOTO 1140 1130 NEWDIRECTION=4 1131 REM Right 1132 GOTO 1140 1140 REM Prevent reversing direction 1141 SUMDIR=DIRECTION+NEWDIRECTION 1142 IF SUMDIR=3 THEN 1060 ELSE 1143 1143 IF SUMDIR=7 THEN 1060 ELSE 1144 1144 DIRECTION=NEWDIRECTION 1145 GOTO 1060 1060 RETURN 2000 REM Subroutine to Move Snake 2001 CALL HCHAR(X(LENGTH),Y(LENGTH),32) 2002 REM Erase tail using space character 2010 FOR I=LENGTH TO 2 STEP -1 2020 X(I)=X(I-1) 2030 Y(I)=Y(I-1) 2040 NEXT I 2050 IF DIRECTION=4 THEN 2051 ELSE 2060 2051 Y(1)=Y(1)+1 2052 GOTO 2090 2060 IF DIRECTION=3 THEN 2061 ELSE 2070 2061 Y(1)=Y(1)-1 2062 GOTO 2090 2070 IF DIRECTION=1 THEN 2071 ELSE 2080 2071 X(1)=X(1)-1 2072 GOTO 2090 2080 IF DIRECTION=2 THEN 2081 ELSE 2090 2081 X(1)=X(1)+1 2090 REM Check for Wall Collision Before Drawing 2091 SUM=(X(1)<1)+(X(1)>24)+(Y(1)<1)+(Y(1)>32) 2092 IF SUM>=1 THEN 5000 ELSE 2095 2095 CALL HCHAR(X(1),Y(1),79) 2096 REM Draw head using ASCII code 79 ('O') 2100 RETURN 3000 REM Subroutine to Check Self-Collision and Food 3001 REM Check Self-Collision 3010 FOR I=2 TO LENGTH 3020 PROD=(X(1)=X(I))*(Y(1)=Y(I)) 3030 IF PROD=1 THEN 5000 ELSE 3040 3040 NEXT I 3050 REM Check Food Collision 3060 PROD=(X(1)=FOODX)*(Y(1)=FOODY) 3070 IF PROD=1 THEN 3080 ELSE 3100 3080 LENGTH=LENGTH+1 3090 SCORE=SCORE+10 3095 X(LENGTH)=X(LENGTH-1) 3096 Y(LENGTH)=Y(LENGTH-1) 3097 CALL SOUND(100,880,0) 3098 GOSUB 800 3100 RETURN 800 REM Subroutine to Generate Food 801 FOODX=INT(RND*22)+2 802 REM Rows between 2 and 23 810 FOODY=INT(RND*30)+2 811 REM Columns between 2 and 31 820 REM Ensure food doesn't appear on the snake 830 FOR I=1 TO LENGTH 840 PROD=(X(I)=FOODX)*(Y(I)=FOODY) 850 IF PROD=1 THEN 801 ELSE 860 860 NEXT I 870 CALL HCHAR(FOODX,FOODY,42) 871 REM Draw food using ASCII code 42 ('*') 880 RETURN 5000 REM Game Over Sequence 5001 CALL CLEAR 5010 CALL SCREEN(9) 5011 REM Set background color to Medium Red 5020 CALL COLOR(2,16,9) 5021 REM Set characters to White on Medium Red 5030 PRINT TAB(10);"GAME OVER!" 5040 PRINT 5050 PRINT TAB(8);"YOUR SCORE: ";SCORE 5060 PRINT 5070 PRINT TAB(6);"PRESS ANY KEY TO EXIT" 5080 CALL KEY(0,K,S) 5090 IF S=0 THEN 5080 5100 END Edited Tuesday at 08:46 AM by moocowmoo 1 Quote Link to comment Share on other sites More sharing options...
+OLD CS1 Posted Tuesday at 02:16 PM Share Posted Tuesday at 02:16 PM 5 hours ago, moocowmoo said: Here's a quick attempt of using ChatGPT o1-preview to write a snake game in BASIC. I pasted in a copy of the BASIC reference card that came with the TI at the beginning of the conversation. hehehe it learns like a child, so scold it like a child! The DIRECTION+NEWDIRECTION approach is novel and interesting to me. It still does not understand that an ELSE target to the next line in the program flow is unnecessary, and that the string of calculations for a true/false IF...THEN does not need to be compared to 1 as any non-zero result is considered to be true. It could still optimize by using more single-line calculations to replace several IF...THENs. During my programming development, I found using POS() with a short string and CHR$(K) is faster than all that single-value comparison, jump to line, set variable to appropriate value, jump out of section. (If only POS() had been overloaded to accept either a character string or numeric ASCII value for comparison. It would have made programming a little less awkward, but probably would have had no impact on performance.) EDIT: Actually, it assumes that true is 1 or greater, and does not take into account that a true result is -1. So line 2091 will not give the programmer its expected results (and, in fact, causes the program to break with * BAD VALUE IN 2095.) Lines 3030 and 3070 just dumb luck. There are other optimizations it could make, like not using temporary variables. But, this is what I would expect from a third or fourth grade-aged programmer. 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.