Connect 4
For a recent take home code challenge, I was tasked with creating a version of Connect 4 with several requirements. My only previous experience in developing a game was in a React tutorial where I created a version of Tic Tac Toe. For this reason I felt it made sense to employ React to handle the user interface. Here are a few takeaways that I got from the experience.
In my most recent work experience, I mostly used Angular and we did not use any state management tools. Going back to React was pretty fun because it felt like I was able to get things up and running quickly. I almost forgot how valuable state management is in React. Being able to keep track of the board relatively easily.
Sadly while I was issued this challenge, I had to work a lot of hours for my part-time job and could not get a sub. This caused me to rush through this challenge. In doing so, the biggest mistake I made was using a functional programming approach rather than an object oriented approach. Had I used an object oriented approach, I could have created a GameState class and represented every possible move as an instance of said class. All possible moves/game states could be represented as a tree. And any time a winning or draw game state is reached, the game will end.
Get John Daise’s stories in your inbox
Join Medium for free to get updates from this writer.
Using a functional programming approach opened up a can of worms because it made the game more susceptible to bugs. An object oriented approach would have almost immediately accessed a particular game state whereas using a functional approach would require the game to actively “think” about what piece is where on the board and what that might mean for the game’s outcome.
I think a good analogy for this would be to consider a musician who is improvising during a song. A functional programming approach would be to think about a note, process whether or not it fits within a particular chord of that song and then play that note if it is a valid note. An object oriented approach could be thought of as choosing notes considering the key that the song is in. An improvising musician who considers a song’s key could be much more efficient in their performance.
When I get more time, I’m going to revisit Connect 4. This was a great exercise and I really got an even deeper understanding of the value of object oriented programming. I highly recommend that anyone who is interested in learning about React or building games check out the Tic Tac Toe tutorial below.




