MegaMax Tic-Tac-Toe

MegaMax Tic-Tac-Toe

I went above and beyond for my first assignment at GA, creating MegaMax, named for the minimax decision-tree algorithm & the ‘mega’ 5x5 game mode it offers.

My First Project

Our first assigned project at the General Assembly software engineering program was to develop a tic-tac-toe application that connected to an authentication API created by GA. I went above and beyond by implementing all the requirements, in addition to creating a game mode allowing users to play against the computer that was initially powered by my JavaScript implementation of the minimax decision-tree algorithm and the alpha-beta pruning method running on the client’s computer.

Upgrade

More recently, I decided to upgrade MegaMax to better reflect my fast-growing skillset. I re-wrote the client entirely in TypeScript and using React. For the 3x3 mode, I kept my JavaScript implementation running on the client side, as the number of possible moves is small enough to be instantly analyzed by any computer. For the 5x5 mode, however, my initial version of MegaMax would often lag on client computers, so I decided to move that to the cloud.

I re-wrote the algorithm in Python, in order to take advantage of Python’s multiprocessing features, and refactored it to run as a serverless AWS Lambda function. When the client app needs the computer’s move to be calculated in the 5x5 mode, it POSTs the current board state to an AWS API Gateway endpoint, which triggers execution of my Lambda function. The Lambda function spawns a separate process for each of the possible & valid moves for the computer, and each process makes an initial call to the recursive minimax function. Once all processes have finished execution, the parent function assembles the results into a JSON response that is returned to the client, which makes the computed move for the computer.


© 2022. All rights reserved.