How cookpete/poker-odds works
Project type and purpose
• This is a Node.js‐based command-line tool (and companion JS library) called “poker-odds,” designed to calculate poker hand probabilities via Monte Carlo or exhaustive simulation.
• It provides both a CLI executable (installed globally via npm/yarn) and an exportable API (calculateEquity) for embedding in other JS projects.
File structure
• Top level
• Configuration: .gitignore, .npmignore, .travis.yml, package.json, CHANGELOG.md, LICENSE.md, README.md
• Data file: lookup.json (precomputed rank lookup table)
• src/ — business logic
• src/bin/
– generate-lookup.js → regenerates lookup.json
– poker-odds.js → CLI entrypoint for running odds calculations
• src/calculate.js → core simulation engine (Monte Carlo/exhaustive)
• src/console.js → command-line argument parsing, output formatting
• src/deck.js → deck & card‐dealing utilities
• src/rank.js → hand‐ranking logic using lookup.json
• test/ — unit tests for each module
README for additional insights
• Confirms CLI flags, API usage, default behaviors, and no external dependencies beyond Node.js
• Emphasizes two modes: Monte Carlo (iterations) and exhaustive
• Shows example outputs and library import signature
Main components
A. CLI Layer
• Bin wrapper (poker-odds.js) → invokes console.js
• Argument parser & formatter (console.js) → translates flags to function calls
B. Core Engine
• calculate.js → implements simulation loops, calls sub‐modules
C. Domain Modules
• deck.js → card generation, shuffling, dealing
• rank.js → hand evaluation, uses lookup.json table
D. Data Store
• lookup.json → precomputed 52-card lookup table for fast ranking
• generate-lookup.js → utility to rebuild lookup.json when rules change
E. External API
• calculateEquity export → available for programmatic use
F. Tests
• test suite for calculate, console, rank, utils
Relationships and interactions
• The CLI bin script calls console.js → console.js parses inputs and calls calculateEquity in calculate.js
• calculate.js orchestrates:
• deck.js for dealing cards
• rank.js for evaluating hands via lookup.json
• utils.js for random draws / combinations
• Data flows: user input → CLI → simulation → output back to console
• generate-lookup.js is a standalone tool that writes to lookup.json (not invoked by CLI)
• External consumers import calculateEquity directly, bypassing the CLI
Architectural patterns and design principles
• Modular separation: CLI vs core engine vs domain logic vs data
• Single Responsibility: each JS module has one concern
• Data-driven ranking: precomputed lookup.json speeds up hand evaluation
• Extensibility point: update lookup.json via generate-lookup, plug in custom deck rules if needed
Relevant technologies
• Node.js (no external npm dependencies)
• Standard CLI argument parsing (built-in)
• File I/O for lookup.json
• JSON data representation for quick lookups
Essential elements
• Don’t omit the generate-lookup utility—it’s the only way to refresh rank data
• Test suite tangentially or in an appendix to indicate coverage
• Clearly distinguish between binary entrypoints and library exports