The Challenge and Journey of Building OMM
As a young chess player, I was always fascinated by the calculated nature of chess. The game’s infinite possibilities intrigued me and I always wondered how I could find a way to calculate the best possible move at all times. As I got older, I grew interested in coding and AI, and I wanted to find a way to combine all of my different passions while also helping me encourage others to improve at chess. Thus, the idea for Opening Move Mentor (OMM) was born.
Though my idea for OMM was clear—a chess AI bot that would evaluate the best possible chess opening in any given situation—I wasn’t entirely set on how I would be able to actually turn this idea into reality. After spending countless hours researching, I decided to create OMM using a mini-max algorithm, which would evaluate each possible move on the board and what it could lead to in the future. One month later, I finally finished it!
However, I quickly came to the heartbreaking realization that OMM ran far too slowly—the results, while accurate, were sometimes only displayed after several long minutes. I quickly backtracked and discovered that the slow speed was the result of coding my AI using a mini-max algorithm. While effective for simple games like tic-tac-toe, a mini-max algorithm has to filter through every move possible—for both sides of the chessboard—and then evaluate the effectiveness of each move stacked against the next move. With a game like chess, the possibilities and combinations are endless. In other words, I knew I had to find a way to limit the number of moves being evaluated and displayed.
Immediately, I scoured the Internet for ways to make Opening Move Mentor faster, and found that many mini-max algorithms use alpha-beta pruning. Since mini-max algorithms create so many different branches of combinations, alpha-beta pruning works by “pruning” irrelevant branches. With a clear goal in mind, I got to work implementing alpha-beta pruning in OMM!
A month later, I was successful…but not quite as successful as I’d hoped. OMM was running more quickly with alpha-beta pruning, but it still took minutes rather than seconds. Frustrated, I briefly thought about restarting the entire project from scratch to fix OMM’s run-time issues. After calming down and thinking it through, however, I went back to the basics of what chess had taught me—running through multiple different options before deciding on the best possible move. I went back to the drawing board and researched multiple different methods of speeding up OMM’s run-time, rather than just settling on the first and most popular method. Between using Principal Variation Search (a directional search algorithm for finding a mini-max value, which was an even faster version of alpha-beta pruning) and using bits (which would allow me to store large amounts of data in one place and later access the data much more efficiently), I found that the latter would be the most optimal solution.
Learning to use bits and bitwise operations for OMM required me to start from scratch as I had no prior experience using them. I had to spend a month first researching how to use bits before I could start with the basics of creating a board in binary and then move to more advanced operations like calculating the possible moves and keeping track of the various chess rules in binary. Finally, I created an algorithm to help calculate the best moves, bringing all of my code together. However, again, I faced a larger problem of constant bugs in the games where pieces randomly appeared due to the way the bits stored the data.
Frustration once again set in as I felt like my hard work had gone to waste. However, rather than giving up, I once again decided to persevere and work to overcome this challenge. I pivoted to using React Native and Stockfish, and I was successfully able to clean up the bot’s interface so that players could test different moves against each other.. Yet my job wasn’t done; I still wanted to be able to include a functionality that allowed users to predict the best move they could play in a certain situation. After spending more time coding, I was finally able to implement this functionality, and I could breathe a sigh of relief as all of my hard work and countless hours coding paid off. In the future, I hope to add additional functions such as being able to see the evaluation of the game in real-time while playing against the chess bot.
As fall 2024 starts, we hope to utilize OMM at various schools and chess communities within the Bay Area through our Chess Opening Mentorship Program (COMP). Our goal is to help as many people as possible develop a passion for chess through interacting with our website and AI.