Giter VIP home page Giter VIP logo

pokerhandevaluator's Introduction

PHEvaluator

PH stands for Poker Hand, as well as Perfect Hashing.

A poker hand evaluation algorithm with perfect hash functions and dynamic programming.

Copyright 2016 Henry Lee ([email protected])


Overview

It's a brand new algorithm, which avoids traversing all 7 choose 5 combinations when evaluating a 7-card poker hand, but uses a perfect hash function instead.

The implementation supports both 5-card and 7-card evaluation, where the 7-card version beats many other algorithms in the execution time, and it's also using a considerably small memory (~100kb for the 7-card evaluation).

Their return value is identical to the Cactus Kev's Poker Hand Evaluator (http://suffe.cool/poker/evaluator.html), where basically a stronger hand has a lower return value. However, one can modify the hash table to support any kind of evaluation system he likes.

Documentation contains the description of the algorithms used in the evaluators.

The examples directory has some examples that demonstrates how to use the interface.


Compile and test

Simply run make can compile the libraries and test program.

If you'd like to add some more flags in gcc, you may export the flags to the environment variable CFLAGS. One example is export CLFAGS="-Ofast".

After the compilation, it generates two programs five and seven. These test programs are cloned from Cactus Kev's evaulator, which loops over all possible hands and display the frequency of each hand type, so that we can approximately tell if the algorithms are correct or not.

If you want to test the time used for evaluating all hands, run time ./five or time ./seven.

As for the programs in examples, simply cd examples and running make will compile all these programs.


Interfaces

The file include/evaluator.h contains the interfaces you need to call.

The inputs are card ids ranged [0, 51]. The card id modulo 4 gives the suit. It doesn't really matter how you assign the four numbers to the 4 suits, as long as they use distinct numbers. The card id divided by 4 gives the rank, where ace has the highest value 12 and deuce has the lowest value 0.

The return value is identical to the Cactus Kev's evaluator. The strongest hands (Royal straight flush) are returned with 1, and the second strongest hands (King high straight flush) are returned with 2 and so on. The weakest hands have the return value 7462.

You can find more about Cactus Kev's evaluation system from these websites.

http://suffe.cool/poker/evaluator.html http://suffe.cool/poker/7462.html

pokerhandevaluator's People

Contributors

henryrlee avatar

Watchers

Butakov Igor 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.