npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

poker-pattern-matching

v1.0.0

Published

### Description The most difficult part of making a poker game is the pattern-matching algorithm. Out of the combination of the total 7 cards (5 from flop, 2 from hand), how do you extract the highest scoring pattern?

Downloads

1

Readme

Poker Matching Algoritm

Description

The most difficult part of making a poker game is the pattern-matching algorithm. Out of the combination of the total 7 cards (5 from flop, 2 from hand), how do you extract the highest scoring pattern?

This repository does two things:

  1. Finds the highest scoring pattern obtained from 7 cards.
  2. Compares two hands to account for same pattern and ties.

Poker Hands

These are the patterns accounted for:

  1. Royal Flush
  2. Straight Flush
  3. Straight Flush (Low Ace)
  4. Four of a Kind
  5. Full House
  6. Flush
  7. Straight
  8. Straight (Low Ace)
  9. Three of A Kind
  10. Two Pair
  11. One Pair
  12. High Card

mapBestPokerHand.js

Map best poker hand is the main function that is used to get the best 5 hand from the 7 hand. I explain the logic as below (it is sligtly convulated):

If you have competing pairs, straight, three, four-of-a-kind, fullhouse:

  1. Find the highest number in the pair.
  2. If the highest number in the pair is the same, find the highest number outside of the pattern.

If you have competing full houses:

  1. Find the highest three (threeHigh)
  2. If the highest three is the same, find the highest pair (twoHigh).

If you have competing two pairs (NOT DONE YET):

  1. Find the highest number in the pattern. It does not matter which pair you are looking at (max.inArray).
  2. If the highest number is the same, look at the lowest pair and find the highest number in the lowest pair.

If you have no pattern:

  1. Find the highest number in the pattern.
  2. If the highest number is the same, then "tie"

Below is the format output of the best poker hand:

let hand=[
  { suit: 'D', number: 9 },
  { suit: 'C', number: 9 },
  { suit: 'H', number: 11 },
  { suit: 'S', number: 11 },
  { suit: 'D', number: 3 },
  { suit: 'H', number: 11 },
  { suit: 'D', number: 8 }
];
{
  hand: [
    { suit: 'D', number: 9 },
    { suit: 'C', number: 9 },
    { suit: 'H', number: 11 },
    { suit: 'S', number: 11 },
    { suit: 'H', number: 11 }
  ],
  suits: [ 'D', 'C', 'H', 'S', 'H' ],
  numbers: [ 9, 9, 11, 11, 11 ],
  suitsReady: [ 8, 2, 4, 1, 4 ],
  pattern: 'FullHouse',
  posList: { '9': [ 0, 1 ], '11': [ 2, 3, 4 ] },
  pos: [ 0, 1, 2, 3, 4 ],
  array: { inArray: [ 9, 9, 11, 11, 11 ], outArray: [] },
  arrayRefine: {
    '9': { inArray: [Array], outArray: [Array] },
    '11': { inArray: [Array], outArray: [Array] }
  },
  max: { inArray: 11, outArray: -Infinity },
  twoHigh: 9,
  threeHigh: 11
}

Installation and Running

node main.js
node test.js

Will be made into npm repository soon.

References

Senzee Poker Algorithm

Cactus Kev 7-hand Algo

Bit Manipulation Algorithm

Js Fiddle for Bit Manipulation Algorithm

Forum

Stack Exchange Question

Bitwise Operators

Find all k-combinations