Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enabled strict mode in tsconfig.json #2

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"tabWidth": 4,
"singleQuote": true,
"semi": true
}
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# poker-odds-machine

> Uses Monte Carlo simulation to estimate win probability of any poker hand.
Check it out in action at https://emileindik.com/projects/poker.html (Heroku will probably be sleepy and need to wake up, so give it a minute)
> Check it out in action at https://emileindik.com/projects/poker.html (Heroku will probably be sleepy and need to wake up, so give it a minute)

## Install

Expand All @@ -17,7 +18,7 @@ const input = {
* Hands of players, following the syntax below.
* A player can have a partial hand (one card specified) in order
* to have their next card randomly selected.
* If hands option not supplied, then numPlayers must be provided.
* If hands option not supplied, then numPlayers must be provided.
*/
hands: ['Ac,Kc', '2h,7d', 'Js'],
/**
Expand Down Expand Up @@ -54,12 +55,12 @@ const input = {
*/
returnTieHandStats: true,
/**
* Number of iterations in the Monte Carlo simluation to perform.
* Number of iterations in the Monte Carlo simulation to perform.
* The more iterations, the more accurate the returned probabilities,
* but the longer the calculation takes.
* Defaults to 1000.
*/
iterations: 1000000
iterations: 1000000,
};

const c = new Calculator(input);
Expand Down Expand Up @@ -185,6 +186,7 @@ console.log(s);
}
}
```

</details>

Disclaimer:
Expand All @@ -210,4 +212,5 @@ npm test
│ 8 │ 'straightFlush' │ 0.031083 │ 0.0308 │ -0.9105 │
└─────────┴─────────────────┴───────────┴─────────────┴─────────┘
```

The test calculates estimated probability for all hands and compares them against their true hypothetical value (% hypo).
17 changes: 17 additions & 0 deletions index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { describe, it, expect } from '@jest/globals';
import { Calculator, Input } from '.';

describe('Calculator', () => {
it('should show player 1 beating player 2 by at least 70%', () => {
const firstHand = 'Ac,Ad';
const secondHand = '7c,2d';
const input: Input = {
hands: [firstHand, secondHand],
numPlayers: 2,
iterations: 10000,
};
const calculator = new Calculator(input);
const results = calculator.simulate();
expect(results[firstHand].winPercent).toBeGreaterThan(70);
});
});
2 changes: 1 addition & 1 deletion index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export { Calculator } from './src/Game';
export { Input } from './src/types';
export { Input } from './src/types';
7 changes: 7 additions & 0 deletions jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { Config } from '@jest/types';

const config: Config.InitialOptions = {
preset: 'ts-jest',
testEnvironment: 'node',
};
export default config;
Loading