Code Architecture

Code Module

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?

How it Works
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.

Grid Strategy
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?

Machine Learning

Machine Learning

There are 4 Neural Nets that influence the actions of the player. Each one serves a specific purpose to give the AI some logic:

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.