Go Fish, Part III: Play a Full Game

This function plays one turn of the game Go Fish. It uses the drawCard() and checkCard() functions (the corrected versions) defined in the previous two parts.

One turn is completed as follows: A rank is randomly selected from the ones that are in the player's hand, and the other hand is interrogated to see if it has any cards of that rank. If it does, they are transferred over. This continues with another card until no card is transferred, at which point the player has to “go fish” and draw a new card from the deck.

Note: The code does not check if the card drawn was the same rank as the last card asked for. ...

Get Find the Bug A Book of Incorrect Programs now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.