Pot Luck Casino

This was a project I wrote over a couple of days to get more familiar with writing a full C++ program, rather than individual components and libraries. One of my ongoing tasks is to become intimately familiar with C++. While I can write production code in the language, I'm not satisfied competency, I am constantly striving to be good, or better, at the things I do often. So that means writing little side projects like this from time to time.

The casino idea came from trawling through a list of short programming projects. I gamefied it a little more with full on win and loss states, and that was kind of it. It was a fairly quick and easy project all things considered, with one slight exception.

Having written this, I was playing it one day and noticed that the winnings from each round were being accumulated poorly. It turns out this was a minor logic bug involving winning a round. I had inadvertently programmed it so that when you "put money on the table", the money wasn't actually removed from your balance. It was only removed if you lost the round. This worked perfectly fine unless you won the round, at which point you'd pick up the total of the pot, but without ever removing your bet from your total. So if all four players put in $100, you would pick up $400 and the other three players would lose $100. But because you hadn't initially lost the $100, you'd essentially get $500 for winning. This led to a slow creep of money just appearing out of nowhere. It was easy to patch once I noticed it, but this taught me a very important lesson.



Anticipating the consequences of the code we write

Something I have been putting a lot of focus on as I improve and gain experience as a developer is anticipating the outcome of any code that I write. Trying to see several steps down the line and expect bugs that could occur based on how I've implemented something. Taking the extra time to think about this allows me to not only prevent some bugs from occurring, but also preemptively work out how I'm going to fix them if there's no way to work around it.