Connect Four caught my eye because of the childhood nostalgia factor. However, ultimately, I chose Connect Four because I couldn’t readily see how to code it – seemed like a challenge.
Rather than talk about the whole experience, I’ll just pinpoint a few highlights and issues:
- I learned how to dynamically create variables. Each grid slot is named according to its row and column (r1c5). I’m not sure it’s the best way, but it helped in visualizing the grid and checking for connections.
- Initially, the goal was to have each slot variable store a list of the 8 surrounding slot variables – tacking the grid/vector calculations onto the front-end allowing me to cycle through slot variables using list indexes. Once I got pretty deep into using the storage-based system, I realized it was easier to visualize the solution when calculating the vectors from an origin point. Also, this method meant less storage for the program to cycle through on, what might end up being, a continual basis.
- The code is pretty dynamic. Board size and player count are player created.
- The screen is cleared for almost every turn or input queue. It’s only been tested in a Windows OS.
- There was some disappointment however, since I hoped for more practice with classes. It ended up only needing two unique classes; simple ones – one for the board and one for the slots. No parent/child stuff.
- Also got a bit lazy. I realized that in order to have rows or columns using double-digits, I’d have to do more detailed string parsing to get my dynamically created variables to work. So, grid size maxes at 9x9. The game was built using the standard Connect Four board size – 6(rows) x 7(columns), and it’s been tested using more than two players with various board sizes.
You can find the game code here: "CFour.py" Github Link
In conclusion, I wish I would have found a way to test my class knowledge more; however, function, list, and dictionary use seemed adequate. Writing the actual gameplay code was challenging and enjoyable, fine-tuning the user interface was kind of an annoying drag – glad I didn’t pick a project more text based.

No comments:
Post a Comment