Coder Social home page Coder Social logo

cribbage's Introduction

Cribbage Game

Introduction

Welcome to the Cribbage! This Python program allows you to play Cribbage against a computer opponent. Cribbage is a classic card game that involves creating combinations of cards to score points.

This iteration of the game assumes you have prior knowledge of Cribbage rules, game object, etc.

Game start

Getting Started

To start the game, run the main.py file. The game will begin by shuffling the deck, dealing cards to you and the computer player, and filling the crib.

Game Components

Classes

  1. Main Class (main.py):

    • Responsible for initializing the game components.
    • Manages the main flow of the game.
  2. Round Class (round.py):

    • Controls the logic for each round of the game.
    • Handles player and computer turns, scoring, and round end.
  3. Scoring Class (scoring.py):

    • Calculates points based on specific card combinations in the game.
  4. Crib Class (crib.py):

    • Manages the initial game setup for establishing the crib.
  5. Hand Class (player.py):

    • Represents a player's hand and provides methods for adding, discarding, and displaying cards.
  6. Card Class (player.py):

    • Represents a playing card with a value, suit, and point value.
  7. Animations Class (animations.py)

    • Manages dynanic print elements.

Functions

  1. Main Class Functions:

    • fill_crib(): Shuffles and deals cards, allowing players to discard cards to fill the crib.
  2. Round Class Functions:

    • play(): Manages the flow of a round, alternating between player and computer turns.
    • player_turn(): Handles the player's turn.
    • computer_turn(): Manages the computer's turn.
    • switch_turns(): Switches turns between player and computer.
    • handle_player_out_of_cards(): Manages the end of the round if a player runs out of cards.
    • reset_table(): Resets the table points and cards played.
    • end_round(): Calculates and displays points at the end of a round.
  3. Scoring Class Functions:

    • calc_points(card_list, player): Calculates points based on card combinations.
31 scoring
  1. Crib Class Functions:
    • discard(p): Allows the player to discard cards to the crib.
    • computer_discard(p): Allows the computer to discard cards to the crib.

Unit Testing

test_scoring.py: Ensures the correctness of the scoring functionality with unit tests.

How to Play

  1. Follow the on-screen instructions to fill the crib with discarded cards.
  2. The game will alternate between your turn and the computer's turn.
  3. During your turn, choose a card to play by entering the corresponding card number.
  4. The computer will then take its turn.
  5. The round continues until both players cannot play or run out of cards, keeping score when the table count of "31" is hit by a player.
  6. Points are calculated based on card combinations at the end of each round. This version currently supports scoring for pairs, combinations that equal 15 and 3-card runs.
  7. The game ends when a player reaches the maximum score or when you decide to exit.
Final score

Enjoy playing Cribbage!

cribbage's People

Contributors

beccajonas avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.