Free ChatGPT

Post your FreeBASIC source, examples, tips and tricks here. Please don’t post code without including an explanation.
Post Reply
neil
Posts: 594
Joined: Mar 17, 2022 23:26

Free ChatGPT

Post by neil »

I found a free, no-login ChatGPT. https://gptchatly.com

I typed "Freebasic Fish Aquarium Code," and I got this.

Code: Select all

Screen 12

Dim As Integer fishX, fishY
fishX = 40
fishY = 12

While Inkey <> Chr(27) ' Press Escape key to exit
    Cls
    Color 4, 0
    Locate fishY, fishX
    Print "><(((('>"
    Sleep 100

    If fishX < 80 Then
        fishX = fishX + 1
    Else
        fishX = 1
    End If
Wend
neil
Posts: 594
Joined: Mar 17, 2022 23:26

Re: Free ChatGPT

Post by neil »

Here's another free one. https://chatgptt.me/

I tested it by typing. "Freebasic the matrix rain code." It's not perfect. I got this.

Code: Select all

ScreenRes 800, 600, 32

Dim Shared As Integer columns = 80
Dim Shared As Integer rows = 25

Dim Shared As String matrix(rows, columns)

Sub InitializeMatrix()
    Dim As Integer i, j
    For i = 0 To rows - 1
        For j = 0 To columns - 1
            matrix(i, j) = Chr(Rnd * 94 + 33)
        Next
    Next
End Sub

Sub UpdateMatrix()
    Dim As Integer i, j
    For i = rows - 1 To 1 Step -1
        For j = 0 To columns - 1
            matrix(i, j) = matrix(i - 1, j)
        Next
    Next
    For j = 0 To columns - 1
        matrix(0, j) = Chr(Rnd * 94 + 33)
    Next
End Sub

Sub DisplayMatrix()
    Dim As Integer i, j
    For i = 0 To rows - 1
        For j = 0 To columns - 1
            Locate i + 1, j + 1
            Color Rgb(0, 255, 0)
            Print matrix(i, j);
        Next
    Next
End Sub

Randomize Timer

InitializeMatrix()

Do
    UpdateMatrix()
    DisplayMatrix()
    Sleep 100
Loop Until InKey <> ""

' It made a mistake I had to comment out the next line.
' ScreenRes 0
neil
Posts: 594
Joined: Mar 17, 2022 23:26

Re: Free ChatGPT

Post by neil »

Last edited by neil on Feb 04, 2024 20:44, edited 4 times in total.
neil
Posts: 594
Joined: Mar 17, 2022 23:26

Re: Free ChatGPT

Post by neil »

This asteroids field was generated by typing "freebasic asteroids field code" using https://echatgpt.org/chat

Code: Select all

SCREEN 12 ' Set the graphics mode

CONST screenWidth = 800
CONST screenHeight = 600
CONST maxAsteroids = 10

TYPE Asteroid
    x AS SINGLE
    y AS SINGLE
    speed AS SINGLE
    dirX AS SINGLE
    dirY AS SINGLE
    size AS INTEGER
END TYPE

DIM SHARED asteroids(maxAsteroids) AS Asteroid
DIM SHARED AS INTEGER i

SUB InitializeAsteroids()
    RANDOMIZE TIMER
    
    FOR i = 1 TO maxAsteroids
        asteroids(i).x = RND * screenWidth
        asteroids(i).y = RND * screenHeight
        asteroids(i).speed = RND * 5 + 1
        asteroids(i).dirX = RND * 2 - 1
        asteroids(i).dirY = RND * 2 - 1
        asteroids(i).size = INT(RND * 3) + 1
    NEXT
END SUB

SUB UpdateAsteroids()
    FOR i = 1 TO maxAsteroids
        asteroids(i).x = asteroids(i).x + asteroids(i).dirX * asteroids(i).speed
        asteroids(i).y = asteroids(i).y + asteroids(i).dirY * asteroids(i).speed
        
        IF asteroids(i).x < 0 THEN
            asteroids(i).x = screenWidth
        END IF
        
        IF asteroids(i).x > screenWidth THEN
            asteroids(i).x = 0
        END IF
        
        IF asteroids(i).y < 0 THEN
            asteroids(i).y = screenHeight
        END IF
        
        IF asteroids(i).y > screenHeight THEN
            asteroids(i).y = 0
        END IF
    NEXT
