Genetic Algorithm Tank AI
- itzvnodm
- Dec 19, 2014
- 2 min read
1. Created a "Tanks collects the mines" game.
a. Player control the tank using independent 'left tread' and 'right tread' controls. Key Q: Left tread forward, key A: Left tread reverse, key W: Right tread forward, key S: Right tread reverse. So to move forward, the player must press both Q and W simultaneously. Pressing only Q should send the tank into a clockwise circle. Pressing both W and A should cause the tank to spin counter-clockwise in place without moving.
b. Randomly populated the world with mines (45). When the tank collects one, respawns it randomly somewhere else.
c. The map wraps at the edges. If the tank goes off the left side of the screen, it reappears on the right side.
d. The game lasts 30 seconds, drive the tank over mines to collect them. Player tries to collect as many as possible within the time limit.
e. Provided HUD elements for the player's current score, the time remaining.
2. Implementd AI opponents. (20)
a. The AI only has two states: Wandering to find a mine and Seeking towards a found mine.
b. The AI has a limited vision radius where it can "see" mines. 4 vision cones, one for each direction: front, back, left, right, each with it's own radius.
c. AI Chooses one of the visible mines as a target. Calculates the angle to the mine relative to the facing direction of the tank, then apply some speed to each tread (forward or reverse) to attempt to steer towards the mine.
d. The scoreboard at the end of the game now reflects the performance of every tank, including the player.
3. Implemenetd a genetic algorithm to improve the tank AI
a. "Weights" of the tank are: The vision radius (Left, Right, Front and Back), the left and right tread speeds, Vision Angle (Left, Right, Back Front).
b. When the game initially starts, all the weights for each AI are randomized.
c. After each round, the genetic algorithm on the population,
d. Implemented 2 fitness functions: Allowed user to select which fitness they want at game start.
i. Most number of mines collected.
ii. Closest match to player score.
"It was supposed to be Tanks but turned out to be spaceship controls after letting them evolve through genetic algorithm overnight."
Comments