c9b21fa047
* Fix getopts version The pinned version does not compile anymore because of mutable aliasing: * https://github.com/rust-lang/getopts/pull/61 * https://github.com/rust-lang/getopts/issues/110 This was achieved by temporarily setting the getopts version to "0.2.21" in Cargo.toml, and running `cargo check`. Note that this also converts the Cargo.lock to a new format. * Fix warning: Instead of deprecated macro try!, use question mark operator * Fix warning: Avoid anonymous parameters * Fix warning: Use dyn on trait objects * Fix warning: Avoid unneeded mutability * Fix warning: Avoid redundant format in panic or assert * Fix lint: Avoid redundant field names in initializers * Fix lint: Avoid redundant clone * Fix lint: Avoid literal cast * Fix lint: Collapse if/else where applicable I left some if/else branches in place, if there was a certain symmetry between the branches. * Fix lint: Avoid needless borrow I left some if/else branches in place, if there was a certain symmetry between the branches. * Fix lint: Use cloned instead of custom closure * Fix lint: Avoid unneeded trait bound * Fix lint: Avoid unneeded trait bound (2) avoid redundant clone * Fix lint: Use &[T] instead of &Vec<T> * Fix lint: Avoid & on each pattern * Fix lint: Avoid manual assign * Fix lint: Use implicit return * Fix lint: Merge if/else branches with same value I left one complicated branch in place. * Fix lint: Use is_empty instead of comparing len against 0 * Fix lint: Use sum instead of fold * Fix lint: Avoid clone on Copy types |
||
---|---|---|
src | ||
.gitignore | ||
Cargo.lock | ||
Cargo.toml | ||
README.md |
Simulations of Hanabi strategies
Hanabi is a cooperative card game of incomplete information. Despite relatively simple rules, the space of Hanabi strategies is quite interesting. This project provides a framework for implementing Hanabi strategies in Rust, and also implements extremely strong strategies.
The best strategy is based on the "information strategy" from this paper. See results (below). It held state-of-the-art results (from March 2016) until December 2019, when researchers at Facebook surpassed it by extending the idea further with explicit search.
Please feel free to contact me about Hanabi strategies, or this framework.
Setup
Install rust (rustc and cargo), and clone this git repo.
Then, in the repo root, run cargo run -- -h
to see usage details.
For example, to simulate a 5 player game using the cheating strategy, for seeds 0-99:
cargo run -- -n 100 -s 0 -p 5 -g cheat
Or, if the simulation is slow, build with --release
and use more threads:
time cargo run --release -- -n 10000 -o 1000 -s 0 -t 4 -p 5 -g info
Or, to see a transcript of the game with seed 222:
cargo run -- -s 222 -p 5 -g info -l debug | less
Strategies
To write a strategy, you simply implement a few traits.
The framework is designed to take advantage of Rust's ownership system
so that you can't cheat, without using stuff like Cell
or Arc
or Mutex
.
Generally, your strategy will be passed something of type &BorrowedGameView
.
This game view contains many useful helper functions (see here).
If you want to mutate a view, you'll want to do something like
let mut self.view = OwnedGameView::clone_from(borrowed_view);
.
An OwnedGameView will have the same API as a borrowed one.
Some examples:
- Basic dummy examples
- A cheating strategy, using
Rc<RefCell<_>>
- The information strategy!
Results (auto-generated)
To reproduce:
time cargo run --release -- --results-table
To update this file:
time cargo run --release -- --write-results-table
On the first 20000 seeds, we have these scores and win rates (average ± standard error):
2p | 3p | 4p | 5p | |
---|---|---|---|---|
cheat | 24.8594 ± 0.0036 | 24.9785 ± 0.0012 | 24.9720 ± 0.0014 | 24.9557 ± 0.0018 |
90.59 ± 0.21 % | 98.17 ± 0.09 % | 97.76 ± 0.10 % | 96.42 ± 0.13 % | |
info | 22.5194 ± 0.0125 | 24.7942 ± 0.0039 | 24.9354 ± 0.0022 | 24.9220 ± 0.0024 |
12.58 ± 0.23 % | 84.46 ± 0.26 % | 95.03 ± 0.15 % | 94.01 ± 0.17 % |
Other work
Most similar projects I am aware of:
- https://github.com/rjtobin/HanSim (written for the paper mentioned above which introduces the information strategy)
- https://github.com/Quuxplusone/Hanabi
Some researchers are trying to solve Hanabi using machine learning techniques:
- Initial paper from DeepMind and Google Brain researchers. See this Wall Street Journal coverage
- This paper from Facebook, code at https://github.com/facebookresearch/Hanabi_SPARTA which includes their machine-learned agent