END SUB

SUB DrawAsteroids()
    SCREENLOCK
    
    CLS
    
    FOR i = 1 TO maxAsteroids
        CIRCLE (asteroids(i).x, asteroids(i).y), asteroids(i).size * 10, 15
    NEXT
    
    SCREENUNLOCK
END SUB

SUB MainLoop()
    InitializeAsteroids()
    
    DO
        UPDATEAsteroids()
        DrawAsteroids()
        
        SLEEP 30
    LOOP UNTIL INKEY$ <> ""
END SUB

MainLoop()
BasicCoder2
Posts: 3909
Joined: Jan 01, 2009 7:03
Location: Australia

Re: Free ChatGPT

Post by BasicCoder2 »

How is it able to do that? !!!

This is what it gave me,

Code: Select all

#include "fbgfx.bi"
#include "math.bi"

const SCREEN_WIDTH = 800
const SCREEN_HEIGHT = 600

dim as integer asteroid_size = 10
dim as integer asteroid_x = SCREEN_WIDTH / 2
dim as integer asteroid_y = SCREEN_HEIGHT / 2
dim as integer asteroid_speed = 5
dim as integer asteroid_heading = rnd * 360

dim as integer ship_x = SCREEN_WIDTH / 2
dim as integer ship_y = SCREEN_HEIGHT / 2

screenres SCREEN_WIDTH, SCREEN_HEIGHT, 32
randomize timer

do
    sleep 10

    ' Clear screen
    cls

    ' Move the asteroid
    asteroid_x += asteroid_speed * cos(asteroid_heading * 3.14159 / 180)
    asteroid_y += asteroid_speed * sin(asteroid_heading * 3.14159 / 180)

    ' Draw the asteroid
    circle(asteroid_x, asteroid_y, asteroid_size), RGB(255, 255, 255), true

    ' Draw the ship
    circle(ship_x, ship_y, 5), RGB(0, 0, 255), true

    ' Check for collision
    if abs(ship_x - asteroid_x) < asteroid_size and abs(ship_y - asteroid_y) < asteroid_size then
        print "Asteroid impact!"
        exit do
    end if

    ' Read user input
    if inkey() = "q" then exit do

    ' Move the ship using arrow keys
    if scancode() = 75 then ship_x -= 5 ' Left arrow
    if scancode() = 77 then ship_x += 5 ' Right arrow
    if scancode() = 72 then ship_y -= 5 ' Up arrow
    if scancode() = 80 then ship_y += 5 ' Down arrow

    ' Wrap the ship around the screen
    if ship_x < 0 then ship_x = SCREEN_WIDTH - 1
    if ship_x >= SCREEN_WIDTH then ship_x = 0
    if ship_y < 0 then ship_y = SCREEN_HEIGHT - 1
    if ship_y >= SCREEN_HEIGHT then ship_y = 0

    ' Wrap the asteroid around the screen
    if asteroid_x < 0 then asteroid_x = SCREEN_WIDTH - 1
    if asteroid_x >= SCREEN_WIDTH then asteroid_x = 0
    if asteroid_y < 0 then asteroid_y = SCREEN_HEIGHT - 1
    if asteroid_y >= SCREEN_HEIGHT then asteroid_y = 0

loop while true

sleep
neil
Posts: 594
Joined: Mar 17, 2022 23:26

Re: Free ChatGPT

Post by neil »

@BasicCoder2
I heard AI will be perfected and ready for everyone to use in five years.
At least it kind of knows what FreeBasic is.
BasicCoder2
Posts: 3909
Joined: Jan 01, 2009 7:03
Location: Australia

Re: Free ChatGPT

Post by BasicCoder2 »

@neil
It amazes me.
Until now I haven't really tried it myself as you had to sign up first.
Although its responses may only be something to work from it seems promising in the future.
I asked it for code for another problem without mentioning the language and it gave me a Python example.
I read that it is important to remember it doesn't know what it is writing and it can write things that are untrue or wrong.
A case of BS in BS out as with any natural language interface to a data base.
I asked it questions about other things I already knew the answer to and it gave concise correct answer in response.
neil
Posts: 594
Joined: Mar 17, 2022 23:26

Re: Free ChatGPT

Post by neil »

Here's a deep learning ChatGPT; this one can debug code.
I pasted my console compiler errors, and it fixed the code.
This might be the smartest one yet.
https://deepai.org/chat
BasicCoder2
Posts: 3909
Joined: Jan 01, 2009 7:03
Location: Australia

Re: Free ChatGPT

Post by BasicCoder2 »

@neil

Thanks for these links to ai chat it has been fun.

I thought I would search for links on how these programs could write code from a description and then thought why not ask the AI :)

It didn't actually explain how it was done in any detail only that it was done using predefined templates and algorithms.

""Chatai is a code generation tool that uses natural language processing and machine learning algorithms to interpret text descriptions and convert them into executable code. The tool analyzes the text input to identify the key requirements and specifications, and then generates the necessary code components using predefined templates and algorithms. This process allows developers to quickly and accurately translate their ideas and requirements into code without having to manually write every line of code from scratch.""

I then went on to google for answers,
https://stratoflow.com/best-ai-coding-tools/
And how to use chatGPT for coding,
https://medium.com/@tanyamarleytsui/cod ... 0ab3fcb45f
caseih
Posts: 2157
Joined: Feb 26, 2007 5:32

Re: Free ChatGPT

Post by caseih »

If code-generation AIs had access to real compilers to run their code through, and a little bit of testing smarts, then I'd rely on AI more in programming.

The only time I've tried asking ChatGPT about some code in FreeBASIC (I asked about using GTK+ 3.x in FB), it happily generated some code for me that was looked pretty good but wouldn't compile. Used some things that weren't defined like NULLPTR or something. I pointed that out to it and it promised to fix it but just spit out the same code again. After three times telling it it still was not right, it finally said if I was going to be short with it, it would not talk to me about this any longer. Pretty funny.

But for summarizing an algorithm or technique with a couple examples, AI does pretty well.
hhr
Posts: 211
Joined: Nov 29, 2019 10:41

Re: Free ChatGPT

Post by hhr »

in DeepAI I typed in:
'Tell me how to round numbers, in freebasic please'
:mrgreen:
Then I typed in:
'Tell me how to round numbers'
and got the answer:

Code: Select all

To round numbers, follow these steps:
    Determine the place value you want to round to (e.g., nearest whole number, nearest tenth, nearest hundred).
    Look at the digit to the right of the desired place value. 
    If the digit is 5 or greater, round up by adding 1 to the desired place value. If the digit is less than 5, simply keep the desired place value the same.
    If there are any digits to the right of the desired place value, replace them with zeros.
    If you round up and the number ends in all zeros, carry the 1 to the next digit to the left.
For example:
    To round 3.56 to the nearest whole number, you would round up to 4.
    To round 7.89 to the nearest tenth, you would round up to 7.9.
    To round 1245 to the nearest hundred, you would round up to 1300.
Remember, rounding is used to make numbers easier to work with and to simplify calculations.
neil
Posts: 594
Joined: Mar 17, 2022 23:26

Re: Free ChatGPT

Post by neil »

Here's a deepai-generated Sodoku solver. I had to send the compiler error codes back six times for debugging to Deepai.
But hey, it finally worked.

Code: Select all

' Define the size of the Sudoku grid
const N = 9

' Declare the Sudoku grid as a shared array
dim shared grid(N, N) as integer

' Function to print the Sudoku grid
sub printGrid()
    dim i as integer, j as integer
    ' Loop through each row and column and print the cell value
    for i = 0 to N-1
        for j = 0 to N-1
            print grid(i, j);
        next j
        print ""
    next i
