Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 07c0c8adc3 | |||
| 6e37a7d209 | |||
| eeae4f01b4 | |||
| 45b5719d63 | |||
| b2683a7f5a | |||
| 3437dab49b | |||
| b72e8ec017 |
@@ -1317,3 +1317,126 @@
|
||||
### Reverts
|
||||
|
||||
* Revert "refactor: update metrics paths formatting in application.yml for clarity" ([3870566](https://git.janis-eccarius.de/NowChess/NowChessSystems/commit/38705663498d5f47c40dafe2f26198589ede8656))
|
||||
## (2026-06-30)
|
||||
|
||||
### Features
|
||||
|
||||
* add initialization metrics for various services ([d438e97](https://git.janis-eccarius.de/NowChess/NowChessSystems/commit/d438e97f32bdde0bfc63c1b4a8cc810cdd093166))
|
||||
* add OpenTelemetry trace configuration with parentbased sampler ([3904d5a](https://git.janis-eccarius.de/NowChess/NowChessSystems/commit/3904d5ad8ad4930ddee65287a7bfab785a6148f5))
|
||||
* **analytics:** add Spark batch analytics module ([#70](https://git.janis-eccarius.de/NowChess/NowChessSystems/issues/70)) ([39f1657](https://git.janis-eccarius.de/NowChess/NowChessSystems/commit/39f1657e1db6e84889af338c43be8cb5c03c3ec3))
|
||||
* **bot:** add Lazy SMP parallel search for the NNUE bot ([3437dab](https://git.janis-eccarius.de/NowChess/NowChessSystems/commit/3437dab49b2cc3f7b7e726febb07ad759e878079))
|
||||
* **bot:** clock-aware time management and stream-driven tournament play ([45b5719](https://git.janis-eccarius.de/NowChess/NowChessSystems/commit/45b5719d630c9480398f51510cc598d2d6ce39db))
|
||||
* **bot:** implement bot-vs-bot harness for NNUE evaluation ([b2683a7](https://git.janis-eccarius.de/NowChess/NowChessSystems/commit/b2683a7f5ab6f3e41883736ac5eeaaee2e1ea5c1))
|
||||
* **config:** update application.yml for PostgreSQL and remove staging/production configurations ([2404e61](https://git.janis-eccarius.de/NowChess/NowChessSystems/commit/2404e6164c3b50ffccbea5238d636060d6abe4d6))
|
||||
* **config:** update application.yml for staging and production environments ([6113432](https://git.janis-eccarius.de/NowChess/NowChessSystems/commit/6113432a14c476a3a0dfc0d449e17d023697f2ba))
|
||||
* configure logging and add OpenTelemetry support ([#49](https://git.janis-eccarius.de/NowChess/NowChessSystems/issues/49)) ([d57c488](https://git.janis-eccarius.de/NowChess/NowChessSystems/commit/d57c4886612d1d92da0e1b79209fc83e6ef537a1))
|
||||
* **docker:** add .dockerignore and .gitignore files for build exclusions ([c987d8e](https://git.janis-eccarius.de/NowChess/NowChessSystems/commit/c987d8e258c0e6c4cfbdaa8381c64c410d7a2b83))
|
||||
* **docker:** add Dockerfiles for building Quarkus application in native and JVM modes ([3f2d2bb](https://git.janis-eccarius.de/NowChess/NowChessSystems/commit/3f2d2bb4c97fa8cddba66e1da4427c54236dfeed))
|
||||
* **docker:** add Dockerfiles for Quarkus application in JVM and native modes ([34b9933](https://git.janis-eccarius.de/NowChess/NowChessSystems/commit/34b993304670cf2aa62cd2f6460cee7b9864b08e))
|
||||
* **events:** migrate game-creation and bot flows to Redis Streams NCS-89 ([#62](https://git.janis-eccarius.de/NowChess/NowChessSystems/issues/62)) ([a24924c](https://git.janis-eccarius.de/NowChess/NowChessSystems/commit/a24924c23057db3d700a75dbc4333557789cd991))
|
||||
* **ncs-110:** feed NNUE root-move scores into search move ordering ([#83](https://git.janis-eccarius.de/NowChess/NowChessSystems/issues/83)) ([e4fee85](https://git.janis-eccarius.de/NowChess/NowChessSystems/commit/e4fee8513430093d46957970618935e99591519f))
|
||||
* NCS-78 Add Traceability to the Applications ([#46](https://git.janis-eccarius.de/NowChess/NowChessSystems/issues/46)) ([649566e](https://git.janis-eccarius.de/NowChess/NowChessSystems/commit/649566eb3fcf38f91c8896a739f74ea318af312d))
|
||||
* NCS-78 Add Traceability to the Applications ([#47](https://git.janis-eccarius.de/NowChess/NowChessSystems/issues/47)) ([87dfc6c](https://git.janis-eccarius.de/NowChess/NowChessSystems/commit/87dfc6c2bcce7f7d58fc641bd8d468a2e584c108))
|
||||
* NCS-82 add Swiss-system tournament module ([#55](https://git.janis-eccarius.de/NowChess/NowChessSystems/issues/55)) ([c5661de](https://git.janis-eccarius.de/NowChess/NowChessSystems/commit/c5661de4a0ebf4b33211f5a391840dcf744656b7))
|
||||
* **official-bots:** activate opening book in expert bot (native-safe) ([260db25](https://git.janis-eccarius.de/NowChess/NowChessSystems/commit/260db25803ec55ce99e55782791eabdc190dfed4))
|
||||
* **official-bots:** add Google Colab notebook for NNUE training (NCS-111) ([#81](https://git.janis-eccarius.de/NowChess/NowChessSystems/issues/81)) ([fa10852](https://git.janis-eccarius.de/NowChess/NowChessSystems/commit/fa10852bc98451d4068ec6fb9e7a486b5e53ef5c))
|
||||
* **official-bots:** consume GameOver stream for bot cleanup ([#67](https://git.janis-eccarius.de/NowChess/NowChessSystems/issues/67)) ([db9d153](https://git.janis-eccarius.de/NowChess/NowChessSystems/commit/db9d1533912f4b41c4d1ca80ccffdde5d23d6ff6))
|
||||
* **official-bots:** implement king-relative (HalfKP) encoding in NNUE (NCS-109) ([#80](https://git.janis-eccarius.de/NowChess/NowChessSystems/issues/80)) ([44f376f](https://git.janis-eccarius.de/NowChess/NowChessSystems/commit/44f376f03221f086b898741436e13c93fd314dd1))
|
||||
* **official-bots:** make HybridBot veto actionable and use it for expert ([1df29cf](https://git.janis-eccarius.de/NowChess/NowChessSystems/commit/1df29cf3a6e21af3f396b2b7a6da67d978f941ae))
|
||||
* **official-bots:** park expert bot on tournament server at startup ([#75](https://git.janis-eccarius.de/NowChess/NowChessSystems/issues/75)) ([30295a4](https://git.janis-eccarius.de/NowChess/NowChessSystems/commit/30295a4bb95855ee8261c92278bb9ebc80ee12ee))
|
||||
* **official-bots:** resolve tournament bot token from Redis and account service ([386ddc5](https://git.janis-eccarius.de/NowChess/NowChessSystems/commit/386ddc5c19f8f893b16c6422aa5393b54c872e45))
|
||||
* **official-bots:** standalone self-play + one-shot dataset builder for NNUE training ([1c80abd](https://git.janis-eccarius.de/NowChess/NowChessSystems/commit/1c80abdb8a45814d642d43c633cde81ce7374c4f))
|
||||
* **tournament:** auto-join external tournaments and publish created ones ([#77](https://git.janis-eccarius.de/NowChess/NowChessSystems/issues/77)) ([9978b7e](https://git.janis-eccarius.de/NowChess/NowChessSystems/commit/9978b7ea78eb658a225a461b9cd339386c0c14f3))
|
||||
* **tournament:** federate tournaments across clusters with DB replication ([5b000a6](https://git.janis-eccarius.de/NowChess/NowChessSystems/commit/5b000a6e5f04ea6770d1c7ab6bfdaded77a99172))
|
||||
* **tournament:** seed external server registry from env var on startup ([845dc9c](https://git.janis-eccarius.de/NowChess/NowChessSystems/commit/845dc9c2935c8bc1be42541dfaf31c9a861d3272))
|
||||
* true-microservices ([#40](https://git.janis-eccarius.de/NowChess/NowChessSystems/issues/40)) ([5909242](https://git.janis-eccarius.de/NowChess/NowChessSystems/commit/590924254e8a2754de661a57a03e43f89ceb6299))
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* **bot:** include quiet promotions in quiescence search ([4938560](https://git.janis-eccarius.de/NowChess/NowChessSystems/commit/49385600147021cd29f00a8eecc6be7ba8470717))
|
||||
* **bot:** seed search with game history, add contempt and NNUE mop-up ([faf7eb3](https://git.janis-eccarius.de/NowChess/NowChessSystems/commit/faf7eb38ea7a0d3bc41ae4c2ef9a5195822f390c))
|
||||
* enable official bots to connect to external tournament server ([#71](https://git.janis-eccarius.de/NowChess/NowChessSystems/issues/71)) ([688d30e](https://git.janis-eccarius.de/NowChess/NowChessSystems/commit/688d30e2b10026923372be5fca3c63eaaee2de2a))
|
||||
* modified training pipeline ([9f9140c](https://git.janis-eccarius.de/NowChess/NowChessSystems/commit/9f9140cb585345cd244a1dfee1a06e51a5f7f7a8))
|
||||
* **official-bots:** configure JWT verification ([#72](https://git.janis-eccarius.de/NowChess/NowChessSystems/issues/72)) ([98c64fc](https://git.janis-eccarius.de/NowChess/NowChessSystems/commit/98c64fc0d56dc542beb31c75f4b9056d91de03cd))
|
||||
* **official-bots:** correct parkOn path from /api/bots to /api/account/bots ([1be9949](https://git.janis-eccarius.de/NowChess/NowChessSystems/commit/1be9949c0b5c6a1db535696620d77735050d6c93))
|
||||
* **official-bots:** derive tournament game color from game endpoint ([#79](https://git.janis-eccarius.de/NowChess/NowChessSystems/issues/79)) ([bfc4672](https://git.janis-eccarius.de/NowChess/NowChessSystems/commit/bfc46723e615bb9b65f7f9bba5f53877c4f079a7))
|
||||
* **official-bots:** discover tournament games by polling, not just the stream ([10113fd](https://git.janis-eccarius.de/NowChess/NowChessSystems/commit/10113fd0579b614d15870798d933bc9c495d2049))
|
||||
* **official-bots:** make botToken optional, fall back to env, fix 502 status ([f43d193](https://git.janis-eccarius.de/NowChess/NowChessSystems/commit/f43d1930d80670d810c57b54eaa3789854fa082c))
|
||||
* **official-bots:** NCS-70-auto-register official bots with account service ([#59](https://git.janis-eccarius.de/NowChess/NowChessSystems/issues/59)) ([7117a93](https://git.janis-eccarius.de/NowChess/NowChessSystems/commit/7117a93376272094d0b1a6abf2121254ce396684))
|
||||
* **official-bots:** park on external tournament servers using correct endpoint and token ([3188241](https://git.janis-eccarius.de/NowChess/NowChessSystems/commit/31882417377468b41bbe3ff94506aa4928024450))
|
||||
* **official-bots:** play games by polling state instead of NDJSON stream ([bfb15c7](https://git.janis-eccarius.de/NowChess/NowChessSystems/commit/bfb15c7299bd471d5e064a577ed10af98e2ea90a))
|
||||
* **official-bots:** play only own tournament games with correct color ([4651bb7](https://git.janis-eccarius.de/NowChess/NowChessSystems/commit/4651bb796f07a21bd013d9521b2dfe2e1078cebb))
|
||||
* **official-bots:** prevent Colab OOM in NNUE training ([e2b4342](https://git.janis-eccarius.de/NowChess/NowChessSystems/commit/e2b4342f602215b5e8de6fccafc4105525a1ddd1))
|
||||
* **official-bots:** prioritize Redis token over stale env var in joinTournament ([83dd2d4](https://git.janis-eccarius.de/NowChess/NowChessSystems/commit/83dd2d4335ca48eb3e5aa234a75367574276ba63))
|
||||
* **official-bots:** register with tournament server directly to get correct token ([64b5d55](https://git.janis-eccarius.de/NowChess/NowChessSystems/commit/64b5d5567f110c2fe152558c7de275a1e0b30e21))
|
||||
* **official-bots:** resolve per-difficulty bot token on tournament join ([fdf4c94](https://git.janis-eccarius.de/NowChess/NowChessSystems/commit/fdf4c94811d086996447bb4657fac1d9bd6e5a93))
|
||||
* **official-bots:** resume tournaments already joined after restart ([285b73e](https://git.janis-eccarius.de/NowChess/NowChessSystems/commit/285b73efbd6dd98cec410ade9eead9881d693a8f))
|
||||
* **official-bots:** stream NNUE features as sparse indices to stop host OOM ([9d65662](https://git.janis-eccarius.de/NowChess/NowChessSystems/commit/9d656624d85889f55746faa5704578e248f9b088))
|
||||
* **official-bots:** sync bots before token fetch on first startup after DB wipe ([b0ddb27](https://git.janis-eccarius.de/NowChess/NowChessSystems/commit/b0ddb274d23bca8b1b3f691ce0d643f33e0b54cd))
|
||||
* **official-bots:** use ThreadLocalRandom in PolyglotBook for native image ([1b30c3b](https://git.janis-eccarius.de/NowChess/NowChessSystems/commit/1b30c3be393d25712c8743d3d9057207f8bbb67c))
|
||||
|
||||
### Reverts
|
||||
|
||||
* Revert "refactor: update metrics paths formatting in application.yml for clarity" ([3870566](https://git.janis-eccarius.de/NowChess/NowChessSystems/commit/38705663498d5f47c40dafe2f26198589ede8656))
|
||||
## (2026-06-30)
|
||||
|
||||
### Features
|
||||
|
||||
* add initialization metrics for various services ([d438e97](https://git.janis-eccarius.de/NowChess/NowChessSystems/commit/d438e97f32bdde0bfc63c1b4a8cc810cdd093166))
|
||||
* add OpenTelemetry trace configuration with parentbased sampler ([3904d5a](https://git.janis-eccarius.de/NowChess/NowChessSystems/commit/3904d5ad8ad4930ddee65287a7bfab785a6148f5))
|
||||
* **analytics:** add Spark batch analytics module ([#70](https://git.janis-eccarius.de/NowChess/NowChessSystems/issues/70)) ([39f1657](https://git.janis-eccarius.de/NowChess/NowChessSystems/commit/39f1657e1db6e84889af338c43be8cb5c03c3ec3))
|
||||
* **bot:** add Lazy SMP parallel search for the NNUE bot ([3437dab](https://git.janis-eccarius.de/NowChess/NowChessSystems/commit/3437dab49b2cc3f7b7e726febb07ad759e878079))
|
||||
* **bot:** clock-aware time management and stream-driven tournament play ([45b5719](https://git.janis-eccarius.de/NowChess/NowChessSystems/commit/45b5719d630c9480398f51510cc598d2d6ce39db))
|
||||
* **bot:** implement bot-vs-bot harness for NNUE evaluation ([b2683a7](https://git.janis-eccarius.de/NowChess/NowChessSystems/commit/b2683a7f5ab6f3e41883736ac5eeaaee2e1ea5c1))
|
||||
* **config:** update application.yml for PostgreSQL and remove staging/production configurations ([2404e61](https://git.janis-eccarius.de/NowChess/NowChessSystems/commit/2404e6164c3b50ffccbea5238d636060d6abe4d6))
|
||||
* **config:** update application.yml for staging and production environments ([6113432](https://git.janis-eccarius.de/NowChess/NowChessSystems/commit/6113432a14c476a3a0dfc0d449e17d023697f2ba))
|
||||
* configure logging and add OpenTelemetry support ([#49](https://git.janis-eccarius.de/NowChess/NowChessSystems/issues/49)) ([d57c488](https://git.janis-eccarius.de/NowChess/NowChessSystems/commit/d57c4886612d1d92da0e1b79209fc83e6ef537a1))
|
||||
* **docker:** add .dockerignore and .gitignore files for build exclusions ([c987d8e](https://git.janis-eccarius.de/NowChess/NowChessSystems/commit/c987d8e258c0e6c4cfbdaa8381c64c410d7a2b83))
|
||||
* **docker:** add Dockerfiles for building Quarkus application in native and JVM modes ([3f2d2bb](https://git.janis-eccarius.de/NowChess/NowChessSystems/commit/3f2d2bb4c97fa8cddba66e1da4427c54236dfeed))
|
||||
* **docker:** add Dockerfiles for Quarkus application in JVM and native modes ([34b9933](https://git.janis-eccarius.de/NowChess/NowChessSystems/commit/34b993304670cf2aa62cd2f6460cee7b9864b08e))
|
||||
* **events:** migrate game-creation and bot flows to Redis Streams NCS-89 ([#62](https://git.janis-eccarius.de/NowChess/NowChessSystems/issues/62)) ([a24924c](https://git.janis-eccarius.de/NowChess/NowChessSystems/commit/a24924c23057db3d700a75dbc4333557789cd991))
|
||||
* **ncs-110:** feed NNUE root-move scores into search move ordering ([#83](https://git.janis-eccarius.de/NowChess/NowChessSystems/issues/83)) ([e4fee85](https://git.janis-eccarius.de/NowChess/NowChessSystems/commit/e4fee8513430093d46957970618935e99591519f))
|
||||
* NCS-78 Add Traceability to the Applications ([#46](https://git.janis-eccarius.de/NowChess/NowChessSystems/issues/46)) ([649566e](https://git.janis-eccarius.de/NowChess/NowChessSystems/commit/649566eb3fcf38f91c8896a739f74ea318af312d))
|
||||
* NCS-78 Add Traceability to the Applications ([#47](https://git.janis-eccarius.de/NowChess/NowChessSystems/issues/47)) ([87dfc6c](https://git.janis-eccarius.de/NowChess/NowChessSystems/commit/87dfc6c2bcce7f7d58fc641bd8d468a2e584c108))
|
||||
* NCS-82 add Swiss-system tournament module ([#55](https://git.janis-eccarius.de/NowChess/NowChessSystems/issues/55)) ([c5661de](https://git.janis-eccarius.de/NowChess/NowChessSystems/commit/c5661de4a0ebf4b33211f5a391840dcf744656b7))
|
||||
* **official-bots:** activate opening book in expert bot (native-safe) ([260db25](https://git.janis-eccarius.de/NowChess/NowChessSystems/commit/260db25803ec55ce99e55782791eabdc190dfed4))
|
||||
* **official-bots:** add Google Colab notebook for NNUE training (NCS-111) ([#81](https://git.janis-eccarius.de/NowChess/NowChessSystems/issues/81)) ([fa10852](https://git.janis-eccarius.de/NowChess/NowChessSystems/commit/fa10852bc98451d4068ec6fb9e7a486b5e53ef5c))
|
||||
* **official-bots:** consume GameOver stream for bot cleanup ([#67](https://git.janis-eccarius.de/NowChess/NowChessSystems/issues/67)) ([db9d153](https://git.janis-eccarius.de/NowChess/NowChessSystems/commit/db9d1533912f4b41c4d1ca80ccffdde5d23d6ff6))
|
||||
* **official-bots:** implement king-relative (HalfKP) encoding in NNUE (NCS-109) ([#80](https://git.janis-eccarius.de/NowChess/NowChessSystems/issues/80)) ([44f376f](https://git.janis-eccarius.de/NowChess/NowChessSystems/commit/44f376f03221f086b898741436e13c93fd314dd1))
|
||||
* **official-bots:** make HybridBot veto actionable and use it for expert ([1df29cf](https://git.janis-eccarius.de/NowChess/NowChessSystems/commit/1df29cf3a6e21af3f396b2b7a6da67d978f941ae))
|
||||
* **official-bots:** park expert bot on tournament server at startup ([#75](https://git.janis-eccarius.de/NowChess/NowChessSystems/issues/75)) ([30295a4](https://git.janis-eccarius.de/NowChess/NowChessSystems/commit/30295a4bb95855ee8261c92278bb9ebc80ee12ee))
|
||||
* **official-bots:** resolve tournament bot token from Redis and account service ([386ddc5](https://git.janis-eccarius.de/NowChess/NowChessSystems/commit/386ddc5c19f8f893b16c6422aa5393b54c872e45))
|
||||
* **official-bots:** standalone self-play + one-shot dataset builder for NNUE training ([1c80abd](https://git.janis-eccarius.de/NowChess/NowChessSystems/commit/1c80abdb8a45814d642d43c633cde81ce7374c4f))
|
||||
* **tournament:** auto-join external tournaments and publish created ones ([#77](https://git.janis-eccarius.de/NowChess/NowChessSystems/issues/77)) ([9978b7e](https://git.janis-eccarius.de/NowChess/NowChessSystems/commit/9978b7ea78eb658a225a461b9cd339386c0c14f3))
|
||||
* **tournament:** federate tournaments across clusters with DB replication ([5b000a6](https://git.janis-eccarius.de/NowChess/NowChessSystems/commit/5b000a6e5f04ea6770d1c7ab6bfdaded77a99172))
|
||||
* **tournament:** seed external server registry from env var on startup ([845dc9c](https://git.janis-eccarius.de/NowChess/NowChessSystems/commit/845dc9c2935c8bc1be42541dfaf31c9a861d3272))
|
||||
* true-microservices ([#40](https://git.janis-eccarius.de/NowChess/NowChessSystems/issues/40)) ([5909242](https://git.janis-eccarius.de/NowChess/NowChessSystems/commit/590924254e8a2754de661a57a03e43f89ceb6299))
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* **bot:** drop game-stream play, poll with low delay ([6e37a7d](https://git.janis-eccarius.de/NowChess/NowChessSystems/commit/6e37a7d20992b7d27c5ffebb12184916ed9d3120))
|
||||
* **bot:** include quiet promotions in quiescence search ([4938560](https://git.janis-eccarius.de/NowChess/NowChessSystems/commit/49385600147021cd29f00a8eecc6be7ba8470717))
|
||||
* **bot:** seed search with game history, add contempt and NNUE mop-up ([faf7eb3](https://git.janis-eccarius.de/NowChess/NowChessSystems/commit/faf7eb38ea7a0d3bc41ae4c2ef9a5195822f390c))
|
||||
* enable official bots to connect to external tournament server ([#71](https://git.janis-eccarius.de/NowChess/NowChessSystems/issues/71)) ([688d30e](https://git.janis-eccarius.de/NowChess/NowChessSystems/commit/688d30e2b10026923372be5fca3c63eaaee2de2a))
|
||||
* modified training pipeline ([9f9140c](https://git.janis-eccarius.de/NowChess/NowChessSystems/commit/9f9140cb585345cd244a1dfee1a06e51a5f7f7a8))
|
||||
* **official-bots:** configure JWT verification ([#72](https://git.janis-eccarius.de/NowChess/NowChessSystems/issues/72)) ([98c64fc](https://git.janis-eccarius.de/NowChess/NowChessSystems/commit/98c64fc0d56dc542beb31c75f4b9056d91de03cd))
|
||||
* **official-bots:** correct parkOn path from /api/bots to /api/account/bots ([1be9949](https://git.janis-eccarius.de/NowChess/NowChessSystems/commit/1be9949c0b5c6a1db535696620d77735050d6c93))
|
||||
* **official-bots:** derive tournament game color from game endpoint ([#79](https://git.janis-eccarius.de/NowChess/NowChessSystems/issues/79)) ([bfc4672](https://git.janis-eccarius.de/NowChess/NowChessSystems/commit/bfc46723e615bb9b65f7f9bba5f53877c4f079a7))
|
||||
* **official-bots:** discover tournament games by polling, not just the stream ([10113fd](https://git.janis-eccarius.de/NowChess/NowChessSystems/commit/10113fd0579b614d15870798d933bc9c495d2049))
|
||||
* **official-bots:** make botToken optional, fall back to env, fix 502 status ([f43d193](https://git.janis-eccarius.de/NowChess/NowChessSystems/commit/f43d1930d80670d810c57b54eaa3789854fa082c))
|
||||
* **official-bots:** NCS-70-auto-register official bots with account service ([#59](https://git.janis-eccarius.de/NowChess/NowChessSystems/issues/59)) ([7117a93](https://git.janis-eccarius.de/NowChess/NowChessSystems/commit/7117a93376272094d0b1a6abf2121254ce396684))
|
||||
* **official-bots:** park on external tournament servers using correct endpoint and token ([3188241](https://git.janis-eccarius.de/NowChess/NowChessSystems/commit/31882417377468b41bbe3ff94506aa4928024450))
|
||||
* **official-bots:** play games by polling state instead of NDJSON stream ([bfb15c7](https://git.janis-eccarius.de/NowChess/NowChessSystems/commit/bfb15c7299bd471d5e064a577ed10af98e2ea90a))
|
||||
* **official-bots:** play only own tournament games with correct color ([4651bb7](https://git.janis-eccarius.de/NowChess/NowChessSystems/commit/4651bb796f07a21bd013d9521b2dfe2e1078cebb))
|
||||
* **official-bots:** prevent Colab OOM in NNUE training ([e2b4342](https://git.janis-eccarius.de/NowChess/NowChessSystems/commit/e2b4342f602215b5e8de6fccafc4105525a1ddd1))
|
||||
* **official-bots:** prioritize Redis token over stale env var in joinTournament ([83dd2d4](https://git.janis-eccarius.de/NowChess/NowChessSystems/commit/83dd2d4335ca48eb3e5aa234a75367574276ba63))
|
||||
* **official-bots:** register with tournament server directly to get correct token ([64b5d55](https://git.janis-eccarius.de/NowChess/NowChessSystems/commit/64b5d5567f110c2fe152558c7de275a1e0b30e21))
|
||||
* **official-bots:** resolve per-difficulty bot token on tournament join ([fdf4c94](https://git.janis-eccarius.de/NowChess/NowChessSystems/commit/fdf4c94811d086996447bb4657fac1d9bd6e5a93))
|
||||
* **official-bots:** resume tournaments already joined after restart ([285b73e](https://git.janis-eccarius.de/NowChess/NowChessSystems/commit/285b73efbd6dd98cec410ade9eead9881d693a8f))
|
||||
* **official-bots:** stream NNUE features as sparse indices to stop host OOM ([9d65662](https://git.janis-eccarius.de/NowChess/NowChessSystems/commit/9d656624d85889f55746faa5704578e248f9b088))
|
||||
* **official-bots:** sync bots before token fetch on first startup after DB wipe ([b0ddb27](https://git.janis-eccarius.de/NowChess/NowChessSystems/commit/b0ddb274d23bca8b1b3f691ce0d643f33e0b54cd))
|
||||
* **official-bots:** use ThreadLocalRandom in PolyglotBook for native image ([1b30c3b](https://git.janis-eccarius.de/NowChess/NowChessSystems/commit/1b30c3be393d25712c8743d3d9057207f8bbb67c))
|
||||
|
||||
### Reverts
|
||||
|
||||
* Revert "refactor: update metrics paths formatting in application.yml for clarity" ([3870566](https://git.janis-eccarius.de/NowChess/NowChessSystems/commit/38705663498d5f47c40dafe2f26198589ede8656))
|
||||
|
||||
@@ -3,4 +3,33 @@ package de.nowchess.bot
|
||||
import de.nowchess.api.game.GameContext
|
||||
import de.nowchess.api.move.Move
|
||||
|
||||
type Bot = GameContext => Option[Move]
|
||||
/** Remaining wall-clock for the side to move and the Fischer increment, both in milliseconds. [[TimeControl.Unlimited]]
|
||||
* is the sentinel for callers without a real clock (local play, self-play, tests): bots then fall back to their own
|
||||
* fixed budgets.
|
||||
*/
|
||||
final case class TimeControl(remainingMs: Long, incrementMs: Long):
|
||||
def isClocked: Boolean = remainingMs >= 0L
|
||||
def budgetMs: Long = TimeControl.budget(remainingMs, incrementMs)
|
||||
|
||||
object TimeControl:
|
||||
val Unlimited: TimeControl = TimeControl(-1L, 0L)
|
||||
|
||||
private val OverheadMs = 1500L
|
||||
private val PanicMs = 20000L
|
||||
private val MaxBudget = 8000L
|
||||
private val PanicCap = 2500L
|
||||
private val FloorMs = 50L
|
||||
|
||||
def budget(remainingMs: Long, incrementMs: Long): Long =
|
||||
val usable = math.max(0L, remainingMs - OverheadMs)
|
||||
if usable <= 0L then FloorMs
|
||||
else if remainingMs < PanicMs then clamp(usable / 15 + incrementMs / 2, PanicCap)
|
||||
else clamp(usable / 30 + incrementMs * 4 / 5, MaxBudget)
|
||||
|
||||
private def clamp(value: Long, ceiling: Long): Long =
|
||||
math.max(FloorMs, math.min(value, ceiling))
|
||||
|
||||
trait Bot:
|
||||
def move(context: GameContext, time: TimeControl): Option[Move]
|
||||
def apply(context: GameContext): Option[Move] = move(context, TimeControl.Unlimited)
|
||||
def apply(context: GameContext, time: TimeControl): Option[Move] = move(context, time)
|
||||
|
||||
@@ -1,25 +1,28 @@
|
||||
package de.nowchess.bot.bots
|
||||
|
||||
import de.nowchess.bot.Bot
|
||||
import de.nowchess.api.game.GameContext
|
||||
import de.nowchess.api.move.Move
|
||||
import de.nowchess.api.rules.RuleSet
|
||||
import de.nowchess.bot.bots.classic.EvaluationClassic
|
||||
import de.nowchess.bot.logic.AlphaBetaSearch
|
||||
import de.nowchess.bot.util.PolyglotBook
|
||||
import de.nowchess.bot.{BotDifficulty, BotMoveRepetition}
|
||||
import de.nowchess.bot.{Bot, BotDifficulty, BotMoveRepetition, TimeControl}
|
||||
import de.nowchess.rules.sets.DefaultRules
|
||||
|
||||
object ClassicalBot:
|
||||
private val defaultBudgetMs = 1000L
|
||||
|
||||
def apply(
|
||||
difficulty: BotDifficulty,
|
||||
rules: RuleSet = DefaultRules,
|
||||
book: Option[PolyglotBook] = None,
|
||||
): Bot =
|
||||
val search = AlphaBetaSearch(rules, weights = EvaluationClassic)
|
||||
val timeBudgetMs = 1000L
|
||||
context =>
|
||||
val blockedMoves = BotMoveRepetition.blockedMoves(context)
|
||||
book
|
||||
.flatMap(_.probe(context))
|
||||
.filterNot(blockedMoves.contains)
|
||||
.orElse(search.bestMoveWithTime(context, timeBudgetMs, blockedMoves))
|
||||
val search = AlphaBetaSearch(rules, weights = EvaluationClassic)
|
||||
new Bot:
|
||||
def move(context: GameContext, time: TimeControl): Option[Move] =
|
||||
val budget = if time.isClocked then time.budgetMs else defaultBudgetMs
|
||||
val blockedMoves = BotMoveRepetition.blockedMoves(context)
|
||||
book
|
||||
.flatMap(_.probe(context))
|
||||
.filterNot(blockedMoves.contains)
|
||||
.orElse(search.bestMoveWithTime(context, budget, blockedMoves))
|
||||
|
||||
@@ -7,12 +7,20 @@ import de.nowchess.api.rules.RuleSet
|
||||
import de.nowchess.bot.ai.Evaluation
|
||||
import de.nowchess.bot.bots.classic.EvaluationClassic
|
||||
import de.nowchess.bot.bots.nnue.EvaluationNNUE
|
||||
import de.nowchess.bot.logic.{AlphaBetaSearch, TranspositionTable}
|
||||
import de.nowchess.bot.logic.{ParallelSearch, TranspositionTable}
|
||||
import de.nowchess.bot.util.PolyglotBook
|
||||
import de.nowchess.bot.{BotDifficulty, BotMoveRepetition, Config}
|
||||
import de.nowchess.bot.{Bot, BotDifficulty, BotMoveRepetition, Config, TimeControl}
|
||||
import de.nowchess.rules.sets.DefaultRules
|
||||
|
||||
object HybridBot:
|
||||
|
||||
private def defaultThreads: Int =
|
||||
sys.env.get("NNUE_SEARCH_THREADS").flatMap(_.toIntOption).filter(_ >= 1).getOrElse(1)
|
||||
|
||||
// The veto re-search must share the move's budget, not double it: give the main search the bulk and
|
||||
// reserve a slice for the at-most-one veto re-search so a vetoed move never costs two full budgets.
|
||||
private val MainSearchShare = 0.7
|
||||
|
||||
def apply(
|
||||
difficulty: BotDifficulty,
|
||||
rules: RuleSet = DefaultRules,
|
||||
@@ -20,28 +28,34 @@ object HybridBot:
|
||||
nnueEvaluation: Evaluation = EvaluationNNUE,
|
||||
classicalEvaluation: Evaluation = EvaluationClassic,
|
||||
vetoReporter: String => Unit = println(_),
|
||||
searchThreads: Int = defaultThreads,
|
||||
): Bot =
|
||||
val search = AlphaBetaSearch(rules, TranspositionTable(), classicalEvaluation)
|
||||
context =>
|
||||
val blockedMoves = BotMoveRepetition.blockedMoves(context)
|
||||
// Use ParallelSearch to enable multi-threaded (SMP) search similar to NNUEBot
|
||||
val search = ParallelSearch(rules, TranspositionTable(), () => classicalEvaluation, searchThreads)
|
||||
new Bot:
|
||||
def move(context: GameContext, time: TimeControl): Option[Move] =
|
||||
val totalBudget = if time.isClocked then time.budgetMs else Config.TIME_LIMIT_MS
|
||||
val mainBudget = math.max(1L, (totalBudget * MainSearchShare).toLong)
|
||||
val vetoBudget = math.max(1L, totalBudget - mainBudget)
|
||||
val blockedMoves = BotMoveRepetition.blockedMoves(context)
|
||||
|
||||
def nnueScore(move: Move): Int = nnueEvaluation.evaluate(rules.applyMove(context)(move))
|
||||
def classicalScore(move: Move): Int = classicalEvaluation.evaluate(rules.applyMove(context)(move))
|
||||
def nnueScore(m: Move): Int = nnueEvaluation.evaluate(rules.applyMove(context)(m))
|
||||
def classicalScore(m: Move): Int = classicalEvaluation.evaluate(rules.applyMove(context)(m))
|
||||
|
||||
def refine(move: Move): Move =
|
||||
val moveNnue = nnueScore(move)
|
||||
if (classicalScore(move) - moveNnue).abs <= Config.VETO_THRESHOLD then move
|
||||
else
|
||||
search
|
||||
.bestMoveWithTime(context, Config.TIME_LIMIT_MS, blockedMoves + move)
|
||||
.filterNot(blockedMoves.contains)
|
||||
.filter(alt => nnueScore(alt) < moveNnue)
|
||||
.map { alt =>
|
||||
vetoReporter(f"[Veto] ${move.from}->${move.to} replaced by ${alt.from}->${alt.to} — NNUE prefers it")
|
||||
alt
|
||||
}
|
||||
.getOrElse(move)
|
||||
def refine(m: Move): Move =
|
||||
val moveNnue = nnueScore(m)
|
||||
if (classicalScore(m) - moveNnue).abs <= Config.VETO_THRESHOLD then m
|
||||
else
|
||||
search
|
||||
.bestMoveWithTime(context, vetoBudget, blockedMoves + m)
|
||||
.filterNot(blockedMoves.contains)
|
||||
.filter(alt => nnueScore(alt) < moveNnue)
|
||||
.map { alt =>
|
||||
vetoReporter(f"[Veto] ${m.from}->${m.to} replaced by ${alt.from}->${alt.to} — NNUE prefers it")
|
||||
alt
|
||||
}
|
||||
.getOrElse(m)
|
||||
|
||||
book.flatMap(_.probe(context)).filterNot(blockedMoves.contains).orElse {
|
||||
search.bestMoveWithTime(context, Config.TIME_LIMIT_MS, blockedMoves).map(refine)
|
||||
}
|
||||
book.flatMap(_.probe(context)).filterNot(blockedMoves.contains).orElse {
|
||||
search.bestMoveWithTime(context, mainBudget, blockedMoves).map(refine)
|
||||
}
|
||||
|
||||
@@ -1,37 +1,41 @@
|
||||
package de.nowchess.bot.bots
|
||||
|
||||
import de.nowchess.bot.Bot
|
||||
import de.nowchess.api.game.GameContext
|
||||
import de.nowchess.api.move.Move
|
||||
import de.nowchess.api.rules.RuleSet
|
||||
import de.nowchess.bot.bots.nnue.EvaluationNNUE
|
||||
import de.nowchess.bot.logic.AlphaBetaSearch
|
||||
import de.nowchess.bot.logic.{ParallelSearch, TranspositionTable}
|
||||
import de.nowchess.bot.util.{PolyglotBook, ZobristHash}
|
||||
import de.nowchess.bot.{BotDifficulty, BotMoveRepetition}
|
||||
import de.nowchess.bot.{Bot, BotDifficulty, BotMoveRepetition, TimeControl}
|
||||
import de.nowchess.rules.sets.DefaultRules
|
||||
|
||||
object NNUEBot:
|
||||
private def defaultThreads: Int =
|
||||
sys.env.get("NNUE_SEARCH_THREADS").flatMap(_.toIntOption).filter(_ >= 1).getOrElse(1)
|
||||
|
||||
def apply(
|
||||
difficulty: BotDifficulty,
|
||||
rules: RuleSet = DefaultRules,
|
||||
book: Option[PolyglotBook] = None,
|
||||
fixedMoveTimeMs: Option[Long] = None,
|
||||
searchThreads: Int = defaultThreads,
|
||||
): Bot =
|
||||
val search = AlphaBetaSearch(rules, weights = EvaluationNNUE)
|
||||
context =>
|
||||
val blockedMoves = BotMoveRepetition.blockedMoves(context)
|
||||
book
|
||||
.flatMap(_.probe(context))
|
||||
.filterNot(blockedMoves.contains)
|
||||
.orElse {
|
||||
val moves = BotMoveRepetition.filterAllowed(context, rules.allLegalMoves(context))
|
||||
if moves.isEmpty then None
|
||||
else
|
||||
val scored = batchEvaluateRoot(rules, context, moves)
|
||||
val bestMove = scored.maxBy(_._2)._1
|
||||
val budget = fixedMoveTimeMs.getOrElse(allocateTime(scored))
|
||||
search.bestMoveWithTime(context, budget, blockedMoves, scored.toMap).orElse(Some(bestMove))
|
||||
}
|
||||
val search = ParallelSearch(rules, TranspositionTable(), () => EvaluationNNUE.freshEvaluator(), searchThreads)
|
||||
new Bot:
|
||||
def move(context: GameContext, time: TimeControl): Option[Move] =
|
||||
val blockedMoves = BotMoveRepetition.blockedMoves(context)
|
||||
book
|
||||
.flatMap(_.probe(context))
|
||||
.filterNot(blockedMoves.contains)
|
||||
.orElse {
|
||||
val moves = BotMoveRepetition.filterAllowed(context, rules.allLegalMoves(context))
|
||||
if moves.isEmpty then None
|
||||
else
|
||||
val scored = batchEvaluateRoot(rules, context, moves)
|
||||
val bestMove = scored.maxBy(_._2)._1
|
||||
val budget = fixedMoveTimeMs.getOrElse(if time.isClocked then time.budgetMs else allocateTime(scored))
|
||||
search.bestMoveWithTime(context, budget, blockedMoves, scored.toMap).orElse(Some(bestMove))
|
||||
}
|
||||
|
||||
private def batchEvaluateRoot(rules: RuleSet, context: GameContext, moves: List[Move]): List[(Move, Int)] =
|
||||
EvaluationNNUE.initAccumulator(context)
|
||||
|
||||
+30
-3
@@ -4,9 +4,11 @@ import de.nowchess.api.game.GameContext
|
||||
import de.nowchess.api.move.Move
|
||||
import de.nowchess.bot.ai.Evaluation
|
||||
|
||||
object EvaluationNNUE extends Evaluation:
|
||||
|
||||
private val nnue = NNUE(NbaiLoader.loadDefault())
|
||||
/** One independent NNUE evaluator: wraps its own [[NNUE]] (own accumulator stack, scratch buffers and eval cache) plus
|
||||
* the endgame mop-up correction. Independent instances may run concurrently as long as they share only the read-only
|
||||
* [[NNUEWeights]].
|
||||
*/
|
||||
final class NNUEEvaluator(nnue: NNUE) extends Evaluation:
|
||||
|
||||
val CHECKMATE_SCORE: Int = 10_000_000
|
||||
val DRAW_SCORE: Int = 0
|
||||
@@ -29,3 +31,28 @@ object EvaluationNNUE extends Evaluation:
|
||||
|
||||
override def evaluateAccumulator(ply: Int, context: GameContext, hash: Long): Int =
|
||||
nnue.evaluateAtPlyWithValidation(ply, context.turn, hash, context.board) + MopUp.score(context)
|
||||
|
||||
/** Default singleton evaluator plus a factory for independent per-thread evaluators that share the loaded weights. */
|
||||
object EvaluationNNUE extends Evaluation:
|
||||
|
||||
private val weights = NNUEWeights(NbaiLoader.loadDefault())
|
||||
private val default = NNUEEvaluator(NNUE(weights))
|
||||
|
||||
/** Build a fresh evaluator backed by its own [[NNUE]] but sharing the immutable [[weights]] — one per search thread.
|
||||
*/
|
||||
def freshEvaluator(): Evaluation = NNUEEvaluator(NNUE(weights))
|
||||
|
||||
val CHECKMATE_SCORE: Int = default.CHECKMATE_SCORE
|
||||
val DRAW_SCORE: Int = default.DRAW_SCORE
|
||||
|
||||
def evaluate(context: GameContext): Int = default.evaluate(context)
|
||||
|
||||
override def initAccumulator(context: GameContext): Unit = default.initAccumulator(context)
|
||||
|
||||
override def copyAccumulator(parentPly: Int, childPly: Int): Unit = default.copyAccumulator(parentPly, childPly)
|
||||
|
||||
override def pushAccumulator(childPly: Int, move: Move, parent: GameContext, child: GameContext): Unit =
|
||||
default.pushAccumulator(childPly, move, parent, child)
|
||||
|
||||
override def evaluateAccumulator(ply: Int, context: GameContext, hash: Long): Int =
|
||||
default.evaluateAccumulator(ply, context, hash)
|
||||
|
||||
@@ -32,7 +32,7 @@ object MopUp:
|
||||
PROXIMITY_WEIGHT * (14 - kingDistance(winnerKing, loserKing))).getOrElse(0)
|
||||
|
||||
private def loneKingColor(context: GameContext): Option[Color] =
|
||||
val nonKing = context.board.pieces.values.filter(_.pieceType != PieceType.King)
|
||||
val nonKing = context.board.pieces.values.filter(_.pieceType != PieceType.King)
|
||||
val whiteHasOther = nonKing.exists(_.color == Color.White)
|
||||
val blackHasOther = nonKing.exists(_.color == Color.Black)
|
||||
if whiteHasOther == blackHasOther then None
|
||||
@@ -48,7 +48,8 @@ object MopUp:
|
||||
case PieceType.Rook => 500
|
||||
case PieceType.Bishop => 330
|
||||
case PieceType.Knight => 320
|
||||
case _ => 0)
|
||||
case _ => 0
|
||||
)
|
||||
}
|
||||
|
||||
private def centerDistance(sq: Square): Int =
|
||||
|
||||
@@ -4,20 +4,20 @@ import de.nowchess.api.board.{Board, Color, Piece, PieceType, Square}
|
||||
import de.nowchess.api.game.GameContext
|
||||
import de.nowchess.api.move.{Move, MoveType, PromotionPiece}
|
||||
|
||||
class NNUE(model: NbaiModel):
|
||||
object NNUE:
|
||||
def apply(model: NbaiModel): NNUE = new NNUE(NNUEWeights(model))
|
||||
def apply(weights: NNUEWeights): NNUE = new NNUE(weights)
|
||||
|
||||
/** Per-thread NNUE evaluator: owns the mutable accumulator stack, scratch buffers and eval cache, while sharing the
|
||||
* read-only [[NNUEWeights]]. Construct one instance per search thread (cheap — only buffer allocation); they may all
|
||||
* share a single weights instance.
|
||||
*/
|
||||
class NNUE(weights: NNUEWeights):
|
||||
|
||||
import weights.{accSize, l1WeightsT, model, HALF_SIZE}
|
||||
|
||||
private val HALF_SIZE = 49152 // 64 king-squares × 12 piece-types × 64 piece-squares
|
||||
private val featureSize = model.layers(0).inputSize // 98304 (= HALF_SIZE * 2) for king-relative
|
||||
private val accSize = model.layers(0).outputSize
|
||||
private val validateAccum = sys.env.contains("NNUE_VALIDATE")
|
||||
|
||||
// Column-major L1 weights: l1WeightsT(featureIdx * accSize + outputIdx)
|
||||
private val l1WeightsT: Array[Float] =
|
||||
val w = model.weights(0).weights
|
||||
val t = new Array[Float](featureSize * accSize)
|
||||
for j <- 0 until featureSize; i <- 0 until accSize do t(j * accSize + i) = w(i * featureSize + j)
|
||||
t
|
||||
|
||||
// ── Accumulator stack ────────────────────────────────────────────────────
|
||||
|
||||
private val MAX_PLY = 128
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
package de.nowchess.bot.bots.nnue
|
||||
|
||||
/** Immutable, shareable NNUE parameters.
|
||||
*
|
||||
* Heavy to build (transposes the L1 weight matrix once, ~98304 × accSize floats) but read-only thereafter, so a single
|
||||
* instance is safely shared across many per-thread [[NNUE]] evaluators. Holds no accumulator or scratch state — those
|
||||
* live on each [[NNUE]] instance — which is what makes parallel search (independent evaluators sharing these weights)
|
||||
* possible without duplicating the weight matrix.
|
||||
*/
|
||||
class NNUEWeights(val model: NbaiModel):
|
||||
|
||||
val HALF_SIZE: Int = 49152 // 64 king-squares × 12 piece-types × 64 piece-squares
|
||||
val featureSize: Int = model.layers(0).inputSize // 98304 (= HALF_SIZE * 2) for king-relative
|
||||
val accSize: Int = model.layers(0).outputSize
|
||||
|
||||
// Column-major L1 weights: l1WeightsT(featureIdx * accSize + outputIdx)
|
||||
val l1WeightsT: Array[Float] =
|
||||
val w = model.weights(0).weights
|
||||
val t = new Array[Float](featureSize * accSize)
|
||||
for j <- 0 until featureSize; i <- 0 until accSize do t(j * accSize + i) = w(i * featureSize + j)
|
||||
t
|
||||
@@ -95,7 +95,7 @@ final class AlphaBetaSearch(
|
||||
bestMoveWithTime(context, timeBudgetMs, Set.empty)
|
||||
|
||||
def bestMoveWithTime(context: GameContext, timeBudgetMs: Long, excludedRootMoves: Set[Move]): Option[Move] =
|
||||
doTimedSearch(context, timeBudgetMs, excludedRootMoves, Map.empty)
|
||||
doTimedSearch(context, timeBudgetMs, excludedRootMoves, Map.empty, clearTt = true)
|
||||
|
||||
def bestMoveWithTime(
|
||||
context: GameContext,
|
||||
@@ -103,15 +103,27 @@ final class AlphaBetaSearch(
|
||||
excludedRootMoves: Set[Move],
|
||||
hints: Map[Move, Int],
|
||||
): Option[Move] =
|
||||
doTimedSearch(context, timeBudgetMs, excludedRootMoves, hints)
|
||||
doTimedSearch(context, timeBudgetMs, excludedRootMoves, hints, clearTt = true)
|
||||
|
||||
/** Timed search over a transposition table that is shared with other workers (Lazy SMP): the caller is responsible
|
||||
* for clearing it once before launching all workers, so this worker must not clear it.
|
||||
*/
|
||||
def bestMoveWithTimeSharedTt(
|
||||
context: GameContext,
|
||||
timeBudgetMs: Long,
|
||||
excludedRootMoves: Set[Move],
|
||||
hints: Map[Move, Int],
|
||||
): Option[Move] =
|
||||
doTimedSearch(context, timeBudgetMs, excludedRootMoves, hints, clearTt = false)
|
||||
|
||||
private def doTimedSearch(
|
||||
context: GameContext,
|
||||
timeBudgetMs: Long,
|
||||
excludedRootMoves: Set[Move],
|
||||
hints: Map[Move, Int],
|
||||
clearTt: Boolean,
|
||||
): Option[Move] =
|
||||
tt.clear()
|
||||
if clearTt then tt.clear()
|
||||
ordering.clear()
|
||||
weights.initAccumulator(context)
|
||||
timeStartMs.set(System.currentTimeMillis)
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
package de.nowchess.bot.logic
|
||||
|
||||
import de.nowchess.api.game.GameContext
|
||||
import de.nowchess.api.move.Move
|
||||
import de.nowchess.api.rules.RuleSet
|
||||
import de.nowchess.bot.ai.Evaluation
|
||||
import de.nowchess.rules.sets.DefaultRules
|
||||
|
||||
import java.util.concurrent.{Callable, Executors}
|
||||
import scala.jdk.CollectionConverters.*
|
||||
|
||||
/** Lazy SMP search coordinator.
|
||||
*
|
||||
* Runs `numThreads` independent [[AlphaBetaSearch]] workers over one shared transposition table for the same time
|
||||
* budget. Every worker has its own evaluator (independent NNUE accumulator) and move-ordering state, but they share
|
||||
* the thread-safe TT, so faster-progressing threads deepen entries the others reuse. Only the main worker's move is
|
||||
* returned; helpers exist purely to enrich the shared TT.
|
||||
*
|
||||
* `numThreads <= 1` runs a single worker via the ordinary clearing entry point, byte-identical to sequential
|
||||
* [[AlphaBetaSearch]].
|
||||
*/
|
||||
final class ParallelSearch(
|
||||
rules: RuleSet = DefaultRules,
|
||||
tt: TranspositionTable = TranspositionTable(),
|
||||
evalFactory: () => Evaluation,
|
||||
numThreads: Int = 1,
|
||||
):
|
||||
|
||||
private val threadCount = math.max(1, numThreads)
|
||||
private val workers = Vector.fill(threadCount)(AlphaBetaSearch(rules, tt, evalFactory()))
|
||||
|
||||
def bestMoveWithTime(
|
||||
context: GameContext,
|
||||
timeBudgetMs: Long,
|
||||
excludedRootMoves: Set[Move] = Set.empty,
|
||||
hints: Map[Move, Int] = Map.empty,
|
||||
): Option[Move] =
|
||||
if threadCount == 1 then workers.head.bestMoveWithTime(context, timeBudgetMs, excludedRootMoves, hints)
|
||||
else runParallel(context, timeBudgetMs, excludedRootMoves, hints)
|
||||
|
||||
private def runParallel(
|
||||
context: GameContext,
|
||||
timeBudgetMs: Long,
|
||||
excludedRootMoves: Set[Move],
|
||||
hints: Map[Move, Int],
|
||||
): Option[Move] =
|
||||
tt.clear()
|
||||
val pool = Executors.newFixedThreadPool(threadCount)
|
||||
try
|
||||
val tasks = workers.map { worker =>
|
||||
new Callable[Option[Move]]:
|
||||
def call(): Option[Move] =
|
||||
worker.bestMoveWithTimeSharedTt(context, timeBudgetMs, excludedRootMoves, hints)
|
||||
}
|
||||
pool.invokeAll(tasks.asJava).get(0).get()
|
||||
finally pool.shutdownNow()
|
||||
@@ -0,0 +1,180 @@
|
||||
package de.nowchess.bot.selfplay
|
||||
|
||||
import de.nowchess.api.game.GameContext
|
||||
import de.nowchess.api.move.Move
|
||||
import de.nowchess.api.rules.RuleSet
|
||||
import de.nowchess.api.board.Color
|
||||
import de.nowchess.bot.{Bot, BotDifficulty}
|
||||
import de.nowchess.bot.bots.{HybridBot, NNUEBot}
|
||||
import de.nowchess.io.fen.FenExporter
|
||||
import de.nowchess.rules.sets.DefaultRules
|
||||
|
||||
import java.io.{BufferedWriter, FileWriter}
|
||||
import java.nio.file.{Files, Path}
|
||||
import scala.collection.mutable
|
||||
import scala.util.Random
|
||||
|
||||
enum GameResult:
|
||||
case Bot1Wins
|
||||
case Bot2Wins
|
||||
case Draw
|
||||
|
||||
/** Standalone bot-vs-bot harness. Runs two NNUEBots against each other from randomised openings and writes the visited
|
||||
* positions as one FEN per line. Each bot can use different difficulty levels and weight files.
|
||||
*
|
||||
* Games run sequentially. Bots alternate: bot1 plays white, then bot1 plays black, alternating per game to ensure fair
|
||||
* evaluation.
|
||||
*/
|
||||
object BotVsBotMain:
|
||||
|
||||
private case class Config(
|
||||
games: Int = 1,
|
||||
out: String = "modules/official-bots/python/data/botvbot.txt",
|
||||
weights1: Option[String] = None,
|
||||
weights2: Option[String] = None,
|
||||
difficulty1: String = "Hard",
|
||||
difficulty2: String = "Hard",
|
||||
moveTimeMs: Long = 1000L,
|
||||
randomPlies: Int = 8,
|
||||
maxPlies: Int = 200,
|
||||
seed: Long = System.nanoTime(),
|
||||
)
|
||||
|
||||
def main(args: Array[String]): Unit =
|
||||
val config = parse(args.toList, Config())
|
||||
|
||||
val rules = DefaultRules
|
||||
val difficulty1 = parseDifficulty(config.difficulty1)
|
||||
val difficulty2 = parseDifficulty(config.difficulty2)
|
||||
|
||||
config.weights1.foreach(System.setProperty("nnue.weights", _))
|
||||
val bot1 = HybridBot(difficulty1, rules, searchThreads = 6)
|
||||
|
||||
config.weights2.foreach(System.setProperty("nnue.weights", _))
|
||||
val bot2 = HybridBot(difficulty2, rules)
|
||||
|
||||
val rng = new Random(config.seed)
|
||||
val seen = mutable.HashSet.empty[String]
|
||||
var bot1Wins = 0
|
||||
var bot2Wins = 0
|
||||
var draws = 0
|
||||
|
||||
Files.createDirectories(Path.of(config.out).toAbsolutePath.getParent)
|
||||
val writer = new BufferedWriter(new FileWriter(config.out))
|
||||
try
|
||||
var game = 0
|
||||
while game < config.games do
|
||||
val bot1AsWhite = game % 2 == 0
|
||||
val result = playGame(rules, bot1, bot2, rng, config, seen, writer, bot1AsWhite)
|
||||
game += 1
|
||||
|
||||
result match
|
||||
case Some(GameResult.Bot1Wins) =>
|
||||
bot1Wins += 1
|
||||
println(s"Game $game: Bot1 wins${if bot1AsWhite then " (as white)" else " (as black)"}")
|
||||
case Some(GameResult.Bot2Wins) =>
|
||||
bot2Wins += 1
|
||||
println(s"Game $game: Bot2 wins${if !bot1AsWhite then " (as white)" else " (as black)"}")
|
||||
case Some(GameResult.Draw) =>
|
||||
draws += 1
|
||||
println(s"Game $game: Draw")
|
||||
case None => ()
|
||||
|
||||
if game % 25 == 0 then
|
||||
writer.flush()
|
||||
println(
|
||||
s" Progress: $game/${config.games} | Positions: ${seen.size} | Bot1: $bot1Wins, Bot2: $bot2Wins, Draws: $draws\n",
|
||||
)
|
||||
finally writer.close()
|
||||
println(s"\nFinal Statistics:")
|
||||
println(s" Bot1 wins: $bot1Wins")
|
||||
println(s" Bot2 wins: $bot2Wins")
|
||||
println(s" Draws: $draws")
|
||||
println(s" Positions: ${seen.size} -> ${config.out}")
|
||||
|
||||
private def playGame(
|
||||
rules: RuleSet,
|
||||
bot1: Bot,
|
||||
bot2: Bot,
|
||||
rng: Random,
|
||||
config: Config,
|
||||
seen: mutable.HashSet[String],
|
||||
writer: BufferedWriter,
|
||||
bot1AsWhite: Boolean,
|
||||
): Option[GameResult] =
|
||||
randomOpening(rules, rng, config.randomPlies, GameContext.initial) match
|
||||
case None => None
|
||||
case Some(start) =>
|
||||
var ctx = start
|
||||
var plies = config.randomPlies
|
||||
var live = true
|
||||
while live && plies < config.maxPlies do
|
||||
if isTerminal(rules, ctx) then live = false
|
||||
else
|
||||
val currentBot =
|
||||
if (plies - config.randomPlies) % 2 == 0 then if bot1AsWhite then bot1 else bot2
|
||||
else if bot1AsWhite then bot2
|
||||
else bot1
|
||||
|
||||
currentBot(ctx) match
|
||||
case None => live = false
|
||||
case Some(move) =>
|
||||
ctx = rules.applyMove(ctx)(move)
|
||||
plies += 1
|
||||
record(rules, ctx, seen, writer)
|
||||
|
||||
determineWinner(rules, ctx, bot1AsWhite)
|
||||
|
||||
private def determineWinner(rules: RuleSet, ctx: GameContext, bot1AsWhite: Boolean): Option[GameResult] =
|
||||
val legalMoves = rules.allLegalMoves(ctx)
|
||||
|
||||
if legalMoves.nonEmpty then Some(GameResult.Draw)
|
||||
else if rules.isCheck(ctx) then
|
||||
if ctx.turn == (if bot1AsWhite then Color.Black else Color.White) then Some(GameResult.Bot1Wins)
|
||||
else Some(GameResult.Bot2Wins)
|
||||
else if rules.isFiftyMoveRule(ctx) || rules.isThreefoldRepetition(ctx) || rules.isInsufficientMaterial(ctx) then
|
||||
Some(GameResult.Draw)
|
||||
else Some(GameResult.Draw)
|
||||
|
||||
private def randomOpening(rules: RuleSet, rng: Random, plies: Int, start: GameContext): Option[GameContext] =
|
||||
var ctx = start
|
||||
var i = 0
|
||||
while i < plies do
|
||||
val legal = rules.allLegalMoves(ctx)
|
||||
if legal.isEmpty then return None
|
||||
ctx = rules.applyMove(ctx)(legal(rng.nextInt(legal.size)))
|
||||
i += 1
|
||||
Some(ctx)
|
||||
|
||||
private def record(rules: RuleSet, ctx: GameContext, seen: mutable.HashSet[String], writer: BufferedWriter): Unit =
|
||||
if !rules.isCheck(ctx) && !isTerminal(rules, ctx) then
|
||||
val fen = FenExporter.gameContextToFen(ctx)
|
||||
if seen.add(fen) then
|
||||
writer.write(fen)
|
||||
writer.newLine()
|
||||
|
||||
private def isTerminal(rules: RuleSet, ctx: GameContext): Boolean =
|
||||
rules.allLegalMoves(ctx).isEmpty ||
|
||||
rules.isInsufficientMaterial(ctx) ||
|
||||
rules.isFiftyMoveRule(ctx) ||
|
||||
rules.isThreefoldRepetition(ctx)
|
||||
|
||||
private def parse(args: List[String], acc: Config): Config = args match
|
||||
case "--games" :: v :: rest => parse(rest, acc.copy(games = v.toInt))
|
||||
case "--out" :: v :: rest => parse(rest, acc.copy(out = v))
|
||||
case "--weights1" :: v :: rest => parse(rest, acc.copy(weights1 = Some(v)))
|
||||
case "--weights2" :: v :: rest => parse(rest, acc.copy(weights2 = Some(v)))
|
||||
case "--difficulty1" :: v :: rest => parse(rest, acc.copy(difficulty1 = v))
|
||||
case "--difficulty2" :: v :: rest => parse(rest, acc.copy(difficulty2 = v))
|
||||
case "--move-ms" :: v :: rest => parse(rest, acc.copy(moveTimeMs = v.toLong))
|
||||
case "--random-plies" :: v :: rest => parse(rest, acc.copy(randomPlies = v.toInt))
|
||||
case "--max-plies" :: v :: rest => parse(rest, acc.copy(maxPlies = v.toInt))
|
||||
case "--seed" :: v :: rest => parse(rest, acc.copy(seed = v.toLong))
|
||||
case Nil => acc
|
||||
case unknown :: rest => println(s"Ignoring unknown arg: $unknown"); parse(rest, acc)
|
||||
|
||||
private def parseDifficulty(name: String): BotDifficulty = name match
|
||||
case "Easy" => BotDifficulty.Easy
|
||||
case "Medium" => BotDifficulty.Medium
|
||||
case "Expert" => BotDifficulty.Expert
|
||||
case _ => BotDifficulty.Hard
|
||||
@@ -3,7 +3,7 @@ package de.nowchess.bot.selfplay
|
||||
import de.nowchess.api.game.GameContext
|
||||
import de.nowchess.api.move.Move
|
||||
import de.nowchess.api.rules.RuleSet
|
||||
import de.nowchess.bot.BotDifficulty
|
||||
import de.nowchess.bot.{Bot, BotDifficulty}
|
||||
import de.nowchess.bot.bots.NNUEBot
|
||||
import de.nowchess.io.fen.FenExporter
|
||||
import de.nowchess.rules.sets.DefaultRules
|
||||
@@ -55,7 +55,7 @@ object SelfPlayMain:
|
||||
|
||||
private def playGame(
|
||||
rules: RuleSet,
|
||||
bot: GameContext => Option[Move],
|
||||
bot: Bot,
|
||||
rng: Random,
|
||||
config: Config,
|
||||
seen: mutable.HashSet[String],
|
||||
|
||||
+20
-6
@@ -2,7 +2,7 @@ package de.nowchess.bot.service
|
||||
|
||||
import com.fasterxml.jackson.databind.{JsonNode, ObjectMapper}
|
||||
import de.nowchess.api.move.{Move, MoveType, PromotionPiece}
|
||||
import de.nowchess.bot.{Bot, BotController}
|
||||
import de.nowchess.bot.{Bot, BotController, TimeControl}
|
||||
import de.nowchess.bot.client.AccountServiceClient
|
||||
import de.nowchess.bot.config.RedisConfig
|
||||
import de.nowchess.io.fen.FenParser
|
||||
@@ -42,6 +42,8 @@ class TournamentBotGamePlayer:
|
||||
|
||||
private val hardestDifficulty = "expert"
|
||||
private val autoJoinIntervalMs = 15000L
|
||||
// Detect the opponent's move fast: every poll spent waiting runs our clock without us thinking.
|
||||
private val pollIntervalMs = 150L
|
||||
|
||||
private val gameTerminalStatuses =
|
||||
Set("checkmate", "stalemate", "draw", "resigned", "timeout", "aborted", "finished")
|
||||
@@ -426,16 +428,28 @@ class TournamentBotGamePlayer:
|
||||
val fen = node.path("fen").asText()
|
||||
if turn == myColor && status == "ongoing" && fen.nonEmpty && fen != lastFen then
|
||||
lastFen = fen
|
||||
log.infof("Our turn in game %s — computing move (fen=%s)", gameId, fen)
|
||||
computeUci(cfg, fen) match
|
||||
val time = readTimeControl(node, myColor)
|
||||
log.infof("Our turn in game %s — computing move (fen=%s, budget=%dms)", gameId, fen, time.budgetMs)
|
||||
computeUci(cfg, fen, time) match
|
||||
case None => log.warnf("No move found for game %s (fen=%s)", gameId, fen)
|
||||
case Some(uci) => submitMove(cfg, gameId, uci)
|
||||
sleep(1000)
|
||||
sleep(pollIntervalMs)
|
||||
|
||||
private def computeUci(cfg: TournamentBotConfig, fen: String): Option[String] =
|
||||
// Server clock is reported in seconds; convert to a millisecond TimeControl so the engine can
|
||||
// size its move budget against the real clock instead of a fixed guess.
|
||||
private def readTimeControl(node: JsonNode, myColor: String): TimeControl =
|
||||
val clock = node.path("clock")
|
||||
if clock.isMissingNode || clock.isNull then TimeControl.Unlimited
|
||||
else
|
||||
val field = if myColor == "white" then "whiteTime" else "blackTime"
|
||||
val remainingMs = (clock.path(field).asDouble(0.0) * 1000.0).toLong
|
||||
val incrementMs = (clock.path("increment").asDouble(0.0) * 1000.0).toLong
|
||||
TimeControl(remainingMs, incrementMs)
|
||||
|
||||
private def computeUci(cfg: TournamentBotConfig, fen: String, time: TimeControl): Option[String] =
|
||||
FenParser.parseFen(fen) match
|
||||
case Left(err) => log.warnf("FEN parse failed: %s (%s)", fen, err.toString); None
|
||||
case Right(context) => engine(cfg).apply(context).map(toUci)
|
||||
case Right(context) => engine(cfg).move(context, time).map(toUci)
|
||||
|
||||
private def submitMove(cfg: TournamentBotConfig, gameId: String, uci: String): Unit =
|
||||
Try {
|
||||
|
||||
@@ -11,8 +11,8 @@ class MopUpTest extends AnyFunSuite with Matchers:
|
||||
private def ctx(turn: Color, pieces: (Square, Piece)*): GameContext =
|
||||
GameContext.initial.withBoard(Board(pieces.toMap)).withTurn(turn)
|
||||
|
||||
private val wk = Square(File.E, Rank.R1) -> Piece.WhiteKing
|
||||
private val wq = Square(File.D, Rank.R1) -> Piece.WhiteQueen
|
||||
private val wk = Square(File.E, Rank.R1) -> Piece.WhiteKing
|
||||
private val wq = Square(File.D, Rank.R1) -> Piece.WhiteQueen
|
||||
private val bkCorner = Square(File.H, Rank.R8) -> Piece.BlackKing
|
||||
private val bkCenter = Square(File.D, Rank.R4) -> Piece.BlackKing
|
||||
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
package de.nowchess.bot
|
||||
|
||||
import de.nowchess.api.game.GameContext
|
||||
import de.nowchess.bot.bots.classic.EvaluationClassic
|
||||
import de.nowchess.bot.logic.{ParallelSearch, TranspositionTable}
|
||||
import de.nowchess.rules.sets.DefaultRules
|
||||
import org.scalatest.funsuite.AnyFunSuite
|
||||
import org.scalatest.matchers.should.Matchers
|
||||
|
||||
class ParallelSearchTest extends AnyFunSuite with Matchers:
|
||||
|
||||
private def search(threads: Int): ParallelSearch =
|
||||
ParallelSearch(DefaultRules, TranspositionTable(), () => EvaluationClassic, threads)
|
||||
|
||||
test("single-threaded coordinator returns a legal move on the initial position"):
|
||||
val move = search(1).bestMoveWithTime(GameContext.initial, 200L)
|
||||
move should not be None
|
||||
DefaultRules.allLegalMoves(GameContext.initial) should contain(move.get)
|
||||
|
||||
test("multi-threaded Lazy SMP returns a legal move and does not crash under concurrency"):
|
||||
val parallel = search(4)
|
||||
for _ <- 1 to 5 do
|
||||
val move = parallel.bestMoveWithTime(GameContext.initial, 200L)
|
||||
move should not be None
|
||||
DefaultRules.allLegalMoves(GameContext.initial) should contain(move.get)
|
||||
|
||||
test("numThreads below one is clamped to a single worker"):
|
||||
search(0).bestMoveWithTime(GameContext.initial, 100L) should not be None
|
||||
@@ -1,3 +1,3 @@
|
||||
MAJOR=0
|
||||
MINOR=42
|
||||
MINOR=44
|
||||
PATCH=0
|
||||
|
||||
Reference in New Issue
Block a user