I used ChatGPT

General discussion about LÖVE, Lua, game development, puns, and unicorns.
User avatar
Bobble68
Party member
Posts: 162
Joined: Wed Nov 30, 2022 9:16 pm
Contact:

Re: I used ChatGPT

Post by Bobble68 »

Bobble68 wrote: Tue Dec 26, 2023 5:41 pm I'm curious what it would be like to completely get ChatGPT to create a game in love2d - would probably need some level of automation though, so that you can automatically disregard generated code that throws errors.

Edit: Screw it I'm gonna try it
I am... surprised that it actually did it. I wonder who's code it copied :monocle:


Here's the prompt I gave it:

Come up with a concept for a very simple game that can be programmed in Love2D. Another AI will be tasked of creating this game, so you must create a list of every task that must be completed for the AI to follow.

I then took part of the response, then gave it back to a different conversation (not all of the response was really relevant, though it would be funny to tell chatgpt to "Test the game thoroughly to identify and fix any bugs"

Code: Select all

-- main.lua

function love.load()
    -- Set up the game window
    love.window.setTitle("Space Dodge")
    screenWidth, screenHeight = 800, 600
    love.window.setMode(screenWidth, screenHeight)

    -- Initialize game variables
    player = { x = screenWidth / 2, y = screenHeight - 50, speed = 300, width = 50, height = 50 }
    asteroids = {}
    score = 0
    gameover = false
end

function love.update(dt)
    if not gameover then
        -- Move the player
        if love.keyboard.isDown("left") and player.x > 0 then
            player.x = player.x - player.speed * dt
        elseif love.keyboard.isDown("right") and player.x < screenWidth - player.width then
            player.x = player.x + player.speed * dt
        end

        -- Update asteroids
        updateAsteroids(dt)

        -- Check for collisions
        checkCollisions()

        -- Update score
        score = score + 1
    end
end

function love.draw()
    -- Draw player
    love.graphics.rectangle("fill", player.x, player.y, player.width, player.height)

    -- Draw asteroids
    for _, asteroid in ipairs(asteroids) do
        love.graphics.circle("fill", asteroid.x, asteroid.y, asteroid.radius)
    end

    -- Draw score
    love.graphics.print("Score: " .. score, 10, 10)

    -- Draw game over screen
    if gameover then
        love.graphics.print("Game Over", screenWidth / 2 - 50, screenHeight / 2 - 30)
        love.graphics.print("Score: " .. score, screenWidth / 2 - 40, screenHeight / 2)
        love.graphics.print("Press R to Try Again", screenWidth / 2 - 70, screenHeight / 2 + 30)
    end
end


function spawnAsteroid()
    local asteroid = {
        x = math.random(screenWidth),
        y = -20,
        radius = math.random(20, 40),
        speed = math.random(50, 150)
    }
    table.insert(asteroids, asteroid)
end

function updateAsteroids(dt)
    for i, asteroid in ipairs(asteroids) do
        asteroid.y = asteroid.y + asteroid.speed * dt

        -- Remove asteroids that are out of the screen
        if asteroid.y > screenHeight then
            table.remove(asteroids, i)
            spawnAsteroid()
        end
    end

    -- Spawn a new asteroid with a chance
    if math.random() < 0.01 then
        spawnAsteroid()
    end
end


function checkCollisions()
    for _, asteroid in ipairs(asteroids) do
        if checkCollision(player, asteroid) then
            gameover = true
        end
    end
end

function checkCollision(a, b)
    return a.x < b.x + b.radius and
           a.x + a.width > b.x and
           a.y < b.y + b.radius and
           a.y + a.height > b.y
end


function love.keypressed(key)
    if gameover and key == "r" then
        love.load() -- Reset the game
    end
end
It's obviously not very good, but it does actually run and work as a game.

Potential follow up - completely automate the process then start bemoaning on twitter how no one considers this an artistic skill.

Edit: I tried asking it to create a game from a single prompt, and it generated a catching game instead, with the reverse premise
Last edited by Bobble68 on Tue Dec 26, 2023 9:10 pm, edited 1 time in total.
Dragon
User avatar
kingnoob
Prole
Posts: 29
Joined: Thu Dec 21, 2023 6:52 am

Re: I used ChatGPT

Post by kingnoob »

Bobble68 wrote: Tue Dec 26, 2023 6:10 pm
Bobble68 wrote: Tue Dec 26, 2023 5:41 pm I'm curious what it would be like to completely get ChatGPT to create a game in love2d - would probably need some level of automation though, so that you can automatically disregard generated code that throws errors.

Edit: Screw it I'm gonna try it
I am... surprised that it actually did it.

It's obviously not very good, but it does actually run and work as a game.
It is still amazing especially when ten years hence they will have something magnitudes better.
User avatar
milon
Party member
Posts: 472
Joined: Thu Jan 18, 2018 9:14 pm

Re: I used ChatGPT

Post by milon »

Please remember that ChatGPT (etc) is not an AI at all - it's just an algorithm that's really REALLY good at inferring what sort of output to create based on the input give and the enormous (stolen?) trained data sets. It fails miserably when presented with new or unorthodox situations.

(Crawls back under his rock.)
Any code samples/ideas by me should be considered Public Domain (no attribution needed) license unless otherwise stated.
User avatar
Bobble68
Party member
Posts: 162
Joined: Wed Nov 30, 2022 9:16 pm
Contact:

Re: I used ChatGPT

Post by Bobble68 »

milon wrote: Thu Dec 28, 2023 4:18 pm Please remember that ChatGPT (etc) is not an AI at all
Tbh AI has always been a bit of a vague term anyway, probably because intelligence is also poorly defined. I'll try to avoid getting philosophical, though I would like to point out that much stupider programs have been considered as AI (e.i. npcs in games).
Dragon
User avatar
zorg
Party member
Posts: 3468
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: I used ChatGPT

Post by zorg »

Also might have had to do with marketing departments trying to push the term because it was *the* current hot thing.

And it'd probably be wise to use different terms if one would want to implement multiple types of NPC behaviour in games... "behaviour" being one term, but it could have multiple types, like hard-coded/"scripted", or even neural net-based (one that's small enough to run in real time, that is), or whatever. :3
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
User avatar
knorke
Party member
Posts: 274
Joined: Wed Jul 14, 2010 7:06 pm
Contact:

Re: I used ChatGPT

Post by knorke »

love.window.setTitle("Space Dodge")
googling for that name brings up several git repos and tutorials with that same name. Some use Pygame, some use Lua.
CopyGPT!
User avatar
Bobble68
Party member
Posts: 162
Joined: Wed Nov 30, 2022 9:16 pm
Contact:

Re: I used ChatGPT

Post by Bobble68 »

knorke wrote: Sun Jan 07, 2024 6:35 pm
love.window.setTitle("Space Dodge")
googling for that name brings up several git repos and tutorials with that same name. Some use Pygame, some use Lua.
CopyGPT!
CopyGPT? Ok!

Hello there human do you mind if I learn from your work thanks ok by.
Dragon
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 4 guests