Game AI: Student Project Dives Into Machine Learning

We’ve seen some impressive projects come out of the four-day sprint dubbed Project Week at Code Fellows. From online drum kits to Google Street View on Mars, we’re continually amazed by what students create in just one week.

A project group in a recent Python cohort decided to test their abilities in machine learning—for their final project, they built a neural network and series of algorithms that improved the computer’s ability to play Tic Tac Toe.

The team was made up of five Code 401 students studying Python—Erik Enderlein, Sean Beseler, Ely Paysinger, Chris Hudson, and Alex Short.

Inspiration for the project came from Erik Enderlein’s connection with a Google employee. He asked what would stand out to recruiters at such a high-profile tech company. The answer? Anything related to machine learning. Build something that showcased that kind of knowledge on your resume, and recruiters would be more likely to take notice. The team—all of whom were already intrigued by artificial intelligence—were on board.

How Game AI Works

Machine learning functions similarly to artificial selection in biology—the best or most desirable traits are chosen to use in the next generation.

The neural network is the part of the program that chooses a specific tic tac toe move. The genetic algorithm is made of up many neural networks, testing different moves and outcomes. A neural network’s performance is determined based on several factors, including its performance compared to other neural networks. The best-performing neural network (i.e. move in the game) is duplicated and minor mutations are added to the next generation to continue to test and improve the performance of the neural networks.

To produce a neural network that could adequately compete against a human at Tic Tac Toe, this genetic algorithm had to produce close to a hundred thousand generations. Once the team reached that many iterations, the artificial intelligence was ready to be stored on the backend of their program and compete with a human through a web interface.

The Biggest Challenge

Erik, who worked on both the neural network and genetic code, was surprised by the number of generations required to produce an AI that could adequately challenge a human at Tic Tac Toe. “I expected the networks to be proficient at playing versus a human at Tic Tac Toe after 500-1000 generations. But we were looking more at 100,000-1,000,000 for human competition. I had no clue that they would plateau so intensely, and for so long.”

If this genetic algorithm was going to learn as it played humans online, it needed to learn how to improve its skill level at a much faster rate than 100K iterations. While several members of the team were surprised that training an AI for a specific task was relatively simple, training it to learn based on its environment (essentially, its competitor’s moves in the game) was a much bigger task.

The Payoff

Projects that push students into new territory of learning and technology often come with additional roadblocks, but also greater rewards and sense of accomplishment when they get the project working.

“I believe it was day two when we first achieved some semblance of code progress on the AI,” Alex Short said. “Before there was a lot of ‘aha’ moments on how to get it to work, but it was mostly just theoretical understanding. It was great feeling seeing our AI come online for the first time.”

How You Can Get Started in AI

To learn more about this project, fork the repo on GitHub! Get started in artificial intelligence with the videos below.



Want to add programming to your skill set? Learn more about Code 401: Advanced Software Development in Python »

Next PostPrevious Post

About the Author