Coder Social home page Coder Social logo

poker's Introduction

Poker

A small library for evaluating two poker hands against each other.

Usage

The basic unit of this class is a CardHand object. A CardHand object holds five cards. Every CardHand object maintains the current rank it has, e. g. FLUSH, or TWO_PAIRS, which can be read by calling getRank() on a CardHand object.

Two CardHand objects can be ranked against each other using an object of the Ranker class. The Ranker class method rankHands takes two hands as a parameter and return the winning hand:

Ranker ranker = new Ranker();
CardHand result = ranker.rankHands(hand1, hand2);

Testing

The library comes with unit tests for ensuring the ranking of hands against each other is correctly determining the winner. You can see these tests in action by cloning this repo and then running the tests with Maven:

mvn test

Implementation note

Although Poker cards have no order defined on suits (e. g. a diamond 5 is not more or less "valuable" than a spade 5), this implementation does internally use a sort order not only for card values, but also for card suits. This allows us to use the data structure of a SortedSet internally, which in turn gives us a natural and relatively efficient way of determining the rank of a hand, while the determining of a winner when comparing two hands with each other does not necessarily benefit from this. We assumed here that in a real-life Poker computer game, the determination of a single hand's rank needs to be done more often than the ranking of hands against each other: The single hand's rank needs to be evaluated and displayed on the player's screen, whenever she exchanged some cards. The ranking of different player's hands against each other only needs to be done once per game, at the end of it. That's why we optimized the single hand's rank evaluation by using a sort order for cards that is "stricter" than the sort order of the Poker game's specifications.

poker's People

Contributors

sermo-de-arboribus avatar

Watchers

 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.