Compare commits
3 Commits
37837e76c1
...
6bfa05c292
| Author | SHA1 | Date | |
|---|---|---|---|
| 6bfa05c292 | |||
| da0dfe98c4 | |||
| b840d56725 |
Generated
+9
@@ -132,6 +132,15 @@ dependencies = [
|
||||
"rand",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "klondike-bench"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"card_game",
|
||||
"klondike",
|
||||
"rand",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "klondike-cli"
|
||||
version = "0.1.0"
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
members = [
|
||||
"card_game",
|
||||
"klondike",
|
||||
"klondike-bench",
|
||||
"klondike-cli",
|
||||
]
|
||||
resolver = "3"
|
||||
|
||||
@@ -10,3 +10,6 @@ keywords = ["card", "cards", "solitaire", "klondike"]
|
||||
|
||||
[dependencies]
|
||||
arrayvec = "0.7.6"
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
[package]
|
||||
name = "klondike-bench"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
card_game.workspace = true
|
||||
klondike.workspace = true
|
||||
rand = { version = "0.10.1", default-features = false }
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
@@ -0,0 +1,30 @@
|
||||
use card_game::Game;
|
||||
use klondike::{Klondike, KlondikeConfig, KlondikeStats, Rng};
|
||||
|
||||
fn play_to_win(rng: &mut Rng) -> bool {
|
||||
// create game session
|
||||
let mut game = Klondike::with_rng(rng);
|
||||
let mut stats = KlondikeStats::new();
|
||||
const CONFIG: KlondikeConfig = KlondikeConfig {
|
||||
draw_stock: klondike::DrawStockConfig::DrawOne,
|
||||
};
|
||||
// play game a bit
|
||||
while let Some(instruction) = game.get_auto_move()
|
||||
&& !game.is_win()
|
||||
{
|
||||
game.process_instruction(&mut stats, &CONFIG, instruction);
|
||||
|
||||
// quit after 250 moves
|
||||
if 250 < stats.moves() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
game.is_win()
|
||||
}
|
||||
fn main() {
|
||||
use rand::SeedableRng;
|
||||
let mut rng = Rng::seed_from_u64(0);
|
||||
const GAMES: u32 = 10000;
|
||||
let wins: u32 = (0..GAMES).map(|_| play_to_win(&mut rng) as u32).sum();
|
||||
println!("wins = {wins}/{GAMES} win_rate = {}%", wins * 100 / GAMES);
|
||||
}
|
||||
@@ -7,3 +7,6 @@ edition = "2024"
|
||||
card_game.workspace = true
|
||||
klondike.workspace = true
|
||||
rand = { version = "0.10.1", default-features = false, features = ["thread_rng"] }
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
|
||||
@@ -6,3 +6,6 @@ edition = "2024"
|
||||
[dependencies]
|
||||
card_game.workspace = true
|
||||
rand = { version = "0.10.1", default-features = false, features = ["std_rng"] }
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@ Klondike
|
||||
## Example
|
||||
|
||||
```rust
|
||||
use card_game::{Session, Game};
|
||||
use card_game::Session;
|
||||
use klondike::Klondike;
|
||||
|
||||
// create game session
|
||||
|
||||
Reference in New Issue
Block a user