2019-01-23 v1 Dr David Casperson ------------------------------------------------------------------------------ This document provides the problem statement a description of the game of Cribbage. 1. A detailed list of tasks and deadlines, 2. a document describing the design process, 3. a document on what is generally required of formal reports, and 4. a sample design document are provided on the web-page http://casper.unbc.ca/Semesters/2019W/101-project.php . 1 Problem statement =================== The goal of this project is to write programs to play the two-person variant of the card game called cribbage. The game itself is described in Section~\ref{sec:cribbage} of this documents. 1.1 Programming tasks --------------------- Your team needs to write a cribbage program that consists of a "referee", some kind of user interface, a human player interface, and a computer opponent. The Referee The referee program minimally allows a person to play ~~~~~~~~~~~ cribbage against the computer. It keeps track of whether either player has won the current game; lets the human player quit or restart the game at any time (s)he chooses; and draws (or otherwise displays) the board so that the human player can see the current game situation. The Display ASCII-graphics such as those shown in [see .pdf file] are acceptable for displaying the board. However, a Graphical User Interface (GUI) is preferred. The Computer Player The exact mechanism that the referee program uses ~~~~~~~~~~~~~~~~~~~ for interacting with the computer player is left unspecified for now. However, a longer term goal is to have the various teams' computer players play each other in a tournament. In order for this to happen the Computer Player needs to have minimal coupling with its environment, and this should be a design goal. For the computer player program, correctness is far more important than cleverness. The computer opponent program must work correctly. However, intelligent play by the computer opponent is not necessary, and should not be a priority when completing the team term project. The Human User Human player input and output happens at some level through ~~~~~~~~~~~~~~ the User Interface. However, it helps a lot if the human player and the computer player are represented by similar classes. 1.2 General comments -------------------- The referee program and the computer opponent program make use of similar concepts, so they should make use of common classes and object files in their construction. \textit{Your coding will be graded in part on how much code is shared between the two program;} as one of the goals of good object oriented programming is to create classes and objects that can be re-used. 1.3 Interface mechanisms and tournaments ---------------------------------------- In previous years I have insisted that the computer opponent be a stand-alone prorgram that communicated via System.in/out. My goals were two-fold: 1. to force teams to re-use classes in multiple programs, and 2. to make it possible to have an automated tournament where the AI's played against each other. This didn't work well in practice. I won't require that for this year's project. However, I may yet try to create specifications so that the AI's can play against each other. Cribbage ======== Cribbage is played between two players with a cribbage board and a standard 52-card deck of cards (the jokers are not used). Although there are variants of cribbage for three or four players, for the purposes of this project cribbage is a two-player game. The cribbage board is essentially a mechanical counting device capable of keeping track of two totals that are between 0 and 121 and of displaying the last number added to each total. The object of the game is to be the first player to score (at least) 121 points. At any given point in the game one player is the dealer and the other is the \textit{pone} (non-dealer). In any given game being the dealer alternates between the players. In the first game of the sequence the dealer is determined by drawing cards. Thereafter, the loser of the previous game deals first in the next game. A round During each round of play the dealer starts by dealing six cards ~~~~~~~ face down to each player, alternating between her opponent and herself. Each player then picks up their hand and selects two cards to discard face down into the \textit{crib}, which belongs to the dealer. After the pone has discarded, she cuts the remainder of the deck. After the dealer has discarded and the pone has cut the deck, the dealer turns the top card of the face up. If this card is a Jack, the dealer immediately scores two points.\footnote{ The dealer can win the game this way.} After discarding and cutting, the players take turns exposing their cards as described below under ``pegging''. Assuming that neither player wins during the pegging of the hands, the hands are then counted for points. The pone counts her hand first. The dealer then counts her hand. Finally, the dealer then counts the crib. The order is important because either player may win when it is their turn to count. There are no draws in cribbage. Pegging Pegging happens after players have discarded to the crib and the cut card has been exposed. During pegging, the players take turns exposing their cards with the non-dealer starting. As each player exposes a card, she announces the total count and possibly the number of points scored. Thus a player might say ``twenty'' or ``twenty for three''. For the purposes of counting aces count as one; jacks, queens and kings count as ten, and other cards count as their face value. While pegging, the count never exceeds thirty-one. If a player cannot play a card without exceeding thirty-one, she says "go" instead. Her opponent then plays any cards she legally can (in any order she chooses) until either the count reaches thirty-one, or she also says go. If the count reaches thirty-one or both players say "go" and at least one player has cards remaining, the count restarts at zero. If both players have cards remaining, the player who did not play a card last plays first. Pegging stops when both players are out of cards. The hands are then counted (scored). 2.1 Scoring ----------- Only one player scores at a time. There are no draws in cribbage. Scoring may happen when: 1. the cut card is exposed, 2. during pegging, or 3. when a player is counting her hand or crib. 2.1.1 The cut card ^^^^^^^^^^^^^^^^^^ If the cut card is a jack it counts as two points for the dealer. 2.1.2 Pegging ^^^^^^^^^^^^^ • If a player causes the count to reach exactly fifteen or exactly thirty-one, she scores two points. If a player plays the last card of a counting sequence and the count does not reach thirty-one, she score one point. • If a pair of cards of the same rank are played sequentially (without an intervening restart of counting), the player who plays the second card scores two. • If a three cards of the same rank are played sequentially (without an intervening restart of counting), the player who plays the third card scores six. • If a four cards of the same rank are played sequentially (without an intervening restart of counting), the player who plays the fourth card scores twelve. • If three or more cards played in order (without an intervening restart of counting) form a sequence (possibly out of order) the player who plays the third or later scores the length of the sequence. 2.1.3 Counting a hand ^^^^^^^^^^^^^^^^^^^^^ The following subsets of a hand or a crib count for points as noted. • Each subset whose point count (face value, 10 for face cards) is exactly fifteen counts for two points. • Each pair counts for two points, and thus ▶ each triple counts for six, and ▶ each quadruple counts for twelve. • Each maximal contiguous rank sequence of three or more cards counts for the length of the sequence. • A jack of the same suit as the cut card counts for one. • If the cut card and all of the cards in a hand or the crib are of the same suit, it counts for five. Otherwise if all of the cards in a hand are of the same suit, it counts for four. (This does not work for the crib.) 2.2 Examples ------------ Examples of how to score hands and how to score while pegging will be supplied at some future date. Glossary ======== [Crib] A collection of four cards placed face down in the center of the game space. Each player puts two cards into the crib from their initial hand of six cards. [(to) Cut] To cut a deck of cards means to split the deck into two piles, and then recombine, placing the formerly bottom part on top. [(the) Cut] In a round of cribbage after forming the crib, the pone cuts the deck of cards and the dealer turns the new top card face up. This is the \textit{cut} card, which provides a fifth card when evaluating (scoring, counting) the pone's hand, the dealer's hand, and the crib. [Dealer] Person who deals the cards. [Discard] to place two cards from a player's (initial 6-card) hand into the crib. [Double Skunk] To win (or a win) by more than sixty points. If the winner crosses the finish line (between 120 and 121 points) before the loser crosses the double skunk line (between 60 and 61 points) the loser is ``double skunked''. [Drawing Cards] A way to determine the initial dealer for the first game of a sequence of games. Both players take a card from the face down deck. The player with the card of lower rank deals first. If both players draw cards of the same rank, players draw again. [Face Card] A card with a face on it. Either a Jack, a Queen, or a King. [Hand] A collection of cards held by a player so as to be unseen by the other players. In Cribbage may also refer to a collection of four cards plus the cut card that is scored as a group. [Pair] two cards of the same rank. Scores 2 if pegged consecutively, or found in one hand. [(to) Peg/Pegging] \mbox{} 1. to move one's pegs on the crib board in order to keep track of the score. Each player has two pegs. In order to add 5 points to her score, a player takes their back peg and puts it 5 points ahead of the front peg. 2. also the phase of a round of play where players gradually expose their cards whilst attempting to score points. [Pone] Non-dealer. Pegs first. Counts first. [Quadruple] four cards of the same rank. Scores 12 (six pairs) if pegged consecutively, or found in one hand. [Rank] What is on a card other than its suit. One of Ace, 2, 3, 4, 5, 6, 7, 8, 9, 10, Jack, Queen, or King. [Run] A sequence of three or more cards of consecutive ranks (the suits of the cards are irrelevant). For instance: \heart{9} \club{10} \heart{J} \diamond{Q}. [Skunk] To win (or a win) by more than thirty points. If the winner crosses the finish line before the loser crosses the skunk line (between 90 and 91 points) the loser is ``skunked''. [Suit] One of clubs, diamonds, hearts, and spades. [Triple] three cards of the same rank. Scores 6 (three pairs) if pegged consecutively, or found in one hand.