How I Solidified My Understanding of Object Oriented Programming with Go Fish
Part 1. Introduction
Card games to us humans are notoriously simple. Computers don’t really know much about card games, though. Without any instruction, computers can live their whole pitiful life without playing a single card game, so cherished by us humans. How sad.
Well, I’m sympathetic to my computer, so I chose for it to have a better life; to give it the ability to play the simple card game, Go Fish! Go Fish is a game that has some very easy to follow rules and regulations, with several variations that can be added along the way. The base rules of the game consist of these main points (taken from Wikipedia):
- Players are dealt FIVE cards from a standard 52-card deck, or SEVEN if there are four or fewer players.
- The remaining cards consist of the deck that the players will draw from for the remainder of the game.
- A player whose turn it is to play asks another player for a card of a particular face value
- The player who was asked must hand over all cards of that rank, if possible.
- If the player who was asked does not have any of the face value cards in their hand, the player tells the asking player “Go Fish!”
- The player who asked must draw a card from the deck.
- If a player who asks for cards gets their cards through another player, or if they draw it from the deck after they make a bad guess, they get to go again. If not, it is the next player’s turn
- When any player at any time has all four cards of one face value, it forms a trick, and the cards must be placed down on the playing table
- When all sets of cards have been laid down in tricks, the game ends
- The player with the most tricks wins!
Since I’m new to programming, I knew this would be a whole new experience for me. I hadn’t had the gumption or know-how to start a project like this before, but I knew that applying basic object oriented programming principles would help me get to the bottom of solving this problem. To start things off, I asked myself: “What is an object in a game of Go Fish?”. It’s not surprising what I came up with.
- Engine – An engine is necessary to handle how the game’s different parts will interact with each other
- Deck – The players will interact with the deck
- Card – Every deck is filled with cards, which the player will also interact with in their specific hands
- Player – The player of the actual game. Split into two categories:
- HumanPlayer – Humans control this type of player
- Bot – Since Go Fish isn’t fun without any friends, Players can fill the game up with some computer friends that will take the place of real friends
What else needs to be in there? Nothing? Oh, okay. Yeah… Well it looks like everything that is needed for the base functionality of a card game is there, now all I have to do is actually start to make the classes up. My next post will go over the Card and Deck class, how those two relate to each other, and how they each are built.