# deuces.js

> ![npm downloads](https://img.shields.io/npm/dm/deuces.js.svg?style=flat-square) !["Latest Release"](https://img.shields.io/npm/v/deuces.js.svg?style=flat-square) ![MIT license](https://img.shields.io/badge/license-MIT-green.svg?style=flat-square)

Latest version **0.0.2** (published 2020-02-19) · MIT license · 0 weekly downloads

## Install

```sh
npm install deuces.js
pnpm add deuces.js
yarn add deuces.js
bun add deuces.js
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.2 |
| Published | 2020-02-19 |
| First published | 2020-02-18 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 37.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 6 |
| Author | ShaunLWM |
| Maintainers | shaunlwm |

## Links

- npm: https://www.npmjs.com/package/deuces.js
- Repository: https://github.com/ShaunLWM/deuces.js
- Homepage: https://github.com/ShaunLWM/deuces.js#readme
- Issues: https://github.com/ShaunLWM/deuces.js/issues
- npm.io page: https://npm.io/package/deuces.js

## Dependencies (2)

- [chalk](https://npm.io/package/chalk.md) ^3.0.0
- [knuth-shuffle-seeded](https://npm.io/package/knuth-shuffle-seeded.md) ^1.0.6

## Recent versions

- 0.0.2 (latest) — 2020-02-19
- 0.0.1 — 2020-02-18

## README

# deuces.js

![npm downloads](https://img.shields.io/npm/dm/deuces.js.svg?style=flat-square)
!["Latest Release"](https://img.shields.io/npm/v/deuces.js.svg?style=flat-square)
![MIT license](https://img.shields.io/badge/license-MIT-green.svg?style=flat-square)

A Node.JS port of [deuces](https://github.com/worldveil/deuces) poker hand evaluation library.

![screenshot](img/ss.png "screenshot")

## Installation
```npm install --save deuces.js```

```yarn add deuces.js```

## Usage
Feel free to take a look in the example file in ```test/go.js```

```javascript
const { Card, Deck, Evaluator, LookupTable } = require("deuces.js");

// Create a new card
const card = Card.newCard("Qh"); // Queen of Hearts

// Create a hand of Queen of Spades and Ten of Hearts
const hand = [
    Card.newCard("Qs"),
    Card.newCard("Th")
];

const board = [
     Card.newCard("Ah"),
     Card.newCard("Kd"),
     Card.newCard("Jc")
];

// Instantiate an Evaluator to evaluate the results
const evaluator = new Evaluator();
const rank = evaluator.evaluate(board, hand)
console.log(`Rank for your hand is: ${rank}`);


// Create a Deck
const deck = new Deck();            // Create a new shuffled deck
board = deck.draw(5);               // Draw 5 cards from the deck
const player1_hand = deck.draw(2);  // player 1 will draw 2 cards
const player2_hand = deck.draw(2);  // player 2 will draw 2 cards


// Print out their drawn cards. second parameter denotes if you want it to be colored in console
Card.print_pretty_cards(board, true)
// > [ 2 ♦ ] , [ 2 ❤ ] , [ K ♣ ] , [ J ♣ ] , [ 9 ❤ ]
Card.print_pretty_cards(player1_hand, true)
// > [ 5 ♦ ] , [ 2 ♣ ]
Card.print_pretty_cards(player2_hand, true)
// > [ 7 ♠ ] , [ 7 ❤ ]


// Now let's evaluate their weights and see who's the winner
p1_score = evaluator.evaluate(player1_hand, board)
p2_score = evaluator.evaluate(player2_hand, board)

p1_class = evaluator.get_rank_class(p1_score)
p2_class = evaluator.get_rank_class(p2_score)

console.log(`Player 1 hand rank = ${p1_score} (${evaluator.class_to_string(p1_class)})`)
console.log(`Player 2 hand rank = ${p2_score} (${evaluator.class_to_string(p2_class)})`)
// > Player 1 hand rank = 2414 (Three of a Kind)
// > Player 2 hand rank = 3206 (Two Pair)


// To get a more in-depth explanation
const hands = [player1_hand, player2_hand]
evaluator.hand_summary(board, hands)
/*
========== FLOP ==========
Player 1 hand = Three of a Kind, percentage rank among all hands = 0.6756901634950415
Player 2 hand = Two Pair, percentage rank among all hands = 0.5703564727954972
Player 1 hand is currently winning.

========== TURN ==========
Player 1 hand = Three of a Kind, percentage rank among all hands = 0.6764942374698473
Player 2 hand = Two Pair, percentage rank among all hands = 0.5703564727954972
Player 1 hand is currently winning.

========== RIVER ==========
Player 1 hand = Three of a Kind, percentage rank among all hands = 0.6764942374698473
Player 2 hand = Two Pair, percentage rank among all hands = 0.5703564727954972
========== HAND OVER ==========
Player 1 is the winner with a Three of a Kind
*/
```

## Todo
- Camelcasing functions

## Credits
- [worldveil/deuces](https://github.com/worldveil/deuces)

# License
Copyright (c) 2020 Shaun

---
_Source: https://npm.io/package/deuces.js · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
