Jump to content
IGNORED

AI Based TI-99 Development is a thing!


Recommended Posts

  • 3 weeks later...

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 by moocowmoo
  • Like 1
Link to comment
Share on other sites

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!

Screenshot2024-10-01at10-01-53ChatGPT-TI-99_4ABASICOverview.thumb.png.3ffa9e94965be08847e16fc972b5124c.png

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.

  • Haha 1
Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...