Unit testing and Poker!

The end of week 5 wrapped up on Friday at The Iron Yard. I feel like I am already a developer who works a 9–5 job, that is how much coding I have done.

This week we really focused on unit testing, which is something I was familiar with but had not really used it in a major project. I downloaded Mocha and Chai via npm and went to work. First, we had to build the functions and rules for a BlackJack game, which I really enjoyed. By the end of building the games ‘engine’ I had 40–50 tests passing. It’s so satisfying to see those little green arrows in the terminal :)

For the weekend homework, we were given a similar task but with new card games, our choice of War, or POKER! The extra credit? Actually give it a working game interface in the brower. You bet I wanted to take a crack at Poker and its UI.

Poker is something I have envisioned myself building, and now is my chance. After a few days of tinkering with different builds and architectures, I was finally able to finish a build of all the functions and tests. The most challenging was probably the “determine who wins” functions. It was pretty large by the time I was done coding. I spent a very good amount of time making I code more DRY and functional. I was able to break apart the tests for certain hands up into its own JS file.

I also took a stab at using gulp for the first time in a project, and it made testing and building a much cleaner process.

After the functions were built, I was ready to use my existing knowledge with using the HandlebarsJS template and build this game.

I may not be the best at picking colors, but I was quite pleased with myself after I finally got one round of gameplay to work. Then, I was able to create more functions to handle an actual game flow with betting. Now, the game can play round after round without an issue, with the player gaining and losing money depending on how he bets.

Overall I had a great time building it, and I plan on implementing more features (such as a “game over, you win/lose”).

Here’s a link to the GitHub.io

https://chrislebbano.github.io/poker/

Show your support

Clapping shows how much you appreciated clebbano’s story.