Git Product home page Git Product logo

pokerhand-eval's Introduction

Poker Hand Evaluator

In pure python

27 January 2011, Alvin Liang

Introduction

This is a pure python library to calculate the rank of the best poker hand out of 5, 6, or 7 cards. It does not run the board for you, or calculate winning percentage, EV, or anything like that. But if you give it two hands and the same board, you will be able to tell which hand wins.

It is nowhere near as fast as pypoker-eval, but it works if you can't use C for some reason (the early stages of the first MIT pokerbot competition come to mind). The core algorithm is slower, and you obviously don't have the speed of C.

Quick Start

from pokereval.card import Card
from pokereval.hand_evaluator import HandEvaluator

hole = [Card(2, 1), Card(2, 2)]
board = []
score = HandEvaluator.evaluate_hand(hole, board)

Rank is 2-14 representing 2-A, while suit is 1-4 representing spades, hearts, diamonds, clubs.

The Card constructor accepts two arguments, rank, and suit.

aceOfSpades = Card(14, 1)
twoOfDiamonds = Card(2, 3)

Algorithm

The algorithm for 5 cards is just a port of this algorithm: http://www.suffecool.net/poker/evaluator.html

I came up with the 6 and 7 card evaluators myself, using a very similar card representation and applying some of the same ideas with prime numbers. The idea was to strike a balance between lookup table size and speed.

Also, I haven't included the code I used to generate the lookup tables, but you should be able to do that with a simpler, slower algorithm. Maybe I'll add that later as well.

There is also a two-card ranking/percentile algorithm that is unrelated to the rest and may get cleaned up later. We used it at one point for some pre-flop evaluation. Credit to Zach Wissner-Gross for developing this.

Documentation is sparse at the moment, sorry about that, and obviously I did not really bother to package it or clean it up. I may or may not work on this in the future. Basically, I made it, so why not release it?

Contributors

  • Me! Go me!
  • Zach Wissner-Gross (2-card algorithm)
  • arslr (Fixes for other Python versions)
  • Jim Kelly (Help with packaging, additional documentation)

pokerhand-eval's People

Contributors

aliang avatar

Watchers

Ivan Rocha avatar James Cloos avatar  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.