Code Architecture
Our code consists of two main components
* Main Game Loop (Game.py)
The main game loop runs the Bomberman game, implemented with pygame in a typical Model View Controller(MVC) pattern. The original game was written by a Github user rickyc.
We have made modifications to the original code to incorporate additional machine learning features.
* Machine Learning Module (FeatureExtract.py, FeatureConvert.py, NNClass.py)
The machine learning module consists of a Feature Extraction class and a Neural Network class. Both of these classes are designed so that they function directly within the main gale loop. We did not implement any aspects of concurrency programming because the training of the neural network does not happen simultaneously with the prediction of neural network. The training method runs only when the user is playing the game manually; the prediction method runs only when the user has activated the auto mode.
How Does Feature Extraction Work?
Using the pygame’s board object which uses a more basic numbering system for each kind of tile, we created our own grid object that uses more specific numbering system (0~9) to represent all the unique objects on the grid. Then the grid is saved as a .csv file at a fixed frequency.
Additionally, we’ve attached imaginary walls(that represent the area outside the visible grid) to the basic grid. These extended walls automatically relocated themselves within the matrix relative to the player’s movement, for such extra implementation of the matrix allows us to always keep the player(number 8 on our grid) at the center of the matrix. This forced condition greatly cuts down the computation needed because it allows the neural network to constantly access the grid information “surrounding the player”.
How Do We Build the Neural Network?
-
While the game is running in manual mode, the neural network class takes the extracted feature data(generated by human input) and constructs a neural network for future prediction.
-
While the game is running in AI mode, it receives live features and predicts the movement with the saved data.
There are 4 Neural Nets that influence the actions of the player. Each one serves a specific purpose to give the AI some logic:
- Walls-This net is designed to tell the AI which moves are valid(e.g. if a wall is to the left, left is an invalid move). Additionally, it will provide some logic telling the AI to go down longer paths rather than dead ends
- Bricks-This net will tell the AI to seek out and destroy bricks. Its main purpose is to tell when to place bombs depending on proximity to bricks
- Bombs-The job of this net is to tell the AI when to run away from bombs.
- Enemies-This net is the most experimental, it directs how the AI will act around enemies. It will try to direct the AI to go up to enemies, place bombs, and run away without running into them
The weight, or how much influence each of these categories has on the final decision varies based on the scenario. For example. when a bomb is nearby, movements to protect the player becomes a higher priority than destroying bricks.