Skip to content

Commit 631e507

Browse files
committed
v0.0.1
1 parent 5fa7759 commit 631e507

3 files changed

Lines changed: 108 additions & 1 deletion

File tree

README.md

Lines changed: 102 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,102 @@
1-
# dueces.js
1+
# deuces.js
2+
3+
![npm downloads](https://img.shields.io/npm/dm/deuces.js.svg?style=flat-square)
4+
!["Latest Release"](https://img.shields.io/npm/v/deuces.js.svg?style=flat-square)
5+
![MIT license](https://img.shields.io/badge/license-MIT-green.svg?style=flat-square)
6+
7+
A Node.JS port of [deuces](https://github.com/worldveil/deuces) poker hand evaluation library.
8+
9+
![screenshot](img/ss.png "screenshot")
10+
11+
## Installation
12+
```npm install --save deuces.js```
13+
14+
```yarn add deuces.js```
15+
16+
## Usage
17+
Feel free to take a look in the example file in ```test/go.js```
18+
19+
```javascript
20+
const { Card, Deck, Evaluator, LookupTable } = require("deuces.js");
21+
22+
// Create a new card
23+
const card = Card.newCard("Qh"); // Queen of Hearts
24+
25+
// Create a hand of Queen of Spades and Ten of Hearts
26+
const hand = [
27+
Card.newCard("Qs"),
28+
Card.newCard("Th")
29+
];
30+
31+
const board = [
32+
Card.newCard("Ah"),
33+
Card.newCard("Kd"),
34+
Card.newCard("Jc")
35+
];
36+
37+
// Instantiate an Evaluator to evaluate the results
38+
const evaluator = new Evaluator();
39+
const rank = evaluator.evaluate(board, hand)
40+
console.log(`Rank for your hand is: ${rank}`);
41+
42+
43+
// Create a Deck
44+
const deck = new Deck(); // Create a new shuffled deck
45+
board = deck.draw(5); // Draw 5 cards from the deck
46+
const player1_hand = deck.draw(2); // player 1 will draw 2 cards
47+
const player2_hand = deck.draw(2); // player 2 will draw 2 cards
48+
49+
50+
// Print out their drawn cards
51+
Card.print_pretty_cards(board)
52+
// > [ 2 ♦ ] , [ 2 ❤ ] , [ K ♣ ] , [ J ♣ ] , [ 9 ❤ ]
53+
Card.print_pretty_cards(player1_hand)
54+
// > [ 5 ♦ ] , [ 2 ♣ ]
55+
Card.print_pretty_cards(player2_hand)
56+
// > [ 7 ♠ ] , [ 7 ❤ ]
57+
58+
59+
// Now let's evaluate their weights and see who's the winner
60+
p1_score = evaluator.evaluate(player1_hand, board)
61+
p2_score = evaluator.evaluate(player2_hand, board)
62+
63+
p1_class = evaluator.get_rank_class(p1_score)
64+
p2_class = evaluator.get_rank_class(p2_score)
65+
66+
console.log(`Player 1 hand rank = ${p1_score} (${evaluator.class_to_string(p1_class)})`)
67+
console.log(`Player 2 hand rank = ${p2_score} (${evaluator.class_to_string(p2_class)})`)
68+
// > Player 1 hand rank = 2414 (Three of a Kind)
69+
// > Player 2 hand rank = 3206 (Two Pair)
70+
71+
72+
// To get a more in-depth explanation
73+
const hands = [player1_hand, player2_hand]
74+
evaluator.hand_summary(board, hands)
75+
/*
76+
========== FLOP ==========
77+
Player 1 hand = Three of a Kind, percentage rank among all hands = 0.6756901634950415
78+
Player 2 hand = Two Pair, percentage rank among all hands = 0.5703564727954972
79+
Player 1 hand is currently winning.
80+
81+
========== TURN ==========
82+
Player 1 hand = Three of a Kind, percentage rank among all hands = 0.6764942374698473
83+
Player 2 hand = Two Pair, percentage rank among all hands = 0.5703564727954972
84+
Player 1 hand is currently winning.
85+
86+
========== RIVER ==========
87+
Player 1 hand = Three of a Kind, percentage rank among all hands = 0.6764942374698473
88+
Player 2 hand = Two Pair, percentage rank among all hands = 0.5703564727954972
89+
========== HAND OVER ==========
90+
Player 1 is the winner with a Three of a Kind
91+
*/
92+
```
93+
94+
## Todo
95+
- Add colors to suits
96+
- Camelcasing functions
97+
98+
## Credits
99+
- [worldveil/deuces](https://github.com/worldveil/deuces)
100+
101+
# License
102+
Copyright (c) 2020 Shaun

img/ss.png

12.1 KB
Loading

index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module.exports = {
2+
Card: require("./lib/Card"),
3+
Deck: require("./lib/Card"),
4+
Evaluator: require("./lib/Evaluator"),
5+
LookupTable: require("./lib/LookupTable")
6+
};

0 commit comments

Comments
 (0)