{"id":13692560,"url":"https://github.com/csauve/bookworm","last_synced_at":"2026-01-18T11:02:23.164Z","repository":{"id":73126087,"uuid":"230598561","full_name":"csauve/bookworm","owner":"csauve","description":"A BattleSnake bot for 2020","archived":false,"fork":false,"pushed_at":"2020-03-02T23:00:30.000Z","size":802,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-11-12T18:41:34.343Z","etag":null,"topics":["battlesnake","rust"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/csauve.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2019-12-28T11:05:58.000Z","updated_at":"2021-07-16T22:36:38.000Z","dependencies_parsed_at":"2023-09-19T03:46:57.094Z","dependency_job_id":null,"html_url":"https://github.com/csauve/bookworm","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/csauve%2Fbookworm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/csauve%2Fbookworm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/csauve%2Fbookworm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/csauve%2Fbookworm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/csauve","download_url":"https://codeload.github.com/csauve/bookworm/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252095374,"owners_count":21693908,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["battlesnake","rust"],"created_at":"2024-08-02T17:00:59.449Z","updated_at":"2026-01-18T11:02:23.135Z","avatar_url":"https://github.com/csauve.png","language":"Rust","funding_links":[],"categories":["Battlesnakes"],"sub_categories":[],"readme":"# Bookworm 🐛\n\nBookworm is a [BattleSnake][1] bot written in [Rust][2] for the March 2020 tournament. Combines the strategies of pruned turn tree exploration, minimax, and heuristic scoring. The snake is given a time budget to explore the turn tree; the fewer the snakes, the deeper the exploration.\n\n![](screenshot.png)\n_A server instance playing against itself using the built-in host mode. See `play-host.sh` as an example._\n\n## Building and running\n\nJust run `cargo build --release` to produce a self-contained binary at `target/release/bookworm`. The binary can be invoked with a number of modes and options, which the `-h` flag explains in detail. The available modes are:\n\n* **server:** Runs as a typical snake API server, ready to be play.\n* **host:** Locally hosts a match between given snakes, logging each turn state. Implements 2020 rules.\n* **benchmark:** A series of common operations are timed and logged.\n\n## Development\n\nUnit tests can be run with `cargo test`, though some strategy tests will fail currently. To quickly build and run the bot, use `cargo run \u003cmode\u003e`. Note that the development build is significantly slower at runtime than the release build, so you may need to increase the `--timeout` for host mode and give the server more time budget with `--budget` to achieve similar lookahead depths.\n\n### Todos and improvement ideas:\n* Heuristics and strategy\n  * Implement more unit tests for behaviour\n  * Seed the turn tree exploration with some longer term \"plays\" instead of just single space movements\n  * Allow for chances of death instead of assumed worst case\n  * If death unavoidable, prefer head-to-head\n  * Are there heuristic elements we can skip sometimes?\n* Performance\n  * Can I write some `const fn` to move work to compile time?\n  * Can I use fixed arrays or `vec![0.0; src.len()]` anywhere?\n  * Look for places to use `.copied()` instead of `.cloned()`\n  * Avoid indexing into vecs; use `if let Some(x) = vec.get(i)`\n  * [infallible DS][3] to avoid empty checks\n  * Move hosting to `us-west-1` to be closer to BS host\n* Pathfinding (if used)\n  * JPS\n  * Dynamic heuristic weight\n\n### The \"wat\" list\n\nQuestionable life choices:\n\n* [Turn 114: Feeding rule change?](https://play.battlesnake.com/g/72eee8c6-7b26-4b81-afb0-1afa17f5c5bf/)\n* [Turn 230: Gave enemy opportunity to easily kill us head-to-head](https://play.battlesnake.com/g/04c853c2-0e3e-4013-8bb5-fd66a82ce2d6/)\n* [Turn 383: Gave enemy opportunity to easily trap us](https://play.battlesnake.com/g/c196792b-7a8c-4ccf-b63d-d89da1fdba6b/)\n* [Turn 300: Trapped self... why??](https://play.battlesnake.com/g/880a59ac-3fe9-4204-a37c-6cbf796f5030/)\n* [Turn 36: Giving up too early](https://play.battlesnake.com/g/a1646958-edda-4000-9fde-a926292ba1d0/)\n* [Turn 13: Allow for chance of survival](https://play.battlesnake.com/g/53b159ea-a914-493d-8c73-54680186fafa/)\n* [Turn 21: Prefer going up because less likely blue_bottle will go there](https://play.battlesnake.com/g/eff9c73e-cbb2-4bf9-98a1-89f0e8244bcb/)\n* [Turn 74: Ran into another snake, but should prefer possibility of head-to-head death](https://play.battlesnake.com/g/977be8a8-ca65-48b8-bc8c-37310ab61701/)\n* [Turn 240: Could have trapped enemy but didn't](https://play.battlesnake.com/g/639eb325-932a-463c-9f4c-5aaa96495f7d/)\n* [Turn 122: Ditto above](https://play.battlesnake.com/g/23b1ec46-6c97-407a-b6a7-9aee9b75464d/)\n* [Turn 15: Didn't understand stacked tail rule?](https://play.battlesnake.com/g/93a1babe-2aa6-411f-b67d-e20e4d6d644c/)\n\n## References and resources\n\n* https://github.com/BattlesnakeOfficial/rules/blob/master/standard.go\n* https://github.com/BattlesnakeOfficial/engine/blob/master/rules/tick.go\n* https://github.com/anvaka/ngraph.path\n* https://github.com/riscy/a_star_on_grids\n* https://www.redblobgames.com/pathfinding/grids/algorithms.html\n* [http://likebike.com/posts/How_To_Write_Fast_Rust_Code.html][3]\n\n[1]: https://play.battlesnake.com/\n[2]: https://www.rust-lang.org/\n[3]: http://likebike.com/posts/How_To_Write_Fast_Rust_Code.html\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcsauve%2Fbookworm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcsauve%2Fbookworm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcsauve%2Fbookworm/lists"}