Fish AI Game
For the "Games and AI Techniques subject" at RMIT, I worked with one other student on an AI-focussed game that we designed based on the AI techniques we were required to demonstrate.
The game we ended up creating involves:
- The player controls a single fish that can change its colour at will
- Fish of the same colour will exhibit boid-like flocking behaviours
- "Hungry" fish will perform predator behaviours, roaming and pathfinding to prey if within range
- The player must guide two flocks of fish to their respective "safe zones" before they get eaten by predator fish
I was responsible for implementing the pathfinding algorithm for the "hungry" fish (while they are roaming). The course material was mostly around 2D pathfinding algorithms and node structures - which had to be modified and extended to be relevant to our playspace which was not only visually 3D, but actually navigable in all 3 dimesions which required some extra time spent on how to connect nodes and weight them considering distance travelled on diagonals vs. cardinal directions.
I was also responsible for the 3D node grid creation system. This involved dealing with a playspace that was arbitrarily shaped (based on a 3D mesh file created for the level). This involved:
- Creating the initial node generation/connection script for a n x n x n sized grid
- Making the node grid scalable such that you could control the "resolution" of the pathfinding node system
- Calculating which nodes were permanently outside of the play space and deleting them
- Dealing with dynamically moving obstacles and temporarily disabling nodes based on moving obstacles
- Finding a solution for obstacles that were thinner than the resolution of the grid (resulting in two validly active nodes but an invalid path between them)
I also spent a considerable amount of time improving the rotation/orientation of the AI fish such that they are self-righting and will always swim the correct way up - even when navigating between nodes that would ordinarily leave them swimming upside down. There was some very annoying quaternions and dot/cross product calculations involved.
We extended the game during the semester, using Machine Learning to train an AI fish to play our game - this involved:
- Setting up the ML-agents Toolkit within Unity
- Parameterising our game mechanics such that we could implement deep reinforcement learning
- Setting up an initial 2D test fish and adding perception rays for observation data
- Deciding on reward parameters and values
- Creating training environments and running testing
- Converting our 2D fish's perception ray configuration to 3D
- Recreating training environments and rewards for 3D
We were quite ambitious with our goals for training, and although we didn't reach a state where the AI could play the full game system, we did get our fish to collect other fish and return them to the safe area semi-consistently.