I love it when curiosity sinks its teeth into me, when my need to know drives me to go above and beyond the assignment. When did you go above and beyond the task just for the sake of your own curiosity?
At the start of my Software Engineering Bootcamp, we were tasked with programming a simple tic-tac-toe game to practice DOM manipulation. Before the bootcamp, I had taught computer science, and already had a firm grasp on DOM manipulation. So, I wanted to push myself, and I knew from the 1983 classic film WarGames that tic-tac-toe was a solved game. In other words, if both players know how to play the game, it will always end in a tie. So, I asked myself, “could I program an unbeatable computer player for my game?” From my experience I knew I could use selection to determine the computer’s moves, but the number of conditionals that would take would be too many to type or even think about, and it would be very easy to miss a condition.
Enter recursion.
I knew about recursion, but I was scared of it because it hurt my brain, and I had never encountered a problem I both wanted to solve and needed recursion to solve. So, this was it. I knew I needed recursion because of the branching factor. From my googling I quickly came across the minimax algorithm. Minimax is a simple recursive algorithm that assigns a value to the base case, or end state, of a board game. So, for tic-tac-toe, if the player is X and the computer is O, my computer player would assign -1 to any base case where X wins, 0 to a tie, and 1 to any base case where O wins.
That’s where the recursion came in. Each move branched into more possibilities, and the minimax algorithm allowed me to explore them all without writing out endless conditionals. The computer could now simulate every possible outcome of a game, evaluate them, and then choose the move that maximized its chances of winning, or at least guaranteed a tie.
When I finally got the algorithm working, it felt like unlocking a new way of thinking. Recursion wasn’t abstract anymore. It was practical, powerful, and elegant. And beyond the code itself, the project reminded me why I love learning. Curiosity pulled me past the assignment into uncharted territory, where the real growth happened.
In the end, I didn’t just build a tic-tac-toe game with an unbeatable computer player. I proved to myself that the things that once felt intimidating, like recursion, could become tools I reach for with confidence.
So now I’ll throw the question back to you. When was the last time your curiosity pushed you beyond the assignment and what did you discover?
Also let me know if you’d be interested in a walkthrough of my implementation of the minimax algorithm. Here is the live demo if you want to try and beat it! I themed it as Pirates vs. Ninjas for fun.
Top comments (0)