Giter Site home page Giter Site logo

cards_c_plus_plus's Introduction

cards_c_plus_plus

In this project, I create a program in C++ to create a deck of cards, shuffle it, and deal hands in the game of poker. Then evaluate the value of the poker hand.

There are three classes that make this program function. They are:

  1. Class Card

    • This class represents a single card. It has two int data members face and suit. It has two static arrays of strings representing the faces and suits. I also had to overload the << operator to allow streaming of card in the form of "face of suit".
  2. Class DeckOfCards

    • This class is a deck and holds 52 cards. It implements a shuffle function to suffle the deck using std::random_device, std::mt19937, std::uniform_int_distribution. It implements a dealCard function that returns the top most card in the deck.
  3. Class Hand

    • This class represents a hand of five cards. This is the class that does the evaluation and calculations to figure out the best value of the five card hand: they are - A pair, Two pair, Three of a Kind, Straight, Flush, Four of a Kind, Straight Flush.

I have written some ad-hoc tests for this program. The ad-hoc test functions live in the file "hand.cpp"

I have also written a evaluation program to test the poker program. It basically deals 100k hands and counts the number of times a hand was seen. Just run the main program to see the output. I have also copy pasted the results below.

My program benchmark closely follow the probabilities shown at Wikipedia.

After dealing 100k hands.

Hand Count Probability
A Pair 41780 41.78%
Two Pairs 4668 4.668%
Three of a kind 2154 2.154%
Straight 383 0.383%
Flush 232 0.232%
Four of a Kind 24 0.024%
Straight Flush 3 0.003%

These values match closely to those shown at: https://en.wikipedia.org/wiki/Poker_probability

cards_c_plus_plus's People

Contributors

sm-m-1 avatar

Stargazers

 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.