2D space shooter game in JS with similar functionality to old arcade style shooters. The player controls a ship that can shoot, activate shields and fly. The game world consists of empty space, particles and eventually asteroids passing by. When a player is hit by an asteroid, the shield will disable. Particles cause no harm.
- Compare coordinates of game entities (pivot/center x-coordinate, e.g. pixels)
- Clarify the class of the comparable entity (e.g. asteroid, particle)
- AI checking would be triggered by game, once relevant entities are in scene (simple math)
If both match, the game will trigger another game mechanic that is not specified here (e.g. audio-visual alert, evade flight path, shoot).
Input | Meaning |
---|---|
category | ASTEROID / PARTICLE |
pos_x_item | number |
pos_x_player | number |
For this scenario, the only relevant situation is an asteroid being on the same flight path as the space ship, as a collision can occur.
EXPECT | category | pos_x_item | pos_x_player |
---|---|---|---|
true |
ASTEROID | 100 | 100 |
false |
ASTEROID | 0 | 100 |
false |
ASTEROID | 100 | 0 |
false |
PARTICLE | 100 | 100 |
false |
PARTICLE | 0 | 100 |
false |
PARTICLE | 100 | 0 |
true |
PARTICLE | 0 | 0 |
- Build a custom working micro AI as fast as possible (1 day POC)
- AI must be able to predict the desired value closely
Portability to JS: Can be done via model export/conversion, only partly covered here.
- The author has up to no experience in AI, python, tensorflow, keras concepts
- All code is generated by ChatGPT 4
- A base template (AI tutorial of Breaking Lab) is used
- Research and learning is kept to absolute minimum, ignoring any deeper understanding intentionally
However, it could be made to work, if the game employed features that allowed dynamic generation of training data for reward/punishment functions. This data then could be used to generate a more complex model, which then is backfed in the game.
This can be solved by game-only mechanisms without AI:
- Make algorithm better if the full hit box of item (x, y; size) is considered Also, consider ship speed (can it even evade in short time?).
- Change decision if also enemy ship is in scene (new layer of complexity), as risk of being hit by asteroid and losing shield, and then being shot by the enemy is maybe not acceptable
- Allow use of AI only with certain advanced equipment players get later
- AI models could have stages, e.g. beginner/cheap ones have access to less data or 'sensors' in the game, e.g. just coordinates; while later ones also know about other entities like enemies in game, speeds, actions being taken ...
AI beneficial:
- AI learning/knowledge based on game features not engine knowledge. Act as if the AI is like a virtual player: They don't know the math, but learn about correlation between things to happen. Maybe it discovers over time: -- If there are asteroids, the likeliness of enemies also raises. -- If asteroid is coming close to player, they will be hit due to bad flying skills or slow reactions. So the suggested action will be evasion. -- Tactics to defeat/shoot sth. (e.g. what works, what not)
- Any user-based decisions or input, that are not possible to calculate by math. Example: Item speeds and positions are known, but not the players decisions with these or their reaction times to even take any action. -- If a player acts too slow to evade sth., they will be hit (no reward), but if they evade and it is close, they might get a reward.
- Give a reward score if players evade asteroids closely before hit (not far away, which would be easier). Input: Reward score (Factor), Ship coordinate, Asteroid coordinate -- Game effect: Suggest move paths (stay vs. evade), visually
- NPCs/Game self: Monitor player (inverse perspective, not from player but about them). If they often miss hits, waste ammo, fly too risky, ... adjust the game settings. -- "Correlations of events not just the pure event itself (too easy, math ok). If players do X while Y, then Z should happen more often."
- Frequency of events occuring, e.g. find out how often certain things happen, enemies appear in the scene, ... and pre-cognitive alert players to take care
- Reward functions are not immediate and likely over time, e.g. an action has started, a sequence of things happen, then an outcome is decided and fed to the data pool. How is that determined?
- How to prevent too much data from being collected, e.g. a massive array that takes too much RAM / MB and CPU load? Maybe there should be a cap of data entries. Or something like duplicate avoidance (risk to taint data frequency).
- Define a few outcomes/strategies and think backwards: The AI needs to learn/solve the problem of ... and figure out how (being given tailored data)
- If possible, let it completely train via JS/frontend
- This might be slow/blocking, so it could be done server-side, via webworkers, sockets, ...
- Alternatively, let the AI progressively improve by artificially slowing down the epochs to train with (1, 2, 10, 100, ...) -- So the first AI predictions will be very bad in game and player needs to collect more data -- Also training data could be accummulated and fed part by part into algorithm