Hacker News new | past | comments | ask | show | jobs | submit login
Ask HN: AI Wars – control your 2d space shooter with AI
8 points by thepromptgenius 49 days ago | hide | past | favorite | 6 comments
I've been trying to get around to building a game that allows players to control their characters using AI scripts. So essentially, you don't control your character, but instead the AI controls your character, you just design the AI.

I finally have a prototype up and running, its a 2d space shooter that allows you to program your ship using a simply ChatGPT-like AI prompt.

As a player, all you need to do is give a prompt just like you would with ChatGPT. So for example the prompt I used to program my ship was:

Play aggressively when score is low, become more defensive as score increases

The game then automatically converts this to code that is used to control your ship, in my case it was:

loadPlayerAI(` const score = ai.getScore(); const aggressiveThreshold = 1000; // Adjust as needed const nearestEnemy = ai.getNearestEnemy();

    if (score < aggressiveThreshold) {
        // Aggressive play
        if (nearestEnemy) {
            ai.moveTo(nearestEnemy.x);
            ai.fire();
        } else {
            const screenDims = ai.getScreenDimensions();
            ai.moveTo(screenDims.width / 2);
        }
    } else {
        // Defensive play
        const safeZone = ai.findSafeZone();
        ai.moveTo(safeZone);
        
        if (nearestEnemy && ai.isEnemyInFrontAndRange(nearestEnemy)) {
            if (ai.calculateDistance(ai.getPlayerPosition(), nearestEnemy) > 100) {
                ai.fire();
            }
        }
    }
`);

The ship then automatically moves around shooting down enemy ships, once a collision between you and the enemy ship happens its game over. Number of enemy ships keeps increasing as your score increases which makes it hard to last long without a good prompt. The game now accepts any kind of prompt that you provide and translates it to valid code which runs your ship in the game environment.

I was thinking to develop this further into a tournament/competition where players provide their scripts, and their ships will compete to see who scores the highest (max time limit is 1 minute of play time if your ship can last that long). Ships compete and the best prompt/program wins!

Would anyone be interested to try it out as a player? I just need a prompt and I will load it into your spaceship, I'll share a link where you can see it in action

Below is the "framework" that describes the capabilities available to the ship. You don't need to mention these explicitly in your script, the game engine translates your prompt to code based on these capabilities so for example if your prompt says when surrounded by 10 enemy ships find a safe spot it will probably use functions like `countNearbyEnemies()` and `findSafeZone()` in the code it outputs.

>>>AI Wars - Framework (couldn't add all of it due to character limit on HN)

>Sensing

getNearestEnemy(): Returns the closest enemy object getAllEnemies(): Returns an array of all enemies on screen getPlayerPosition(): Returns the current position of the player's ship getScreenDimensions(): Returns the dimensions of the game screen

>Movement

moveLeft(speed): Move the ship left at the specified speed moveRight(speed): Move the ship right at the specified speed moveTo(x): Move the ship to a specific x-coordinate

>Combat

fire(): Shoot a missile (subject to cooldown) getWeaponCooldown(): Returns the current weapon cooldown status

>Utility calculateDistance(obj1, obj2): Calculate the distance between two objects predictEnemyPosition(enemy, time): Predict where an enemy will be after a given time countNearbyEnemies(): Calculates the number of nearby enemies within 30% of the screen width

>Decision Making

shouldDodge(enemy): Determines if the ship should dodge a specific enemy isEnemyInFrontAndRange(enemy): Checks if an enemy is directly in front and within firing range

.. truncated




For the long history of such games (where people actually wrote the rather simple AI code for their avatar), take a look at RobotWar and its various later clones like C-Robots and Omega.

https://en.wikipedia.org/wiki/RobotWar


thanks! I didn't know about Robotwar and its fascinating, I just wanted to democratize this through normal english prompts, so anyone regardless of their coding ability can participate. Tbh this has been a dream of mine since childhood but I never had the ability to execute until the dawn of Cursor, Claude, and v0 :)


I love the idea of having an AI prompt to write code for the bots. There are already games like https://screeps.com/ or https://store.steampowered.com/app/2060160/The_Farmer_Was_Re... where you program your bot to do things, but they do require some minimal coding experience. Being able to describe behavior in plain english would be pretty cool.

However, I think having real-time feedback is a huge part of games like this. You try a command or two, see what unexpected thing happens, rapidly iterate and try again, one step at a time. Having to submit every prompt revision to you (even for testing) makes it hard to iterate. Any chance you'd want to build a thin web wrapper over it so players can sign up and try it on their own?


you're right, i'm working on it now and will share it as soon as its done. you will be able to just write your prompt and test it live (load it into your ship and see it in action!)


FYI there is already a tower defense game series called AI War on Steam. It doesn't use code, but the name is similar enough to be confusing. https://store.steampowered.com/app/573410/AI_War_2/


thanks for the note! I didn't know about this game tbf, I don't have a name yet for the project. It just started out as a 2d space shooter, and evolved as an AI controlled game




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: