Giter Site home page Giter Site logo

cactus-josh-ts's Introduction

cactus-josh

cactus-josh is a JavaScript implementation of the classic CactusKev poker hand evaluator, originally written in C by Kevin Suffecool. One of the cleverest bits of code ever written, this algorithm represents the 52 cards of a French deck with unsigned 32-bit d-words, each of which corresponds to a prime number. It then uses bitshifting and lookup tables to calculate the value of a hand of five cards. It's insanely fast!

Instructions for use

Install/require, then generate a new deck with fullDeck(). Convert each card to a string with cardName( card ):

const cactus = require( "cactus-josh" );

// pass any non-null argument to shuffle the deck
const shuffledDeck = cactus.fullDeck( true );

const drawFive = shuffledDeck.slice( 0, 5 );

console.log( drawFive.map( cactus.cardName ) );
--> [ 'Nine of Clubs', 'Ten of Clubs', 'Six of Clubs', 'Nine of Diamonds', 'Five of Diamonds' ]

There are 2,598,960 (52-combination-5) possible five-card hands. Each hand has a unique rank, from 7,462 (the lowest possible hand) to 1 (a royal flush of spades). Use handValue( hand ) to return a hand's number rank, and handRank( hand ) to return a string of the hand type:

console.log( cactus.handValue( drawFive ) );
--> 4601

console.log( cactus.handRank( drawFive ) );
--> One pair

cactus-josh-ts's People

Contributors

josh-frank 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.