end sub

' Function to check if a number is safe to place in a cell
function isSafe(row as integer, col as integer, num as integer) as integer
    dim i as integer, j as integer
    ' Check if the number is already present in the row
    for i = 0 to N-1
        if grid(row, i) = num then
            return 0
        end if
    next i
    ' Check if the number is already present in the column
    for i = 0 to N-1
        if grid(i, col) = num then
            return 0
        end if
    next i
    ' Check if the number is already present in the 3x3 grid
    dim startRow as integer = row - row mod 3
    dim startCol as integer = col - col mod 3
    for i = 0 to 2
        for j = 0 to 2
            if grid(startRow + i, startCol + j) = num then
                return 0
            end if
        next j
    next i
    ' If the number is not present in the row, column or 3x3 grid, it is safe to place in the cell
    return 1
end function

' Function to solve the Sudoku puzzle using backtracking
function solveSudoku() as integer
    dim row as integer, col as integer, num as integer
    ' Find the next empty cell
    for row = 0 to N-1
        for col = 0 to N-1
            if grid(row, col) = 0 then
                ' Try each number from 1 to 9 in the empty cell
                for num = 1 to 9
                    if isSafe(row, col, num) then
                        ' If the number is safe to place in the cell, place it
                        grid(row, col) = num
                        ' Recur to fill the rest of the empty cells
                        if solveSudoku() then
                            return 1
                        end if
                        ' If the recursion leads to a dead end, backtrack and try the next number
                        grid(row, col) = 0
                    end if
                next num
                ' If no number works in the cell, backtrack and try a different number in the previous cell
                return 0
            end if
        next col
    next row
    ' If there are no empty cells, the puzzle is solved
    return 1
end function

' Set the initial values in the Sudoku grid
grid(0, 0) = 5
grid(0, 1) = 3
grid(0, 4) = 7
grid(1, 0) = 6
grid(1, 3) = 1
grid(1, 4) = 9
grid(1, 5) = 5
grid(2, 1) = 9
grid(2, 2) = 8
grid(2, 7) = 6
grid(3, 0) = 8
grid(3, 4) = 6
grid(3, 8) = 3
grid(4, 0) = 4
grid(4, 3) = 8
grid(4, 5) = 3
grid(4, 8) = 1
grid(5, 0) = 7
grid(5, 4) = 2
grid(5, 8) = 6
grid(6, 1) = 6
grid(6, 6) = 2
grid(6, 7) = 8
grid(7, 3) = 4
grid(7, 4) = 1
grid(7, 5) = 9
grid(7, 8) = 5
grid(8, 4) = 8
grid(8, 7) = 7
grid(8, 8) = 9

' Solve the Sudoku puzzle
if solveSudoku() then
    ' If the puzzle is solved, print the solution
    printGrid()
else
    ' If the puzzle cannot be solved, print an error message
    print "Unable to solve Sudoku puzzle"
end if

sleep
neil
Posts: 594
Joined: Mar 17, 2022 23:26

Re: Free ChatGPT

Post by neil »

I asked DeepAI for a rotating 3D cylinder, and here's what I got.

Code: Select all

screenres 800, 600, 32
Const screenwidth = 800
Const screenheight = 600
Dim Shared As Double pi = 3.14159
Dim As Double angle = 0
Dim As Integer centerX = ScreenWidth \ 2
Dim As Integer centerY = ScreenHeight \ 2
Dim As Double radius = 100
Dim As Double height = 200
Dim As Double x, y

Do
    Screenlock
    Cls
    
    For i As Double = 0 To 2 * pi Step pi / 10
        x = centerX + radius * Cos(i + angle)
        y = centerY + radius * Sin(i + angle)
        Line(centerX, centerY)-(x, y), RGB(255, 255, 255)
        Line(x, y)-(x, y + height), RGB(255, 255, 255)
    Next
    
    angle += 0.01
    Screenunlock
    Sleep 10
Loop Until Inkey <> ""
Post Reply