PyGame: Let’s beat the machine learning model

PyGame: Let’s beat the machine learning model

Today, this week we will be doing a fun activity as we always do but this time we will try to beat the machine learning model. Wait, what!!! Can it be possible?? I don’t know the answer to the question.๐Ÿ˜ฌ But this is the competition between us and the machine learning model. Let’s start setting things up.๐Ÿ˜๐Ÿ˜Ž

Installation

After installing the requirements, we will be playing the game against the machine. Have you heard of the game FlappyBird Game? Flappy Bird game is similar to Mario forever game in which we have to fly the bird as far as we can without hitting a pipe. So I have created two versions of the game. One is the human version and the other is the machine learning model version. So we will install both versions on our machine.

Download and extract the human version and machine version of the game in your machine. On one side we will be running the human version game and on another side, we will start the machine game. ๐ŸคŸ

Human Version

The human version game is created using the Pygame. Pygame is a cross-platform set of Python modules designed for writing video games. It includes computer graphics and sound libraries designed to be used with the Python programming language. To run the human version, navigate to the root folder. Type the following command.

python flappy.py

Machine Version

The backend of the machine version is running on the deep learning model. There are three convolutional layers and two fully connected layers. Each layer uses ReLU activation, except the last one, which uses linear activation. The neural network outputs two values representing the playerโ€™s only possible actions: โ€œFly upโ€ and โ€œdo nothing.โ€ The input consists of four consecutive 84×84 black-and-white images.ย The neural network architecture is the same as DeepMind used in the paper Human-level control through deep reinforcement learning. To refer more, one can visit this article. To run the machine version, navigate to the root folder. Type the following command.

python deep_q_network.py

Keep running one side of the machine version and let’s play the human version game. See where we can beat the machine version game. I’ll deploy the code to the sandbox library public machine. So if you face trouble in running the game then you can book the public machine and enjoy playing the game. ๐Ÿค™๐Ÿ˜Ž๐Ÿ˜‹