Code Monkey home page Code Monkey logo

cards.jl's Introduction

Cards

Build Status Coverage Status codecov.io

This package defines three types:

  • Suit uses 2 low bits of a UInt8 to represent four suits of cards: ♣, ♢, ♡, ♠.

  • Card uses 6 low bits of a UInt8 to represent 64 possible card values:

    • 2 bits for the Suit (♣, ♢, ♡, ♠)
    • 4 bits for the rank from 0-15, meaning:
      • 0 – low joker
      • 1 – low ace
      • 2-10 – number cards
      • 11-13 – jack, queen, king
      • 14 – high ace
      • 15 – high joker
  • Hand uses 64 bits of a UInt64 to represent all possible hands (sets) of cards.

The design of having high and low aces and jokers allows hands from many different games to be represented in a single scheme, with consistent rank ordering. If you're representing hands from a game with aces high, use the A♣, A♢, A♡, A♠ cards; if you're representing hands from a game with aces low, use the 1♣, 1♢, 1♡, 1♠ cards instead.

Example usage:

julia> using Cards

julia> hand = rand(Hand)
Hand([2♣, 3♣, 6♣, 7♣, 8♣, 9♣, 2♢, 3♢, 4♢, 7♢, 10♢, J♢, A♢, 4♡, 5♡, 6♡, 7♡, Q♡, K♡, A♡, 4♠, 6♠, 9♠, K♠, A♠])

julia> 2in hand
true

julia> 4in hand
false

julia> A♣ in hand
false

julia> A♠ in hand
true

julia> hand
Hand([4♡, 5♡, 6♡, 7♡, Q♡, K♡, A♡])

julia> hand
Hand([4♠, 6♠, 9♠, K♠, A♠])

julia> length(♣  hand)
6

cards.jl's People

Contributors

stefankarpinski avatar mbeltagy avatar jeffreysarnoff avatar stevengj 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.