From dd605e8a66c43036880e6eb945ce4630464907d1 Mon Sep 17 00:00:00 2001 From: Jan-Peter von Hunnius Date: Mon, 11 May 2026 20:22:32 +0200 Subject: [PATCH] feat: add AlgorithmicEvaluator, migrate to log crate, fix flush value calculation - Add AlgorithmicEvaluator wrapper for direct hand evaluation without lookup tables, with proper Result-based error handling - Replace all println! and #[cfg(debug_assertions)] debug output with log crate macros (log::info!, log::debug!, log::warn!) - Fix calculate_flush_value to use base-13 encoding for unique flush hand values instead of simple linear sum - Fix is_straight to use cleaner control flow for regular and wheel straight detection - Remove jump table HighCard/value=0 guard in evaluate_5_card to simplify evaluation path - Add evaluate_n_card_hand_public as pub(crate) for AlgorithmicEvaluator - Add .gitignore to exclude target/ and .idea/ from version control - Add comprehensive tests for AlgorithmicEvaluator (14 test cases) - Update README with new API usage examples - Add log dependency to Cargo.toml - Add placeholder modules for future implementations (tables_new, benchmark_utils, integration_utils, test_utils) --- .gitignore | 10 + Cargo.lock | 1145 +++++++++++++++++ README.md | 44 +- holdem_core/Cargo.toml | 5 +- .../src/evaluator/algorithmic_evaluator.rs | 67 + .../evaluator/algorithmic_evaluator_test.rs | 200 +++ holdem_core/src/evaluator/benchmark_utils.rs | 4 + holdem_core/src/evaluator/benchmarks.rs | 16 +- holdem_core/src/evaluator/evaluator.rs | 115 +- holdem_core/src/evaluator/examples.rs | 136 +- holdem_core/src/evaluator/integration.rs | 8 +- .../src/evaluator/integration_utils.rs | 4 + holdem_core/src/evaluator/property_tests.rs | 60 +- holdem_core/src/evaluator/tables.rs | 72 +- holdem_core/src/evaluator/tables_new.rs | 4 + holdem_core/src/evaluator/test_utils.rs | 4 + 16 files changed, 1666 insertions(+), 228 deletions(-) create mode 100644 .gitignore create mode 100644 Cargo.lock create mode 100644 holdem_core/src/evaluator/algorithmic_evaluator.rs create mode 100644 holdem_core/src/evaluator/algorithmic_evaluator_test.rs create mode 100644 holdem_core/src/evaluator/benchmark_utils.rs create mode 100644 holdem_core/src/evaluator/integration_utils.rs create mode 100644 holdem_core/src/evaluator/tables_new.rs create mode 100644 holdem_core/src/evaluator/test_utils.rs diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..adc91bf --- /dev/null +++ b/.gitignore @@ -0,0 +1,10 @@ +# Build artifacts +/target + +# IDE +.idea/ +*.iml + +# OS +.DS_Store +Thumbs.db diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..8a00f67 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,1145 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "android_system_properties" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" +dependencies = [ + "libc", +] + +[[package]] +name = "anyhow" +version = "1.0.102" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f202df86484c868dbad7eaa557ef785d5c66295e41b460ef922eca0723b842c" + +[[package]] +name = "autocfg" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8" + +[[package]] +name = "bincode" +version = "1.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1f45e9417d87227c7a56d22e471c6206462cba514c7590c09aff4cf6d1ddcad" +dependencies = [ + "serde", +] + +[[package]] +name = "bit-set" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08807e080ed7f9d5433fa9b275196cfc35414f66a0c79d864dc51a0d825231a3" +dependencies = [ + "bit-vec", +] + +[[package]] +name = "bit-vec" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e764a1d40d510daf35e07be9eb06e75770908c27d411ee6c92109c9840eaaf7" + +[[package]] +name = "bitflags" +version = "2.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4512299f36f043ab09a583e57bceb5a5aab7a73db1805848e8fef3c9e8c78b3" + +[[package]] +name = "block-buffer" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" +dependencies = [ + "generic-array", +] + +[[package]] +name = "bumpalo" +version = "3.20.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d20789868f4b01b2f2caec9f5c4e0213b41e3e5702a50157d699ae31ced2fcb" + +[[package]] +name = "cc" +version = "1.2.62" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1dce859f0832a7d088c4f1119888ab94ef4b5d6795d1ce05afb7fe159d79f98" +dependencies = [ + "find-msvc-tools", + "shlex", +] + +[[package]] +name = "cfg-if" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" + +[[package]] +name = "chrono" +version = "0.4.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c673075a2e0e5f4a1dde27ce9dee1ea4558c7ffe648f576438a20ca1d2acc4b0" +dependencies = [ + "iana-time-zone", + "js-sys", + "num-traits", + "serde", + "wasm-bindgen", + "windows-link", +] + +[[package]] +name = "console" +version = "0.15.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "054ccb5b10f9f2cbf51eb355ca1d05c2d279ce1804688d0db74b4733a5aeafd8" +dependencies = [ + "encode_unicode", + "libc", + "once_cell", + "unicode-width", + "windows-sys 0.59.0", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" + +[[package]] +name = "cpufeatures" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59ed5838eebb26a2bb2e58f6d5b5316989ae9d08bab10e0e6d103e656d1b0280" +dependencies = [ + "libc", +] + +[[package]] +name = "crypto-common" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78c8292055d1c1df0cce5d180393dc8cce0abec0a7102adb6c7b1eef6016d60a" +dependencies = [ + "generic-array", + "typenum", +] + +[[package]] +name = "digest" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" +dependencies = [ + "block-buffer", + "crypto-common", +] + +[[package]] +name = "encode_unicode" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34aa73646ffb006b8f5147f3dc182bd4bcb190227ce861fc4a4844bf8e3cb2c0" + +[[package]] +name = "equivalent" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" + +[[package]] +name = "errno" +version = "0.3.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb" +dependencies = [ + "libc", + "windows-sys 0.61.2", +] + +[[package]] +name = "fastrand" +version = "2.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f1f227452a390804cdb637b74a86990f2a7d7ba4b7d5693aac9b4dd6defd8d6" + +[[package]] +name = "find-msvc-tools" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5baebc0774151f905a1a2cc41989300b1e6fbb29aff0ceffa1064fdd3088d582" + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "foldhash" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2" + +[[package]] +name = "futures-core" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e3450815272ef58cec6d564423f6e755e25379b217b0bc688e295ba24df6b1d" + +[[package]] +name = "futures-task" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "037711b3d59c33004d3856fbdc83b99d4ff37a24768fa1be9ce3538a1cde4393" + +[[package]] +name = "futures-util" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "389ca41296e6190b48053de0321d02a77f32f8a5d2461dd38762c0593805c6d6" +dependencies = [ + "futures-core", + "futures-task", + "pin-project-lite", + "slab", +] + +[[package]] +name = "generic-array" +version = "0.14.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" +dependencies = [ + "typenum", + "version_check", +] + +[[package]] +name = "getrandom" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "899def5c37c4fd7b2664648c28120ecec138e4d395b459e5ca34f9cce2dd77fd" +dependencies = [ + "cfg-if", + "libc", + "r-efi 5.3.0", + "wasip2", +] + +[[package]] +name = "getrandom" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0de51e6874e94e7bf76d726fc5d13ba782deca734ff60d5bb2fb2607c7406555" +dependencies = [ + "cfg-if", + "libc", + "r-efi 6.0.0", + "wasip2", + "wasip3", +] + +[[package]] +name = "hashbrown" +version = "0.15.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9229cfe53dfd69f0609a49f65461bd93001ea1ef889cd5529dd176593f5338a1" +dependencies = [ + "foldhash", +] + +[[package]] +name = "hashbrown" +version = "0.17.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed5909b6e89a2db4456e54cd5f673791d7eca6732202bbf2a9cc504fe2f9b84a" + +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + +[[package]] +name = "holdem_core" +version = "0.1.0" +dependencies = [ + "bincode", + "chrono", + "indicatif", + "log", + "once_cell", + "proptest", + "rand", + "serde", + "serde_json", + "sha2", + "tempfile", + "toml", +] + +[[package]] +name = "iana-time-zone" +version = "0.1.65" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e31bc9ad994ba00e440a8aa5c9ef0ec67d5cb5e5cb0cc7f8b744a35b389cc470" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "log", + "wasm-bindgen", + "windows-core", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" +dependencies = [ + "cc", +] + +[[package]] +name = "id-arena" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d3067d79b975e8844ca9eb072e16b31c3c1c36928edf9c6789548c524d0d954" + +[[package]] +name = "indexmap" +version = "2.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d466e9454f08e4a911e14806c24e16fba1b4c121d1ea474396f396069cf949d9" +dependencies = [ + "equivalent", + "hashbrown 0.17.1", + "serde", + "serde_core", +] + +[[package]] +name = "indicatif" +version = "0.17.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "183b3088984b400f4cfac3620d5e076c84da5364016b4f49473de574b2586235" +dependencies = [ + "console", + "number_prefix", + "portable-atomic", + "unicode-width", + "web-time", +] + +[[package]] +name = "itoa" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682" + +[[package]] +name = "js-sys" +version = "0.3.98" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67df7112613f8bfd9150013a0314e196f4800d3201ae742489d999db2f979f08" +dependencies = [ + "cfg-if", + "futures-util", + "once_cell", + "wasm-bindgen", +] + +[[package]] +name = "leb128fmt" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09edd9e8b54e49e587e4f6295a7d29c3ea94d469cb40ab8ca70b288248a81db2" + +[[package]] +name = "libc" +version = "0.2.186" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68ab91017fe16c622486840e4c83c9a37afeff978bd239b5293d61ece587de66" + +[[package]] +name = "linux-raw-sys" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a66949e030da00e8c7d4434b251670a91556f4144941d37452769c25d58a53" + +[[package]] +name = "log" +version = "0.4.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e5032e24019045c762d3c0f28f5b6b8bbf38563a65908389bf7978758920897" + +[[package]] +name = "memchr" +version = "2.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8ca58f447f06ed17d5fc4043ce1b10dd205e060fb3ce5b979b8ed8e59ff3f79" + +[[package]] +name = "num-traits" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" +dependencies = [ + "autocfg", +] + +[[package]] +name = "number_prefix" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "830b246a0e5f20af87141b25c173cd1b609bd7779a4617d6ec582abaf90870f3" + +[[package]] +name = "once_cell" +version = "1.21.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50" + +[[package]] +name = "pin-project-lite" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a89322df9ebe1c1578d689c92318e070967d1042b512afbe49518723f4e6d5cd" + +[[package]] +name = "portable-atomic" +version = "1.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c33a9471896f1c69cecef8d20cbe2f7accd12527ce60845ff44c153bb2a21b49" + +[[package]] +name = "ppv-lite86" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85eae3c4ed2f50dcfe72643da4befc30deadb458a9b590d720cde2f2b1e97da9" +dependencies = [ + "zerocopy", +] + +[[package]] +name = "prettyplease" +version = "0.2.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "479ca8adacdd7ce8f1fb39ce9ecccbfe93a3f1344b3d0d97f20bc0196208f62b" +dependencies = [ + "proc-macro2", + "syn", +] + +[[package]] +name = "proc-macro2" +version = "1.0.106" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8fd00f0bb2e90d81d1044c2b32617f68fcb9fa3bb7640c23e9c748e53fb30934" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "proptest" +version = "1.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4b45fcc2344c680f5025fe57779faef368840d0bd1f42f216291f0dc4ace4744" +dependencies = [ + "bit-set", + "bit-vec", + "bitflags", + "num-traits", + "rand", + "rand_chacha", + "rand_xorshift", + "regex-syntax", + "rusty-fork", + "tempfile", + "unarray", +] + +[[package]] +name = "quick-error" +version = "1.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" + +[[package]] +name = "quote" +version = "1.0.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41f2619966050689382d2b44f664f4bc593e129785a36d6ee376ddf37259b924" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "r-efi" +version = "5.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f" + +[[package]] +name = "r-efi" +version = "6.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8dcc9c7d52a811697d2151c701e0d08956f92b0e24136cf4cf27b57a6a0d9bf" + +[[package]] +name = "rand" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44c5af06bb1b7d3216d91932aed5265164bf384dc89cd6ba05cf59a35f5f76ea" +dependencies = [ + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3022b5f1df60f26e1ffddd6c66e8aa15de382ae63b3a0c1bfc0e4d3e3f325cb" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76afc826de14238e6e8c374ddcc1fa19e374fd8dd986b0d2af0d02377261d83c" +dependencies = [ + "getrandom 0.3.4", +] + +[[package]] +name = "rand_xorshift" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "513962919efc330f829edb2535844d1b912b0fbe2ca165d613e4e8788bb05a5a" +dependencies = [ + "rand_core", +] + +[[package]] +name = "regex-syntax" +version = "0.8.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc897dd8d9e8bd1ed8cdad82b5966c3e0ecae09fb1907d58efaa013543185d0a" + +[[package]] +name = "rustix" +version = "1.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6fe4565b9518b83ef4f91bb47ce29620ca828bd32cb7e408f0062e9930ba190" +dependencies = [ + "bitflags", + "errno", + "libc", + "linux-raw-sys", + "windows-sys 0.61.2", +] + +[[package]] +name = "rustversion" +version = "1.0.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d" + +[[package]] +name = "rusty-fork" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc6bf79ff24e648f6da1f8d1f011e9cac26491b619e6b9280f2b47f1774e6ee2" +dependencies = [ + "fnv", + "quick-error", + "tempfile", + "wait-timeout", +] + +[[package]] +name = "semver" +version = "1.0.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a7852d02fc848982e0c167ef163aaff9cd91dc640ba85e263cb1ce46fae51cd" + +[[package]] +name = "serde" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e" +dependencies = [ + "serde_core", + "serde_derive", +] + +[[package]] +name = "serde_core" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.149" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "83fc039473c5595ace860d8c4fafa220ff474b3fc6bfdb4293327f1a37e94d86" +dependencies = [ + "itoa", + "memchr", + "serde", + "serde_core", + "zmij", +] + +[[package]] +name = "serde_spanned" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6662b5879511e06e8999a8a235d848113e942c9124f211511b16466ee2995f26" +dependencies = [ + "serde_core", +] + +[[package]] +name = "sha2" +version = "0.10.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7507d819769d01a365ab707794a4084392c824f54a7a6a7862f8c3d0892b283" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", +] + +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + +[[package]] +name = "slab" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c790de23124f9ab44544d7ac05d60440adc586479ce501c1d6d7da3cd8c9cf5" + +[[package]] +name = "syn" +version = "2.0.117" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e665b8803e7b1d2a727f4023456bbbbe74da67099c585258af0ad9c5013b9b99" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "tempfile" +version = "3.27.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32497e9a4c7b38532efcdebeef879707aa9f794296a4f0244f6f69e9bc8574bd" +dependencies = [ + "fastrand", + "getrandom 0.4.2", + "once_cell", + "rustix", + "windows-sys 0.61.2", +] + +[[package]] +name = "toml" +version = "0.9.12+spec-1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf92845e79fc2e2def6a5d828f0801e29a2f8acc037becc5ab08595c7d5e9863" +dependencies = [ + "indexmap", + "serde_core", + "serde_spanned", + "toml_datetime", + "toml_parser", + "toml_writer", + "winnow 0.7.15", +] + +[[package]] +name = "toml_datetime" +version = "0.7.5+spec-1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92e1cfed4a3038bc5a127e35a2d360f145e1f4b971b551a2ba5fd7aedf7e1347" +dependencies = [ + "serde_core", +] + +[[package]] +name = "toml_parser" +version = "1.1.2+spec-1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2abe9b86193656635d2411dc43050282ca48aa31c2451210f4202550afb7526" +dependencies = [ + "winnow 1.0.2", +] + +[[package]] +name = "toml_writer" +version = "1.1.1+spec-1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "756daf9b1013ebe47a8776667b466417e2d4c5679d441c26230efd9ef78692db" + +[[package]] +name = "typenum" +version = "1.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "40ce102ab67701b8526c123c1bab5cbe42d7040ccfd0f64af1a385808d2f43de" + +[[package]] +name = "unarray" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eaea85b334db583fe3274d12b4cd1880032beab409c0d774be044d4480ab9a94" + +[[package]] +name = "unicode-ident" +version = "1.0.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75" + +[[package]] +name = "unicode-width" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4ac048d71ede7ee76d585517add45da530660ef4390e49b098733c6e897f254" + +[[package]] +name = "unicode-xid" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853" + +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + +[[package]] +name = "wait-timeout" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ac3b126d3914f9849036f826e054cbabdc8519970b8998ddaf3b5bd3c65f11" +dependencies = [ + "libc", +] + +[[package]] +name = "wasip2" +version = "1.0.3+wasi-0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "20064672db26d7cdc89c7798c48a0fdfac8213434a1186e5ef29fd560ae223d6" +dependencies = [ + "wit-bindgen 0.57.1", +] + +[[package]] +name = "wasip3" +version = "0.4.0+wasi-0.3.0-rc-2026-01-06" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5428f8bf88ea5ddc08faddef2ac4a67e390b88186c703ce6dbd955e1c145aca5" +dependencies = [ + "wit-bindgen 0.51.0", +] + +[[package]] +name = "wasm-bindgen" +version = "0.2.121" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49ace1d07c165b0864824eee619580c4689389afa9dc9ed3a4c75040d82e6790" +dependencies = [ + "cfg-if", + "once_cell", + "rustversion", + "wasm-bindgen-macro", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.121" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e68e6f4afd367a562002c05637acb8578ff2dea1943df76afb9e83d177c8578" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.121" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d95a9ec35c64b2a7cb35d3fead40c4238d0940c86d107136999567a4703259f2" +dependencies = [ + "bumpalo", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.121" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4e0100b01e9f0d03189a92b96772a1fb998639d981193d7dbab487302513441" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "wasm-encoder" +version = "0.244.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "990065f2fe63003fe337b932cfb5e3b80e0b4d0f5ff650e6985b1048f62c8319" +dependencies = [ + "leb128fmt", + "wasmparser", +] + +[[package]] +name = "wasm-metadata" +version = "0.244.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb0e353e6a2fbdc176932bbaab493762eb1255a7900fe0fea1a2f96c296cc909" +dependencies = [ + "anyhow", + "indexmap", + "wasm-encoder", + "wasmparser", +] + +[[package]] +name = "wasmparser" +version = "0.244.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47b807c72e1bac69382b3a6fb3dbe8ea4c0ed87ff5629b8685ae6b9a611028fe" +dependencies = [ + "bitflags", + "hashbrown 0.15.5", + "indexmap", + "semver", +] + +[[package]] +name = "web-time" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a6580f308b1fad9207618087a65c04e7a10bc77e02c8e84e9b00dd4b12fa0bb" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "windows-core" +version = "0.62.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8e83a14d34d0623b51dce9581199302a221863196a1dde71a7663a4c2be9deb" +dependencies = [ + "windows-implement", + "windows-interface", + "windows-link", + "windows-result", + "windows-strings", +] + +[[package]] +name = "windows-implement" +version = "0.60.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "053e2e040ab57b9dc951b72c264860db7eb3b0200ba345b4e4c3b14f67855ddf" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "windows-interface" +version = "0.59.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f316c4a2570ba26bbec722032c4099d8c8bc095efccdc15688708623367e358" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "windows-link" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" + +[[package]] +name = "windows-result" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7781fa89eaf60850ac3d2da7af8e5242a5ea78d1a11c49bf2910bb5a73853eb5" +dependencies = [ + "windows-link", +] + +[[package]] +name = "windows-strings" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7837d08f69c77cf6b07689544538e017c1bfcf57e34b4c0ff58e6c2cd3b37091" +dependencies = [ + "windows-link", +] + +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-sys" +version = "0.61.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc" +dependencies = [ + "windows-link", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_gnullvm", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "winnow" +version = "0.7.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df79d97927682d2fd8adb29682d1140b343be4ac0f08fd68b7765d9c059d3945" + +[[package]] +name = "winnow" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2ee1708bef14716a11bae175f579062d4554d95be2c6829f518df847b7b3fdd0" + +[[package]] +name = "wit-bindgen" +version = "0.51.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7249219f66ced02969388cf2bb044a09756a083d0fab1e566056b04d9fbcaa5" +dependencies = [ + "wit-bindgen-rust-macro", +] + +[[package]] +name = "wit-bindgen" +version = "0.57.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ebf944e87a7c253233ad6766e082e3cd714b5d03812acc24c318f549614536e" + +[[package]] +name = "wit-bindgen-core" +version = "0.51.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea61de684c3ea68cb082b7a88508a8b27fcc8b797d738bfc99a82facf1d752dc" +dependencies = [ + "anyhow", + "heck", + "wit-parser", +] + +[[package]] +name = "wit-bindgen-rust" +version = "0.51.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b7c566e0f4b284dd6561c786d9cb0142da491f46a9fbed79ea69cdad5db17f21" +dependencies = [ + "anyhow", + "heck", + "indexmap", + "prettyplease", + "syn", + "wasm-metadata", + "wit-bindgen-core", + "wit-component", +] + +[[package]] +name = "wit-bindgen-rust-macro" +version = "0.51.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c0f9bfd77e6a48eccf51359e3ae77140a7f50b1e2ebfe62422d8afdaffab17a" +dependencies = [ + "anyhow", + "prettyplease", + "proc-macro2", + "quote", + "syn", + "wit-bindgen-core", + "wit-bindgen-rust", +] + +[[package]] +name = "wit-component" +version = "0.244.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d66ea20e9553b30172b5e831994e35fbde2d165325bec84fc43dbf6f4eb9cb2" +dependencies = [ + "anyhow", + "bitflags", + "indexmap", + "log", + "serde", + "serde_derive", + "serde_json", + "wasm-encoder", + "wasm-metadata", + "wasmparser", + "wit-parser", +] + +[[package]] +name = "wit-parser" +version = "0.244.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ecc8ac4bc1dc3381b7f59c34f00b67e18f910c2c0f50015669dde7def656a736" +dependencies = [ + "anyhow", + "id-arena", + "indexmap", + "log", + "semver", + "serde", + "serde_derive", + "serde_json", + "unicode-xid", + "wasmparser", +] + +[[package]] +name = "zerocopy" +version = "0.8.48" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eed437bf9d6692032087e337407a86f04cd8d6a16a37199ed57949d415bd68e9" +dependencies = [ + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.8.48" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70e3cd084b1788766f53af483dd21f93881ff30d7320490ec3ef7526d203bad4" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "zmij" +version = "1.0.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8848ee67ecc8aedbaf3e4122217aff892639231befc6a1b58d29fff4c2cabaa" diff --git a/README.md b/README.md index 13cee35..342e0f7 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # Poker Testbed - Java-Compatible Hand Evaluator for Bot Testing -[![Crates.io](https://img.shields.io/crates/v/poker-api.svg)](https://crates.io/crates/poker-api) -[![Documentation](https://docs.rs/poker-api/badge.svg)](https://docs.rs/poker-api) +[![Crates.io](https://img.shields.io/crates/v/holdem_core.svg)](https://crates.io/crates/holdem_core) +[![Documentation](https://docs.rs/holdem_core/badge.svg)](https://docs.rs/holdem_core) [![License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE) A comprehensive poker bot testing framework with Java-compatible hand evaluation. This library implements the Meerkat API algorithm with full Java compatibility, specifically designed for automated poker bot testing, development, and integration with existing poker tools. @@ -50,31 +50,39 @@ Add this to your `Cargo.toml`: ```toml [dependencies] -poker-api = "0.1.0" +holdem_core = "0.1.0" ``` ## Quick Start - Bot Testing ```rust -use holdem_core::hand_evaluator::LookupHandEvaluator; -use holdem_core::api::{hand::Hand, card::Card}; +use holdem_core::{Card, Hand, HoleCards, Board, Evaluator}; +use std::str::FromStr; -// Initialize Java-compatible evaluator for bot testing -let evaluator = LookupHandEvaluator::new().unwrap(); +// Create cards from string notation +let ace_spades = Card::from_str("As").unwrap(); +let king_spades = Card::from_str("Ks").unwrap(); -// Create hole cards for bot analysis -let mut hole_cards = Hand::new(); -hole_cards.add_card(Card::from_string("As").unwrap()).unwrap(); -hole_cards.add_card(Card::from_string("Ks").unwrap()).unwrap(); +// Create hole cards from notation +let hole_cards = HoleCards::from_notation("AKs").unwrap(); -// Evaluate hand strength for bot decision making -let rank = evaluator.rank_hand(&hole_cards); -println!("Hole card rank: {}", rank); // Lower = stronger hand +// Create a board with community cards +let board = Board::new() + .with_flop([ + Card::from_str("Qh").unwrap(), + Card::from_str("Jh").unwrap(), + Card::from_str("Th").unwrap(), + ]).unwrap() + .with_turn(Card::from_str("2c").unwrap()).unwrap() + .with_river(Card::from_str("3d").unwrap()).unwrap(); -// Use rank for bot strategy decisions -if rank < 1000 { // Strong hand threshold - println!("Bot: This is a premium starting hand!"); -} +// Create a hand from hole cards and board +let hand = Hand::from_hole_cards_and_board(&hole_cards, &board).unwrap(); + +// Evaluate the hand +let evaluator = Evaluator::new().unwrap(); +let hand_value = evaluator.evaluate_hand(&hand); +println!("Hand rank: {:?}", hand_value.rank); ``` ## Bot Testing Capabilities diff --git a/holdem_core/Cargo.toml b/holdem_core/Cargo.toml index c73665e..7f036ae 100644 --- a/holdem_core/Cargo.toml +++ b/holdem_core/Cargo.toml @@ -8,10 +8,10 @@ readme = "README.md" license = "MIT" repository = "https://github.com/jhunnius/rusty_marvin" documentation = "https://docs.rs/holdem_core" -homepage = "https://github.com/your-org/holdem_core" +homepage = "https://github.com/jhunnius/rusty_marvin" keywords = ["poker", "bot-testing", "texas-holdem", "testbed"] categories = ["games", "api-bindings", "mathematics"] -exclude = ["docs/*", "target/*", "*.md"] +exclude = ["docs/*", "target/*"] [dependencies] serde = { version = "1.0", features = ["derive"] } @@ -24,6 +24,7 @@ tempfile = "3.23.0" once_cell = "1.19" chrono = { version = "0.4", features = ["serde"] } indicatif = "0.17" +log = "0.4" [dev-dependencies] proptest = "1.0" diff --git a/holdem_core/src/evaluator/algorithmic_evaluator.rs b/holdem_core/src/evaluator/algorithmic_evaluator.rs new file mode 100644 index 0000000..b0855be --- /dev/null +++ b/holdem_core/src/evaluator/algorithmic_evaluator.rs @@ -0,0 +1,67 @@ +//! Algorithmic hand evaluator for direct poker hand evaluation. +//! +//! This module provides a standalone evaluator that uses pure algorithmic +//! methods (no lookup tables) for evaluating poker hands. It wraps the +//! direct evaluation logic from [`Evaluator::evaluate_5_card_direct`]. + +use crate::Card; +use super::errors::EvaluatorError; +use super::evaluator::{Evaluator, HandValue}; +use std::sync::Arc; + +/// Statistics tracking for evaluation operations. +#[derive(Debug, Clone, Default)] +pub struct EvaluationStats { + /// Total number of evaluations performed. + pub total_evaluations: u64, + /// Average time per evaluation in nanoseconds. + pub average_time_ns: u64, + /// Total time spent evaluating in nanoseconds. + pub total_time_ns: u64, +} + +/// Algorithmic poker hand evaluator. +/// +/// Performs direct hand evaluation without relying on lookup tables. +/// Delegates to the same core algorithm used by [`Evaluator::evaluate_5_card_direct`]. +#[derive(Debug, Clone)] +pub struct AlgorithmicEvaluator { + inner: Arc, + stats: EvaluationStats, +} + +impl AlgorithmicEvaluator { + /// Create a new algorithmic evaluator instance. + pub fn new() -> Result { + let inner = Evaluator::new()?; + Ok(Self { + inner: Arc::new(inner), + stats: EvaluationStats::default(), + }) + } + + /// Evaluate a 5-card hand directly using the algorithmic approach. + pub fn evaluate_5_card_direct(&self, cards: &[Card; 5]) -> HandValue { + self.inner.evaluate_5_card_direct(cards) + } + + /// Evaluate a 6-card hand, finding the best 5-card combination. + pub fn evaluate_6_card(&self, cards: &[Card; 6]) -> HandValue { + self.inner.evaluate_n_card_hand_public(cards) + } + + /// Evaluate a 7-card hand, finding the best 5-card combination. + pub fn evaluate_7_card(&self, cards: &[Card; 7]) -> HandValue { + self.inner.evaluate_n_card_hand_public(cards) + } + + /// Get a reference to the current evaluation statistics. + pub fn stats(&self) -> &EvaluationStats { + &self.stats + } + + /// Reset the evaluation statistics. + pub fn reset_stats(&mut self) { + self.stats = EvaluationStats::default(); + } +} diff --git a/holdem_core/src/evaluator/algorithmic_evaluator_test.rs b/holdem_core/src/evaluator/algorithmic_evaluator_test.rs new file mode 100644 index 0000000..647c4ca --- /dev/null +++ b/holdem_core/src/evaluator/algorithmic_evaluator_test.rs @@ -0,0 +1,200 @@ +//! Tests for the algorithmic evaluator. + +use super::algorithmic_evaluator::AlgorithmicEvaluator; +use super::evaluator::HandRank; +use crate::Card; +use std::str::FromStr; + +#[test] +fn test_new_evaluator() { + let evaluator = AlgorithmicEvaluator::new(); + assert!(evaluator.is_ok()); +} + +#[test] +fn test_royal_flush() { + let evaluator = AlgorithmicEvaluator::new().unwrap(); + let cards = [ + Card::from_str("As").unwrap(), + Card::from_str("Ks").unwrap(), + Card::from_str("Qs").unwrap(), + Card::from_str("Js").unwrap(), + Card::from_str("Ts").unwrap(), + ]; + let result = evaluator.evaluate_5_card_direct(&cards); + assert_eq!(result.rank, HandRank::RoyalFlush); +} + +#[test] +fn test_straight_flush() { + let evaluator = AlgorithmicEvaluator::new().unwrap(); + let cards = [ + Card::from_str("9s").unwrap(), + Card::from_str("Ks").unwrap(), + Card::from_str("Qs").unwrap(), + Card::from_str("Js").unwrap(), + Card::from_str("Ts").unwrap(), + ]; + let result = evaluator.evaluate_5_card_direct(&cards); + assert_eq!(result.rank, HandRank::StraightFlush); +} + +#[test] +fn test_four_of_a_kind() { + let evaluator = AlgorithmicEvaluator::new().unwrap(); + let cards = [ + Card::from_str("As").unwrap(), + Card::from_str("Ah").unwrap(), + Card::from_str("Ad").unwrap(), + Card::from_str("Ac").unwrap(), + Card::from_str("Ks").unwrap(), + ]; + let result = evaluator.evaluate_5_card_direct(&cards); + assert_eq!(result.rank, HandRank::FourOfAKind); +} + +#[test] +fn test_full_house() { + let evaluator = AlgorithmicEvaluator::new().unwrap(); + let cards = [ + Card::from_str("As").unwrap(), + Card::from_str("Ah").unwrap(), + Card::from_str("Ad").unwrap(), + Card::from_str("Ks").unwrap(), + Card::from_str("Kh").unwrap(), + ]; + let result = evaluator.evaluate_5_card_direct(&cards); + assert_eq!(result.rank, HandRank::FullHouse); +} + +#[test] +fn test_flush() { + let evaluator = AlgorithmicEvaluator::new().unwrap(); + let cards = [ + Card::from_str("As").unwrap(), + Card::from_str("Ks").unwrap(), + Card::from_str("Qs").unwrap(), + Card::from_str("Js").unwrap(), + Card::from_str("9s").unwrap(), + ]; + let result = evaluator.evaluate_5_card_direct(&cards); + assert_eq!(result.rank, HandRank::Flush); +} + +#[test] +fn test_straight() { + let evaluator = AlgorithmicEvaluator::new().unwrap(); + let cards = [ + Card::from_str("As").unwrap(), + Card::from_str("Kh").unwrap(), + Card::from_str("Qd").unwrap(), + Card::from_str("Jc").unwrap(), + Card::from_str("Ts").unwrap(), + ]; + let result = evaluator.evaluate_5_card_direct(&cards); + assert_eq!(result.rank, HandRank::Straight); +} + +#[test] +fn test_wheel_straight() { + let evaluator = AlgorithmicEvaluator::new().unwrap(); + let cards = [ + Card::from_str("As").unwrap(), + Card::from_str("2h").unwrap(), + Card::from_str("3d").unwrap(), + Card::from_str("4c").unwrap(), + Card::from_str("5s").unwrap(), + ]; + let result = evaluator.evaluate_5_card_direct(&cards); + assert_eq!(result.rank, HandRank::Straight); +} + +#[test] +fn test_three_of_a_kind() { + let evaluator = AlgorithmicEvaluator::new().unwrap(); + let cards = [ + Card::from_str("As").unwrap(), + Card::from_str("Ah").unwrap(), + Card::from_str("Ad").unwrap(), + Card::from_str("Ks").unwrap(), + Card::from_str("Qh").unwrap(), + ]; + let result = evaluator.evaluate_5_card_direct(&cards); + assert_eq!(result.rank, HandRank::ThreeOfAKind); +} + +#[test] +fn test_two_pair() { + let evaluator = AlgorithmicEvaluator::new().unwrap(); + let cards = [ + Card::from_str("As").unwrap(), + Card::from_str("Ah").unwrap(), + Card::from_str("Ks").unwrap(), + Card::from_str("Kh").unwrap(), + Card::from_str("Qd").unwrap(), + ]; + let result = evaluator.evaluate_5_card_direct(&cards); + assert_eq!(result.rank, HandRank::TwoPair); +} + +#[test] +fn test_pair() { + let evaluator = AlgorithmicEvaluator::new().unwrap(); + let cards = [ + Card::from_str("As").unwrap(), + Card::from_str("Ah").unwrap(), + Card::from_str("Ks").unwrap(), + Card::from_str("Qh").unwrap(), + Card::from_str("Jd").unwrap(), + ]; + let result = evaluator.evaluate_5_card_direct(&cards); + assert_eq!(result.rank, HandRank::Pair); +} + +#[test] +fn test_high_card() { + let evaluator = AlgorithmicEvaluator::new().unwrap(); + let cards = [ + Card::from_str("As").unwrap(), + Card::from_str("Kh").unwrap(), + Card::from_str("Qd").unwrap(), + Card::from_str("Jc").unwrap(), + Card::from_str("9s").unwrap(), + ]; + let result = evaluator.evaluate_5_card_direct(&cards); + assert_eq!(result.rank, HandRank::HighCard); +} + +#[test] +fn test_hand_rank_ordering() { + let evaluator = AlgorithmicEvaluator::new().unwrap(); + + let royal_flush = [ + Card::from_str("As").unwrap(), + Card::from_str("Ks").unwrap(), + Card::from_str("Qs").unwrap(), + Card::from_str("Js").unwrap(), + Card::from_str("Ts").unwrap(), + ]; + let four_of_a_kind = [ + Card::from_str("As").unwrap(), + Card::from_str("Ah").unwrap(), + Card::from_str("Ad").unwrap(), + Card::from_str("Ac").unwrap(), + Card::from_str("Ks").unwrap(), + ]; + + let rf = evaluator.evaluate_5_card_direct(&royal_flush); + let foak = evaluator.evaluate_5_card_direct(&four_of_a_kind); + + assert!(rf.rank as u8 > foak.rank as u8); +} + +#[test] +fn test_stats_initially_default() { + let evaluator = AlgorithmicEvaluator::new().unwrap(); + let stats = evaluator.stats(); + assert_eq!(stats.total_evaluations, 0); + assert_eq!(stats.average_time_ns, 0); + assert_eq!(stats.total_time_ns, 0); +} diff --git a/holdem_core/src/evaluator/benchmark_utils.rs b/holdem_core/src/evaluator/benchmark_utils.rs new file mode 100644 index 0000000..31fb8a2 --- /dev/null +++ b/holdem_core/src/evaluator/benchmark_utils.rs @@ -0,0 +1,4 @@ +//! Benchmark utilities for the hand evaluator. +//! +//! This module provides helper functions and data structures for benchmarking +//! hand evaluation performance. diff --git a/holdem_core/src/evaluator/benchmarks.rs b/holdem_core/src/evaluator/benchmarks.rs index 31f11d7..0206775 100644 --- a/holdem_core/src/evaluator/benchmarks.rs +++ b/holdem_core/src/evaluator/benchmarks.rs @@ -321,12 +321,12 @@ impl JumpTableBenchmark { /// Print benchmark results in a formatted table pub fn print_results(&self, results: &[BenchmarkResult]) { - println!("\n=== Jump Table Performance Benchmarks ==="); - println!("{:<20} {:<15} {:<15} {:<15} {}", + log::info!("\n=== Jump Table Performance Benchmarks ==="); + log::info!("{:<20} {:<15} {:<15} {:<15} {}", "Test", "Total Time", "Avg Time/Op", "Ops/Second", "Memory"); for result in results { - println!( + log::info!( "{:<20} {:<15} {:<15} {:<15.0} {}", result.name, format!("{:.2?}", result.total_time), @@ -339,7 +339,7 @@ impl JumpTableBenchmark { ); } - println!("\n=== Performance Requirements Check ==="); + log::info!("\n=== Performance Requirements Check ==="); self.check_performance_requirements(results); } @@ -350,7 +350,7 @@ impl JumpTableBenchmark { "5-Card Evaluation" => { let target_ns = 100; // Target: 100 nanoseconds let actual_ns = result.avg_time_per_op.as_nanos() as u64; - println!( + log::info!( "5-Card Evaluation: {} ns (target: {} ns) - {}", actual_ns, target_ns, @@ -360,7 +360,7 @@ impl JumpTableBenchmark { "6-Card Evaluation" => { let target_ns = 500; // Target: 500 nanoseconds let actual_ns = result.avg_time_per_op.as_nanos() as u64; - println!( + log::info!( "6-Card Evaluation: {} ns (target: {} ns) - {}", actual_ns, target_ns, @@ -370,7 +370,7 @@ impl JumpTableBenchmark { "7-Card Evaluation" => { let target_us = 2; // Target: 2 microseconds let actual_us = result.avg_time_per_op.as_micros() as u64; - println!( + log::info!( "7-Card Evaluation: {} μs (target: {} μs) - {}", actual_us, target_us, @@ -381,7 +381,7 @@ impl JumpTableBenchmark { let target_mb = 130; // Target: 130 MB if let Some(bytes) = result.memory_usage { let actual_mb = bytes / 1_000_000; - println!( + log::info!( "Memory Usage: {} MB (target: {} MB) - {}", actual_mb, target_mb, diff --git a/holdem_core/src/evaluator/evaluator.rs b/holdem_core/src/evaluator/evaluator.rs index 4772450..4ee493e 100644 --- a/holdem_core/src/evaluator/evaluator.rs +++ b/holdem_core/src/evaluator/evaluator.rs @@ -145,101 +145,88 @@ impl HandValue { } // DEBUG: Log the flat rank being processed - #[cfg(debug_assertions)] - println!("DEBUG: Processing flat_rank: {}", flat_rank); + log::debug!("Processing flat_rank: {}", flat_rank); // Find which rank this flat_rank belongs to using proper poker hand distribution let result = match flat_rank { 1..=1_302_539 => { - #[cfg(debug_assertions)] - println!("DEBUG: Mapping to HighCard with value {}", flat_rank); + log::debug!("Mapping to HighCard with value {}", flat_rank); Self::new(HandRank::HighCard, flat_rank) } 1_302_540..=2_400_779 => { - #[cfg(debug_assertions)] - println!( - "DEBUG: Mapping to Pair with value {}", + log::debug!( + "Mapping to Pair with value {}", flat_rank - 1_302_540 ); Self::new(HandRank::Pair, flat_rank - 1_302_540) } 2_400_780..=2_524_331 => { - #[cfg(debug_assertions)] - println!( - "DEBUG: Mapping to TwoPair with value {}", + log::debug!( + "Mapping to TwoPair with value {}", flat_rank - 2_400_780 ); Self::new(HandRank::TwoPair, flat_rank - 2_400_780) } 2_524_332..=2_579_243 => { - #[cfg(debug_assertions)] - println!( - "DEBUG: Mapping to ThreeOfAKind with value {}", + log::debug!( + "Mapping to ThreeOfAKind with value {}", flat_rank - 2_524_332 ); Self::new(HandRank::ThreeOfAKind, flat_rank - 2_524_332) } 2_579_244..=2_589_443 => { - #[cfg(debug_assertions)] - println!( - "DEBUG: Mapping to Straight with value {}", + log::debug!( + "Mapping to Straight with value {}", flat_rank - 2_579_244 ); Self::new(HandRank::Straight, flat_rank - 2_579_244) } 2_589_444..=2_594_551 => { - #[cfg(debug_assertions)] - println!( - "DEBUG: Mapping to Flush with value {}", + log::debug!( + "Mapping to Flush with value {}", flat_rank - 2_589_444 ); Self::new(HandRank::Flush, flat_rank - 2_589_444) } 2_594_552..=2_598_295 => { - #[cfg(debug_assertions)] - println!( - "DEBUG: Mapping to FullHouse with value {}", + log::debug!( + "Mapping to FullHouse with value {}", flat_rank - 2_594_552 ); Self::new(HandRank::FullHouse, flat_rank - 2_594_552) } 2_598_296..=2_598_919 => { - #[cfg(debug_assertions)] - println!( - "DEBUG: Mapping to FourOfAKind with value {}", + log::debug!( + "Mapping to FourOfAKind with value {}", flat_rank - 2_598_296 ); Self::new(HandRank::FourOfAKind, flat_rank - 2_598_296) } 2_598_920..=2_598_955 => { - #[cfg(debug_assertions)] - println!( - "DEBUG: Mapping to StraightFlush with value {}", + log::debug!( + "Mapping to StraightFlush with value {}", flat_rank - 2_598_920 ); Self::new(HandRank::StraightFlush, flat_rank - 2_598_920) } 2_598_956..=2_598_959 => { - #[cfg(debug_assertions)] - println!( - "DEBUG: Mapping to RoyalFlush with value {}", + log::debug!( + "Mapping to RoyalFlush with value {}", flat_rank - 2_598_956 ); Self::new(HandRank::RoyalFlush, flat_rank - 2_598_956) } _ => { // Out of range, fallback to high card - #[cfg(debug_assertions)] - println!( - "DEBUG: Out of range, falling back to HighCard with value {}", + log::debug!( + "Out of range, falling back to HighCard with value {}", flat_rank ); Self::new(HandRank::HighCard, flat_rank) } }; - #[cfg(debug_assertions)] - println!("DEBUG: Result: {:?}", result); + log::debug!("Result: {:?}", result); result } @@ -634,11 +621,11 @@ impl Evaluator { if JumpTable::exists(&path) { match JumpTable::load_from_file(&path) { Ok(table) => { - println!("Loaded existing jump table from: {}", path.display()); + log::info!("Loaded existing jump table from: {}", path.display()); return Ok(table); } Err(e) => { - println!( + log::warn!( "Failed to load existing jump table ({}), creating new one...", e ); @@ -652,7 +639,7 @@ impl Evaluator { /// Create a new jump table and save it to file fn create_and_save_table(path: &Path) -> Result { - println!("Creating new jump table..."); + log::info!("Creating new jump table..."); let mut table = JumpTable::with_target_memory(); // Build the jump table with proper evaluation data @@ -668,7 +655,7 @@ impl Evaluator { EvaluatorError::table_init_failed(&format!("Failed to save jump table: {}", e)) })?; - println!( + log::info!( "Evaluator created successfully with {} table entries and saved to: {}", table.size, path.display() @@ -696,11 +683,7 @@ impl Evaluator { let packed_array: [PackedCard; 5] = packed_cards.try_into().unwrap(); if let Ok(result) = self.tables.evaluate_5_card(&packed_array) { - // Only use jump table result if it's not the default HighCard with value 0 - // This indicates the jump table lookup succeeded - if result.rank != HandRank::HighCard || result.value != 0 { - return result; - } + return result; } } @@ -771,6 +754,12 @@ impl Evaluator { best_hand_value } + /// Crate-internal wrapper for evaluating an N-card hand by finding the best 5-card combination. + /// Used by [`AlgorithmicEvaluator`](super::algorithmic_evaluator::AlgorithmicEvaluator). + pub(crate) fn evaluate_n_card_hand_public>(&self, cards: T) -> HandValue { + self.evaluate_n_card_hand(cards) + } + /// Generate all combinations of K elements from a set of N elements fn generate_combinations(&self, set: &[usize], k: usize) -> Vec> { let mut result = Vec::new(); @@ -909,17 +898,19 @@ impl Evaluator { /// Check if ranks form a straight fn is_straight(&self, ranks: &[u8; 5]) -> bool { - // Check for regular straight (consecutive ranks) + // Check for regular straight (consecutive ranks descending) + let mut is_regular = true; for i in 0..4 { if ranks[i] != ranks[i + 1] + 1 { - // Check for wheel straight (A,2,3,4,5) - if *ranks == [12, 3, 2, 1, 0] { - return true; - } - return false; + is_regular = false; + break; } } - true + if is_regular { + return true; + } + // Check for wheel straight: A,2,3,4,5 → sorted desc: [12,3,2,1,0] + *ranks == [12, 3, 2, 1, 0] } /// Check if hand has N of a kind @@ -983,9 +974,9 @@ impl Evaluator { /// Calculate value for flush fn calculate_flush_value(&self, ranks: &[u8; 5]) -> u32 { // For flush, value is based on highest card, then next highest, etc. - // Use minimal range to ensure flush values stay within expected bounds - // Simple linear combination to ensure values stay in range - ranks[0] as u32 * 1 + ranks[1] as u32 + ranks[2] as u32 + ranks[3] as u32 + ranks[4] as u32 + // Use base-13 encoding to ensure unique values for different flush hands + ranks[0] as u32 * 28561 + ranks[1] as u32 * 2197 + + ranks[2] as u32 * 169 + ranks[3] as u32 * 13 + ranks[4] as u32 } /// Calculate value for three of a kind @@ -1094,7 +1085,7 @@ impl Evaluator { // Validate that the table was built correctly table.validate()?; - println!( + log::info!( "Evaluator created successfully with {} table entries (no persistence)", table.size ); @@ -1108,7 +1099,7 @@ impl Evaluator { pub fn regenerate_table(&mut self) -> Result<(), EvaluatorError> { let path = JumpTable::default_file_path(); - println!("Regenerating jump table..."); + log::info!("Regenerating jump table..."); let mut table = JumpTable::with_target_memory(); // Build the jump table with proper evaluation data @@ -1127,7 +1118,7 @@ impl Evaluator { // Update the evaluator's table self.tables = Arc::new(table); - println!("Jump table regenerated and saved successfully"); + log::info!("Jump table regenerated and saved successfully"); Ok(()) } @@ -1139,7 +1130,7 @@ impl Evaluator { /// Validate the compressed ranking system /// Ensures all 7,462 distinct hands are properly represented and comparison semantics are preserved pub fn validate_compressed_ranking(&self) -> Result<(), EvaluatorError> { - println!("Validating compressed ranking system..."); + log::info!("Validating compressed ranking system..."); // Test 1: Ensure all compressed ranks are within 0-7461 range let mut compressed_ranks = std::collections::HashSet::new(); @@ -1366,9 +1357,9 @@ impl Evaluator { } } - println!("Compressed ranking validation completed successfully!"); - println!("Tested {} unique compressed ranks", compressed_ranks.len()); - println!("Range: {} - {}", min_rank, max_rank); + log::info!("Compressed ranking validation completed successfully!"); + log::info!("Tested {} unique compressed ranks", compressed_ranks.len()); + log::info!("Range: {} - {}", min_rank, max_rank); Ok(()) } diff --git a/holdem_core/src/evaluator/examples.rs b/holdem_core/src/evaluator/examples.rs index bdab16e..9ac108b 100644 --- a/holdem_core/src/evaluator/examples.rs +++ b/holdem_core/src/evaluator/examples.rs @@ -22,7 +22,7 @@ use std::time::Instant; /// Basic usage example demonstrating core functionality pub fn basic_usage_example() -> Result<(), EvaluatorError> { - println!("=== Basic Usage Example ==="); + log::info!("=== Basic Usage Example ==="); // Create a 7-card poker hand let cards = [ @@ -35,7 +35,7 @@ pub fn basic_usage_example() -> Result<(), EvaluatorError> { Card::from_str("6d").unwrap(), ]; - println!( + log::info!( "Evaluating hand: {:?}", cards.iter().map(|c| c.to_string()).collect::>() ); @@ -44,7 +44,7 @@ pub fn basic_usage_example() -> Result<(), EvaluatorError> { let mut math_evaluator = MathEvaluator::new()?; let result1 = math_evaluator.evaluate_7_card(&cards); - println!("MathEvaluator result: {:?}", result1); + log::info!("MathEvaluator result: {:?}", result1); // Method 2: Using JumpTable directly (for advanced use cases) let mut table = JumpTable::with_target_memory(); @@ -54,18 +54,18 @@ pub fn basic_usage_example() -> Result<(), EvaluatorError> { let packed_array: [PackedCard; 7] = packed_cards.try_into().unwrap(); let result2 = table.evaluate_7_card(&packed_array); - println!("JumpTable result: {:?}", result2); + log::info!("JumpTable result: {:?}", result2); // Results should be identical assert_eq!(result1, result2.unwrap()); - println!("✓ Basic evaluation complete\n"); + log::info!("✓ Basic evaluation complete\n"); Ok(()) } /// Performance benchmarking example pub fn performance_example() -> Result<(), EvaluatorError> { - println!("=== Performance Benchmarking Example ==="); + log::info!("=== Performance Benchmarking Example ==="); // Create test hands of different types let test_hands = vec![ @@ -121,7 +121,7 @@ pub fn performance_example() -> Result<(), EvaluatorError> { let mut math_evaluator = MathEvaluator::new()?; - println!("Benchmarking {} hand types...", test_hands.len()); + log::info!("Benchmarking {} hand types...", test_hands.len()); for (hand_type, cards) in test_hands { let iterations = 10000; @@ -135,23 +135,23 @@ pub fn performance_example() -> Result<(), EvaluatorError> { let elapsed = start_time.elapsed(); let avg_time = elapsed / iterations; - println!(" {}: {:?}", hand_type, avg_time); + log::info!(" {}: {:?}", hand_type, avg_time); } // Display evaluator statistics let stats = math_evaluator.stats(); - println!("\nEvaluator Statistics:"); - println!(" Total evaluations: {}", stats.total_evaluations); - println!(" Average time: {} ns", stats.average_time_ns); - println!(" Total time: {} ms", stats.total_time_ns / 1_000_000); + log::info!("\nEvaluator Statistics:"); + log::info!(" Total evaluations: {}", stats.total_evaluations); + log::info!(" Average time: {} ns", stats.average_time_ns); + log::info!(" Total time: {} ms", stats.total_time_ns / 1_000_000); - println!("✓ Performance benchmarking complete\n"); + log::info!("✓ Performance benchmarking complete\n"); Ok(()) } /// Integration example showing compatibility with holdem_core pub fn integration_example() -> Result<(), EvaluatorError> { - println!("=== Integration Example ==="); + log::info!("=== Integration Example ==="); // Create hands using holdem_core let hole_cards = crate::HoleCards::from_notation("AKs") @@ -160,10 +160,10 @@ pub fn integration_example() -> Result<(), EvaluatorError> { let hand = Hand::from_hole_cards_and_board(&hole_cards, &board) .map_err(|_| EvaluatorError::table_init_failed("Invalid hand"))?; - println!("Evaluating complete hand:"); - println!(" Hole cards: {}", hole_cards); - println!(" Board: {}", board); - println!(" Complete hand: {}", hand); + log::info!("Evaluating complete hand:"); + log::info!(" Hole cards: {}", hole_cards); + log::info!(" Board: {}", board); + log::info!(" Complete hand: {}", hand); // Compare results between math and holdem_core evaluators let mut comparison = EvaluatorComparison::new()?; @@ -171,40 +171,40 @@ pub fn integration_example() -> Result<(), EvaluatorError> { let math_result = comparison.math_evaluator.evaluate_hand(&hand); let core_result = comparison.core_evaluator.evaluate_hand(&hand); - println!("\nEvaluation Results:"); - println!(" Math evaluator: {:?}", math_result); - println!(" Core evaluator: {:?}", core_result); - println!(" Results match: {}", math_result == core_result); + log::info!("\nEvaluation Results:"); + log::info!(" Math evaluator: {:?}", math_result); + log::info!(" Core evaluator: {:?}", core_result); + log::info!(" Results match: {}", math_result == core_result); // Test type conversion utilities let cards = hand.cards(); let packed_cards = super::integration::convert_cards(&cards); let converted_back = super::integration::convert_cards_back(&packed_cards)?; - println!("\nType Conversion Test:"); - println!( + log::info!("\nType Conversion Test:"); + log::info!( " Original: {:?}", cards.iter().map(|c| c.to_string()).collect::>() ); - println!( + log::info!( " Converted back: {:?}", converted_back .iter() .map(|c| c.to_string()) .collect::>() ); - println!( + log::info!( " Conversion successful: {}", cards.len() == converted_back.len() ); - println!("✓ Integration example complete\n"); + log::info!("✓ Integration example complete\n"); Ok(()) } /// Canonical mapping example demonstrating suit canonicalization pub fn canonicalization_example() -> Result<(), EvaluatorError> { - println!("=== Canonical Mapping Example ==="); + log::info!("=== Canonical Mapping Example ==="); // Create cards with different suit patterns let test_cases = vec![ @@ -240,12 +240,12 @@ pub fn canonicalization_example() -> Result<(), EvaluatorError> { ]; for (description, cards) in test_cases { - println!("Testing: {}", description); + log::info!("Testing: {}", description); let mapping = CanonicalMapping::from_cards(&cards); - println!(" Original suits: {:?}", extract_suits(&cards)); - println!( + log::info!(" Original suits: {:?}", extract_suits(&cards)); + log::info!( " Canonical suits: {:?}", mapping .canonical_cards @@ -253,46 +253,46 @@ pub fn canonicalization_example() -> Result<(), EvaluatorError> { .map(|&c| c & 0x03) .collect::>() ); - println!(" Suit mapping: {:?}", mapping.suit_map); - println!(" Reverse mapping: {:?}", mapping.reverse_map); + log::info!(" Suit mapping: {:?}", mapping.suit_map); + log::info!(" Reverse mapping: {:?}", mapping.reverse_map); // Verify round-trip conversion let original_suits = mapping.to_original_suits(&mapping.canonical_cards); - println!( + log::info!( " Round-trip successful: {}", original_suits.len() == cards.len() ); - println!(); + log::info!(""); } - println!("✓ Canonical mapping example complete\n"); + log::info!("✓ Canonical mapping example complete\n"); Ok(()) } /// Advanced configuration example pub fn advanced_configuration_example() -> Result<(), EvaluatorError> { - println!("=== Advanced Configuration Example ==="); + log::info!("=== Advanced Configuration Example ==="); // Create custom jump table with specific size let custom_size = 25_000_000; // 25M entries let mut table = JumpTable::new(custom_size); - println!("Creating custom jump table with {} entries...", custom_size); + log::info!("Creating custom jump table with {} entries...", custom_size); let build_start = Instant::now(); table.build()?; let build_time = build_start.elapsed(); - println!("Table built in {:?}", build_time); - println!( + log::info!("Table built in {:?}", build_time); + log::info!( "Memory usage: {:.2} MB", table.memory_usage() as f64 / 1_000_000.0 ); // Validate table integrity table.validate()?; - println!("Table validation: ✓ Passed"); + log::info!("Table validation: ✓ Passed"); // Test evaluation with custom table let test_cards = [ @@ -309,27 +309,27 @@ pub fn advanced_configuration_example() -> Result<(), EvaluatorError> { let packed_array: [PackedCard; 7] = packed_cards.try_into().unwrap(); let result = table.evaluate_7_card(&packed_array); - println!("Custom table evaluation result: {:?}", result); + log::info!("Custom table evaluation result: {:?}", result); // Display table metadata - println!("\nTable Metadata:"); - println!(" Version: {}", table.metadata.version); - println!(" Created: {}", table.metadata.created_at); - println!( + log::info!("\nTable Metadata:"); + log::info!(" Version: {}", table.metadata.version); + log::info!(" Created: {}", table.metadata.created_at); + log::info!( " Total combinations: {}", table.metadata.total_combinations ); - println!(" Level 5 nodes: {}", table.metadata.stats.level5_nodes); - println!(" Level 6 nodes: {}", table.metadata.stats.level6_nodes); - println!(" Level 7 nodes: {}", table.metadata.stats.level7_nodes); + log::info!(" Level 5 nodes: {}", table.metadata.stats.level5_nodes); + log::info!(" Level 6 nodes: {}", table.metadata.stats.level6_nodes); + log::info!(" Level 7 nodes: {}", table.metadata.stats.level7_nodes); - println!("✓ Advanced configuration example complete\n"); + log::info!("✓ Advanced configuration example complete\n"); Ok(()) } /// Memory optimization example pub fn memory_optimization_example() -> Result<(), EvaluatorError> { - println!("=== Memory Optimization Example ==="); + log::info!("=== Memory Optimization Example ==="); // Compare different table sizes let sizes = vec![10_000_000, 20_000_000, 30_000_000, 34_000_000]; @@ -343,7 +343,7 @@ pub fn memory_optimization_example() -> Result<(), EvaluatorError> { let memory_mb = table.memory_usage() as f64 / 1_000_000.0; - println!( + log::info!( "Size: {:8} entries | Memory: {:6.1} MB | Build time: {:?}", size, memory_mb, build_time ); @@ -356,22 +356,22 @@ pub fn memory_optimization_example() -> Result<(), EvaluatorError> { let target_table = JumpTable::with_target_memory(); let target_memory = target_table.memory_usage() as f64 / 1_000_000.0; - println!("\nTarget configuration:"); - println!(" Memory usage: {:.1} MB", target_memory); - println!(" Recommended for production use: ✓"); + log::info!("\nTarget configuration:"); + log::info!(" Memory usage: {:.1} MB", target_memory); + log::info!(" Recommended for production use: ✓"); - println!("✓ Memory optimization example complete\n"); + log::info!("✓ Memory optimization example complete\n"); Ok(()) } /// Error handling example pub fn error_handling_example() -> Result<(), EvaluatorError> { - println!("=== Error Handling Example ==="); + log::info!("=== Error Handling Example ==="); // Demonstrate proper error handling match MathEvaluator::new() { Ok(mut evaluator) => { - println!("✓ MathEvaluator created successfully"); + log::info!("✓ MathEvaluator created successfully"); // Test with valid input let valid_cards = [ @@ -385,10 +385,10 @@ pub fn error_handling_example() -> Result<(), EvaluatorError> { ]; let result = evaluator.evaluate_7_card(&valid_cards); - println!("✓ Evaluation successful: {:?}", result); + log::info!("✓ Evaluation successful: {:?}", result); } Err(e) => { - println!("✗ Failed to create MathEvaluator: {:?}", e); + log::info!("✗ Failed to create MathEvaluator: {:?}", e); return Err(e); } } @@ -405,23 +405,23 @@ pub fn error_handling_example() -> Result<(), EvaluatorError> { } match table.validate() { - Ok(()) => println!("✓ Table validation passed"), - Err(e) => println!("✗ Table validation failed: {:?}", e), + Ok(()) => log::info!("✓ Table validation passed"), + Err(e) => log::info!("✗ Table validation failed: {:?}", e), } // Test invalid table access match table.get(2000) { - Some(_) => println!("✗ Should not find entry beyond table size"), - None => println!("✓ Properly handles out-of-bounds access"), + Some(_) => log::info!("✗ Should not find entry beyond table size"), + None => log::info!("✓ Properly handles out-of-bounds access"), } - println!("✓ Error handling example complete\n"); + log::info!("✓ Error handling example complete\n"); Ok(()) } /// Comprehensive demonstration of all features pub fn comprehensive_demo() -> Result<(), EvaluatorError> { - println!("=== Comprehensive Math Evaluator Demo ===\n"); + log::info!("=== Comprehensive Math Evaluator Demo ===\n"); // Run all examples basic_usage_example()?; @@ -432,8 +432,8 @@ pub fn comprehensive_demo() -> Result<(), EvaluatorError> { memory_optimization_example()?; error_handling_example()?; - println!("🎉 All examples completed successfully!"); - println!("The math evaluator is ready for production use."); + log::info!("🎉 All examples completed successfully!"); + log::info!("The math evaluator is ready for production use."); Ok(()) } diff --git a/holdem_core/src/evaluator/integration.rs b/holdem_core/src/evaluator/integration.rs index ed60443..974389b 100644 --- a/holdem_core/src/evaluator/integration.rs +++ b/holdem_core/src/evaluator/integration.rs @@ -39,7 +39,7 @@ //! //! let packed_array: [PackedCard; 7] = math_cards.try_into().unwrap(); //! let result = table.evaluate_7_card(&packed_array); -//! println!("Hand evaluation: {:?}", result); +//! log::info!("Hand evaluation: {:?}", result); //! ``` //! //! ### Performance Comparison @@ -58,8 +58,8 @@ //! core_eval.evaluate_7_card(cards) //! }); //! -//! println!("Math evaluator: {:?}", math_time); -//! println!("Core evaluator: {:?}", core_time); +//! log::info!("Math evaluator: {:?}", math_time); +//! log::info!("Core evaluator: {:?}", core_time); //! ``` use super::errors::EvaluatorError; @@ -494,7 +494,7 @@ pub mod utils { } } - println!("All evaluator compatibility tests passed!"); + log::info!("All evaluator compatibility tests passed!"); Ok(()) } diff --git a/holdem_core/src/evaluator/integration_utils.rs b/holdem_core/src/evaluator/integration_utils.rs new file mode 100644 index 0000000..5f6751d --- /dev/null +++ b/holdem_core/src/evaluator/integration_utils.rs @@ -0,0 +1,4 @@ +//! Integration utilities for the hand evaluator. +//! +//! This module provides helper functions and data structures for integration +//! testing and cross-validation of hand evaluation results. diff --git a/holdem_core/src/evaluator/property_tests.rs b/holdem_core/src/evaluator/property_tests.rs index e45d286..8a62128 100644 --- a/holdem_core/src/evaluator/property_tests.rs +++ b/holdem_core/src/evaluator/property_tests.rs @@ -71,7 +71,7 @@ impl EvaluatorTestSuite { pub fn run_all_tests(&mut self) -> Result { let start_time = std::time::Instant::now(); - println!("Running comprehensive math evaluator test suite..."); + log::info!("Running comprehensive math evaluator test suite..."); // Run correctness tests self.run_correctness_tests()?; @@ -91,13 +91,13 @@ impl EvaluatorTestSuite { let elapsed = start_time.elapsed(); self.stats.execution_time_ms = elapsed.as_millis() as u64; - println!("Test suite completed: {:?}", self.stats); + log::info!("Test suite completed: {:?}", self.stats); Ok(self.stats.clone()) } /// Test that math evaluator produces correct results fn run_correctness_tests(&mut self) -> Result<(), EvaluatorError> { - println!("Running correctness tests..."); + log::info!("Running correctness tests..."); let test_hands = generate_comprehensive_test_hands(); let mut passed = 0; @@ -130,7 +130,7 @@ impl EvaluatorTestSuite { passed += 1; } else { failed += 1; - println!( + log::info!( "5-card mismatch at test {}: math={:?}, core={:?}", i, math_result_5, core_result_5 ); @@ -150,7 +150,7 @@ impl EvaluatorTestSuite { passed += 1; } else { failed += 1; - println!( + log::info!( "6-card mismatch at test {}: math={:?}, core={:?}", i, math_result_6, core_result_6 ); @@ -167,7 +167,7 @@ impl EvaluatorTestSuite { passed += 1; } else { failed += 1; - println!( + log::info!( "7-card mismatch at test {}: math={:?}, core={:?}", i, math_result_7, core_result_7 ); @@ -182,13 +182,13 @@ impl EvaluatorTestSuite { self.stats.passed_tests += passed; self.stats.failed_tests += failed; - println!("Correctness tests: {} passed, {} failed", passed, failed); + log::info!("Correctness tests: {} passed, {} failed", passed, failed); Ok(()) } /// Test performance characteristics fn run_performance_tests(&mut self) -> Result<(), EvaluatorError> { - println!("Running performance tests..."); + log::info!("Running performance tests..."); // Test 5-card performance let time_5 = benchmark_evaluation(|cards| { @@ -209,33 +209,33 @@ impl EvaluatorTestSuite { let max_7_card_time = std::time::Duration::from_nanos(1000); if time_7 > max_7_card_time { - println!("Warning: 7-card evaluation too slow: {:?}", time_7); + log::info!("Warning: 7-card evaluation too slow: {:?}", time_7); } else { - println!("Performance tests passed"); + log::info!("Performance tests passed"); } - println!("Performance results:"); - println!(" 5-card: {:?}", time_5); - println!(" 6-card: {:?}", time_6); - println!(" 7-card: {:?}", time_7); + log::info!("Performance results:"); + log::info!(" 5-card: {:?}", time_5); + log::info!(" 6-card: {:?}", time_6); + log::info!(" 7-card: {:?}", time_7); Ok(()) } /// Test memory usage targets fn run_memory_tests(&mut self) -> Result<(), EvaluatorError> { - println!("Running memory tests..."); + log::info!("Running memory tests..."); let memory_usage = self.math_evaluator.get_jump_table().memory_usage(); let target_max_memory = 150_000_000; // 150MB target if memory_usage > target_max_memory { - println!( + log::info!( "Warning: Memory usage exceeds target: {} bytes", memory_usage ); } else { - println!("Memory usage within target: {} bytes", memory_usage); + log::info!("Memory usage within target: {} bytes", memory_usage); } // Test that jump table is properly sized @@ -245,13 +245,13 @@ impl EvaluatorTestSuite { assert!(table.size > 0); assert!(table.memory_usage() > 0); - println!("Memory tests passed"); + log::info!("Memory tests passed"); Ok(()) } /// Test integration between systems fn run_integration_tests(&mut self) -> Result<(), EvaluatorError> { - println!("Running integration tests..."); + log::info!("Running integration tests..."); // Test type conversions let cards = [ @@ -272,13 +272,13 @@ impl EvaluatorTestSuite { // Should handle empty input gracefully assert_eq!(results.len(), 0); - println!("Integration tests passed"); + log::info!("Integration tests passed"); Ok(()) } /// Test for known bugs and regressions fn run_regression_tests(&mut self) -> Result<(), EvaluatorError> { - println!("Running regression tests..."); + log::info!("Running regression tests..."); // Test edge cases that have caused issues in the past let edge_cases = vec![ @@ -325,10 +325,10 @@ impl EvaluatorTestSuite { assert!(result_7.rank as u8 <= HandRank::RoyalFlush as u8); } - println!("Regression test {} passed", i); + log::info!("Regression test {} passed", i); } - println!("Regression tests passed"); + log::info!("Regression tests passed"); Ok(()) } } @@ -441,7 +441,7 @@ fn generate_comprehensive_test_hands() -> Vec<[Card; 7]> { /// Property-based tests for canonicalization pub fn test_canonicalization_properties() -> Result<(), EvaluatorError> { - println!("Testing canonicalization properties..."); + log::info!("Testing canonicalization properties..."); // Test that canonicalization is deterministic let cards = vec![ @@ -468,13 +468,13 @@ pub fn test_canonicalization_properties() -> Result<(), EvaluatorError> { let original_suits = mapping1.to_original_suits(&mapping1.canonical_cards); assert_eq!(original_suits.len(), mapping1.canonical_cards.len()); - println!("Canonicalization property tests passed"); + log::info!("Canonicalization property tests passed"); Ok(()) } /// Property-based tests for jump table pub fn test_jump_table_properties() -> Result<(), EvaluatorError> { - println!("Testing jump table properties..."); + log::info!("Testing jump table properties..."); let mut table = JumpTable::with_target_memory(); @@ -509,13 +509,13 @@ pub fn test_jump_table_properties() -> Result<(), EvaluatorError> { assert!(entry.is_some()); } - println!("Jump table property tests passed"); + log::info!("Jump table property tests passed"); Ok(()) } /// Stress tests for performance under load pub fn run_stress_tests() -> Result<(), EvaluatorError> { - println!("Running stress tests..."); + log::info!("Running stress tests..."); let mut evaluator = MathEvaluator::new()?; let num_hands = 1000; @@ -586,7 +586,7 @@ pub fn run_stress_tests() -> Result<(), EvaluatorError> { eval_pb.finish_with_message("Stress test completed"); - println!( + log::info!( "Stress test: {} hands in {:?}, average: {:?}", test_hands.len(), elapsed, @@ -599,7 +599,7 @@ pub fn run_stress_tests() -> Result<(), EvaluatorError> { "Stress test too slow" ); - println!("Stress tests passed"); + log::info!("Stress tests passed"); Ok(()) } diff --git a/holdem_core/src/evaluator/tables.rs b/holdem_core/src/evaluator/tables.rs index cd42d87..cfac20a 100644 --- a/holdem_core/src/evaluator/tables.rs +++ b/holdem_core/src/evaluator/tables.rs @@ -468,11 +468,11 @@ impl JumpTable { let total_size = level5_size + level6_size + level7_size; - println!("Creating jump table with optimal memory layout:"); - println!(" Level 5 (5-card): {} entries", level5_size); - println!(" Level 6 (6-card): {} entries", level6_size); - println!(" Level 7 (7-card): {} entries", level7_size); - println!( + log::info!("Creating jump table with optimal memory layout:"); + log::info!(" Level 5 (5-card): {} entries", level5_size); + log::info!(" Level 6 (6-card): {} entries", level6_size); + log::info!(" Level 7 (7-card): {} entries", level7_size); + log::info!( " Total: {} entries (~{} MB)", total_size, total_size * 16 / 1024 / 1024 @@ -574,7 +574,7 @@ impl JumpTable { EvaluatorError::table_init_failed(&format!("Failed to write to file: {}", e)) })?; - println!("Jump table saved to: {}", path.display()); + log::info!("Jump table saved to: {}", path.display()); Ok(()) } @@ -621,7 +621,7 @@ impl JumpTable { // Validate the loaded table table.validate()?; - println!("Jump table loaded from: {}", path.display()); + log::info!("Jump table loaded from: {}", path.display()); Ok(table) } @@ -655,7 +655,7 @@ impl JumpTable { // Generate all C(52,7) combinations - this is a large number (133M+) // For practical purposes, we'll generate a representative subset // In production, this would be done in batches or with streaming - println!("Generating canonical 7-card combinations..."); + log::info!("Generating canonical 7-card combinations..."); // For now, generate a smaller subset for testing and development let max_combinations = if cfg!(test) { 1000 } else { 100_000 }; @@ -680,7 +680,7 @@ impl JumpTable { combinations.push(combo); if combinations.len() >= max_combinations { - println!( + log::info!( "Generated {} combinations for testing", combinations.len() ); @@ -694,31 +694,31 @@ impl JumpTable { } } - println!("Generated {} canonical combinations", combinations.len()); + log::info!("Generated {} canonical combinations", combinations.len()); Ok(combinations) } /// Build the jump table using bottom-up trie construction pub fn build(&mut self) -> Result<(), EvaluatorError> { - println!("Building jump table with {} entries...", self.size); + log::info!("Building jump table with {} entries...", self.size); // Step 1: Generate canonical mappings for all 7-card combinations let combinations = self.generate_canonical_combinations()?; // Step 2: Build Level 5 (terminal nodes) - 5-card hand evaluations - println!("Building Level 5 terminal nodes..."); + log::info!("Building Level 5 terminal nodes..."); self.build_level_5()?; // Step 3: Build Level 6 (intermediate nodes) - 6-card combinations - println!("Building Level 6 intermediate nodes..."); + log::info!("Building Level 6 intermediate nodes..."); self.build_level_6(&combinations)?; // Step 4: Build Level 7 (root nodes) - 7-card combinations - println!("Building Level 7 root nodes..."); + log::info!("Building Level 7 root nodes..."); self.build_level_7(&combinations)?; // Step 5: Flatten the trie into contiguous array - println!("Flattening trie structure..."); + log::info!("Flattening trie structure..."); // Temporary placeholder for flatten_trie method // self.flatten_trie()?; @@ -726,13 +726,13 @@ impl JumpTable { self.metadata.total_combinations = combinations.len(); self.metadata.memory_usage = self.memory_usage(); - println!("Jump table construction complete!"); + log::info!("Jump table construction complete!"); Ok(()) } /// Build Level 5 terminal nodes (5-card hand evaluations) using proper combinatorial indexing fn build_level_5(&mut self) -> Result<(), EvaluatorError> { - println!( + log::info!( "Building Level 5: Terminal nodes for 5-card hands using combinatorial indexing..." ); @@ -743,7 +743,7 @@ impl JumpTable { // This is more efficient than generating from 7-card combinations let unique_5_card_hands = self.generate_all_unique_5_card_hands(); - println!( + log::info!( "Generated {} unique 5-card combinations using combinatorial indexing", unique_5_card_hands.len() ); @@ -763,7 +763,7 @@ impl JumpTable { let card_array: [Card; 5] = cards.try_into().unwrap(); // Evaluate the hand using the algorithmic evaluator for accuracy - let evaluator = AlgorithmicEvaluator::new(); + let evaluator = AlgorithmicEvaluator::new()?; let hand_value = evaluator.evaluate_5_card_direct(&card_array); // Use proper combinatorial indexing instead of simple hashing @@ -776,12 +776,12 @@ impl JumpTable { } if hand_index % 10000 == 0 && hand_index > 0 { - println!("Processed {} Level 5 entries", hand_index); + log::info!("Processed {} Level 5 entries", hand_index); } } let elapsed = start_time.elapsed(); - println!( + log::info!( "Level 5 construction complete: {} nodes in {:?}", level5_count, elapsed ); @@ -890,7 +890,7 @@ impl JumpTable { /// Build Level 6 intermediate nodes (6-card combinations) fn build_level_6(&mut self, combinations: &[Vec]) -> Result<(), EvaluatorError> { - println!("Building Level 6: Intermediate nodes for 6-card hands..."); + log::info!("Building Level 6: Intermediate nodes for 6-card hands..."); let mut level6_count = 0; let start_time = std::time::Instant::now(); @@ -907,7 +907,7 @@ impl JumpTable { } // Find the best 5-card hand from this 6-card hand using algorithmic evaluator - let mut evaluator = AlgorithmicEvaluator::new(); + let evaluator = AlgorithmicEvaluator::new()?; // Convert 6 PackedCards to 6-element Card array let mut cards = Vec::new(); for &packed in &six_cards { @@ -927,12 +927,12 @@ impl JumpTable { } if combo_index % 1000 == 0 && combo_index > 0 { - println!("Processed {} 7-card combinations for Level 6", combo_index); + log::info!("Processed {} 7-card combinations for Level 6", combo_index); } } let elapsed = start_time.elapsed(); - println!( + log::info!( "Level 6 construction complete: {} nodes in {:?}", level6_count, elapsed ); @@ -945,7 +945,7 @@ impl JumpTable { /// Build Level 7 root nodes (7-card combinations) fn build_level_7(&mut self, combinations: &[Vec]) -> Result<(), EvaluatorError> { - println!("Building Level 7: Root nodes for 7-card hands..."); + log::info!("Building Level 7: Root nodes for 7-card hands..."); let mut level7_count = 0; let start_time = std::time::Instant::now(); @@ -954,7 +954,7 @@ impl JumpTable { for (combo_index, combo) in combinations.iter().enumerate() { if combo.len() >= 6 { // Find the best 5-card hand from this 7-card hand using algorithmic evaluator - let mut evaluator = AlgorithmicEvaluator::new(); + let evaluator = AlgorithmicEvaluator::new()?; // Convert 7 PackedCards to 7-element Card array let mut cards = Vec::new(); for &packed in combo { @@ -973,12 +973,12 @@ impl JumpTable { } if combo_index % 1000 == 0 && combo_index > 0 { - println!("Processed {} 7-card combinations for Level 7", combo_index); + log::info!("Processed {} 7-card combinations for Level 7", combo_index); } } let elapsed = start_time.elapsed(); - println!( + log::info!( "Level 7 construction complete: {} nodes in {:?}", level7_count, elapsed ); @@ -1294,7 +1294,7 @@ impl JumpTable { // TEMPORARY FIX: Use algorithmic evaluator instead of jump table // This bypasses hash function issues and ensures correct results use super::algorithmic_evaluator::AlgorithmicEvaluator; - let evaluator = AlgorithmicEvaluator::new(); + let evaluator = AlgorithmicEvaluator::new()?; Ok(evaluator.evaluate_5_card_direct(&card_array)) } @@ -1351,7 +1351,7 @@ impl JumpTable { // TEMPORARY FIX: Use algorithmic evaluator directly to bypass hash function issues use super::algorithmic_evaluator::AlgorithmicEvaluator; - let mut evaluator = AlgorithmicEvaluator::new(); + let evaluator = AlgorithmicEvaluator::new()?; // Convert PackedCards to Cards for algorithmic evaluator let card_array: Vec = cards @@ -1493,11 +1493,11 @@ pub fn calculate_optimal_table_size() -> JumpTable { let total_size = level5_size + level6_size + level7_size; - println!("Creating jump table with optimal memory layout:"); - println!(" Level 5 (5-card): {} entries", level5_size); - println!(" Level 6 (6-card): {} entries", level6_size); - println!(" Level 7 (7-card): {} entries", level7_size); - println!( + log::info!("Creating jump table with optimal memory layout:"); + log::info!(" Level 5 (5-card): {} entries", level5_size); + log::info!(" Level 6 (6-card): {} entries", level6_size); + log::info!(" Level 7 (7-card): {} entries", level7_size); + log::info!( " Total: {} entries (~{} MB)", total_size, total_size * 16 / 1024 / 1024 diff --git a/holdem_core/src/evaluator/tables_new.rs b/holdem_core/src/evaluator/tables_new.rs new file mode 100644 index 0000000..a91b355 --- /dev/null +++ b/holdem_core/src/evaluator/tables_new.rs @@ -0,0 +1,4 @@ +//! New table implementations for the hand evaluator. +//! +//! This module is a placeholder for future jump table implementations +//! and optimized lookup structures. diff --git a/holdem_core/src/evaluator/test_utils.rs b/holdem_core/src/evaluator/test_utils.rs new file mode 100644 index 0000000..304f062 --- /dev/null +++ b/holdem_core/src/evaluator/test_utils.rs @@ -0,0 +1,4 @@ +//! Test utilities for the hand evaluator. +//! +//! This module provides helper functions and data structures for testing +//! hand evaluation correctness.