Giter Club home page Giter Club logo

cards's Introduction

Cards

Implements some useful functions and elements to use a deck of cards in your favourite C projects!

Some basic infos about the types

Given a Card new_card variable, you can access and assign its suit and face value with Suit suit = new_card.suit and Value value = new_card.value. The following suits and values are supported:

SUITS:

  • HEARTS
  • DIAMONDS
  • SPADES
  • CLUBS
  • JOKER
  • SHUFFLE_MARKER

VALUES:

  • ACE
  • TWO
  • THREE
  • FOUR
  • FIVE
  • SIX
  • SEVEN
  • EIGHT
  • NINE
  • TEN
  • JACK
  • QUEEN
  • KING
  • JOKER_VALUE
  • SHUFFLE_MARKER_VALUE

You can get the string literal associated with a card's suit or value with char *new_suit = suit(new_card)and char *new_value = value(new_card) please note that you can't get the suit literal or value literal of a shuffle marker.

Given a Deck *new_deck variable you can access the number of its cards (drawn + NOT drawn, jokers and shuffle markers not included) with new_deck->cards_nmb, the number of jokers (drawn + NOT drawn) with new_deck->jokers and the number of shuffle markers with new_deck->shuffle_markers.

Brief tutorial

To create a new deck:

Deck *new_deck = create_deck(NUMBER_OF_DECKS, NUMBER_OF_JOKERS, NUMBER_OF_SHUFFLE_MARKERS);

NUMBER_OF_DECKS indicates the number of decks the new deck will be made out of. For example, keeping in mind that a standard deck of playing cards has 52 cards (13 per suit), if NUMBER_OF_DECKS = 3 the new_deck will be made out of 3 * 52 cards, with 3 copies of each card. NUMBER_OF_JOKERS indicates the number of jokers present in the deck. NUMBER_OF_SHUFFLE_MARKERS specifies how many shuffle markers are there in the deck. Once a shuffle marker is drawn, all the previously dealt card get shuffled back in the deck, including all the shuffle markers. Drawing a shuffle marker is like "resetting the deck".

To draw a card:

Card drawn_card = draw(new_deck);

Where deck is the deck from which you want your card to be drawn from.

The decks get shuffled automatically once all cards have been drawn from it

To check the number of cards yet to be drawn

int not_drawn = available_cards(new_deck);

To shuffle a deck

shuffle(new_deck);

Keep in mind that shuffling here means taking all the dealt cards and shuffling them back into the deck.

In conclusion

I hope you find this library useful, I had lots of fun writing this! I recommend you check the cards.h header to discover more functions that you may find useful and the cards.c file to have a more in depth understanding of how everything works. I tried to make each function as efficient as possible, minimizing wasted time and CPU use while giving you the same odds of drawing a card that you would normally get if you drew a card with a real deck of cards. I am open to suggestions on new functions to implement or on how to make things more efficient... enjoy!

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.