Pong's the debut game of almost every programmer aspiring to be a game developer. This weekend I wanted to test my coding skills by creating a Pong game and an AI agent that is at par to its human opponent. The primary goal was to build an AI that mimics human behaviour well and doesn't frustrate the players and give them a fair chance at winning.

What it does

It's a retro-styled pong game that has 4 modes - Single Player - Players can hone the skills needed to play the game.
Multiplayer - 2 Players can put their skills to test and find out who's the best
AI Mode- Players can find out whether they are better than their computers at pong.

How I built it

The entire code has been written in C++ by leveraging the Simple DirectMedia Layer(SDL) library. Multiple AI agent algorithms have been implemented such as the ball tracking algorithm and the prediction algorithm.

Challenges I ran into

I built the whole game from scratch so I faced challenges working with the game loop. As I have no previous experience in game programming I faced several issues like fps variation which I solved by using the deta time concept and double buffering. Making the AI agent was complex as the goal of game AI is to not make perfect AI but human-like AI. Ones that seem natural to play with and the user shouldn't feel that the agent has more advantage than him. So the task was to make the AI simulate human behaviour and that was hard but I solved it using the ball tracking algorithm.

Accomplishments that I'm proud of

AI works well - The agent mimics human behaviour pretty well. The algorithm ensures it has no advantage over the human player and has to play the game by analyzing ball movement and predicting the positions just like humans do.
Made my first 2D game - Learned a lot of concepts like double buffering, synchronization, the usage of delta time, game loops etc.

What's next for AI Plays Pong

Better mimicing of human behaviour - The agent is good at what it does but I wonder how to make it better without any major tradeoff in terms of complexity and memory?

Built With

Share this project: