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:
- Finds the highest scoring pattern obtained from 7 cards.
- Compares two hands to account for same pattern and ties.
Poker Hands
These are the patterns accounted for:
- Royal Flush
- Straight Flush
- Straight Flush (Low Ace)
- Four of a Kind
- Full House
- Flush
- Straight
- Straight (Low Ace)
- Three of A Kind
- Two Pair
- One Pair
- 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:
- Find the highest number in the pair.
- If the highest number in the pair is the same, find the highest number outside of the pattern.
If you have competing full houses:
- Find the highest three (threeHigh)
- If the highest three is the same, find the highest pair (twoHigh).
If you have competing two pairs (NOT DONE YET):
- Find the highest number in the pattern. It does not matter which pair you are looking at (max.inArray).
- 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:
- Find the highest number in the pattern.
- 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.