Connect Four

Connect Four Game

During the spring of 2022, midway through my first ever computer science course, I decided that I wanted to code a program that could beat me in a game. I decided that Connect Four had the perfect amount of complexity for me to tackle on my own. I knew I wanted to be able to play against my program on a browser, as my dreams of having my own website were dominant in my mind. So I began picking up JavaScript and tinkering with simpler programs in my web browser.

I started with simple games like Tic Tac Toe, and began discovering the basics of algorithms for decision making. I figured out that for turn-based games like Tic Tac Toe, Connect Four, Checkers, and Chess, a simple decision tree can be used to calculate many moves ahead, and a relatively simple algorithm can yield surprisingly powerful results.

After setting up my first move-generation and win-checking code, I let it run on the starting position and sat around for a few minutes, hoping It would give me the perfect starting move. Nothing happened. I knew that I was asking too much of my poor laptop to solve connect four. I needed to cut the search sort and develop an efficient heuristic function for determining the relative strength of a position.

After a good bit of head-scratching, I squabbled together a crude rating function, and after fiddling for the right depth to stop the search, I was impressed by results. It wasn't beating me yet, but certainly made some intelligent moves. After a couple weeks of additional head-scratching and tweaks, I had a program that was extremely fun to play against. It was competitive, beating me most of the time, but always led to long and fun games.

I coded a cool graphical interface, and posted it online and challenged all of my friends at school to try it out. Overall, the whole journey became one of my favorite projects to work on.

javascript
html5
css3