Coder Social home page Coder Social 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

jeffreysarnoff avatar mbeltagy avatar stefankarpinski avatar stevengj avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

cards.jl's Issues

Julia 0.5 compatibility

The REQUIRE file states that Julia 0.5 should work. Trying the package on Julia 0.5 results in

julia> using Cards
ERROR: LoadError: syntax: extra token "Suit" after end of expression
 in include_from_node1(::String) at .\loading.jl:488
 in eval(::Module, ::Any) at .\boot.jl:234
 in require(::Symbol) at .\loading.jl:415
while loading C:\Users\admin\.julia\v0.5\Cards\src\Cards.jl, in expression starting on line 17

This is clearly the result of the new v0.6 syntax for types. Not sure if you want 0.5 compatibility, but either the code or the REQUIRE file should probably change.

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.