diff options
-rw-r--r-- | README.md | 2 | ||||
-rw-r--r-- | wwb/Cargo.toml | 8 | ||||
-rw-r--r-- | wwb/src/main.rs | 32 |
3 files changed, 24 insertions, 18 deletions
@@ -28,7 +28,7 @@ A completed simulation of WWB has never been done either, the longest known one ### My current record -Using this program, a computer managed to go at least 100 trillion turns overnight with a high score of 17. The game runs about 150-200 million turns a second* on my AMD Ryzen 9 5900X running Arch Linux on WSL. Running it on Windows on the same machine was about the same. +Using this program, a computer managed to go at least 100 trillion turns over several days with a high score of 17. The game runs about 150-200 million turns a second* on my AMD Ryzen 9 5900X running Arch Linux on WSL. Running it on Windows on the same machine was about the same. \* *This program relies heavily on single-threaded CPU performance, and performance will depend on your CPU. A 2011 Mac Mini only runs about 25 million turns a second, for example; a Raspberry Pi 4 runs about 19 million turns a second.* diff --git a/wwb/Cargo.toml b/wwb/Cargo.toml index dc17870..944e24e 100644 --- a/wwb/Cargo.toml +++ b/wwb/Cargo.toml @@ -5,9 +5,9 @@ edition = "2021" [dependencies] bincode = "=2.0.1" -chrono = "0.4.39" -ctrlc = "3.4.5" -env_logger = "0.11.6" +chrono = "0.4.41" +ctrlc = "3.4.6" +env_logger = "0.11.8" fastrand = "2.3.0" locusts = "0.0.0" -log = "0.4.25" +log = "0.4.27" diff --git a/wwb/src/main.rs b/wwb/src/main.rs index 62a7f24..e421f96 100644 --- a/wwb/src/main.rs +++ b/wwb/src/main.rs @@ -42,6 +42,20 @@ fn save_game(game: &Game, path: &str) { fs::write(path, serialized_game).unwrap(); } +/// This unholy abomination is used to turn a number like 10000 to "10,000". +/// Thank you, random person on StackOverflow. +fn number_to_pretty_string(number: u128) -> String { + number + .to_string() + .as_bytes() + .rchunks(3) + .rev() + .map(std::str::from_utf8) + .collect::<Result<Vec<&str>, _>>() + .unwrap() + .join(",") +} + fn main() { introduce_locusts(); @@ -106,7 +120,7 @@ fn game_loop(game: &Arc<Mutex<Game>>, path: &str) { "Player {} rolled a {} on turn {} from space {}", current_player_number, roll, - game.turn_count, + number_to_pretty_string(game.turn_count), current_space ); @@ -119,7 +133,7 @@ fn game_loop(game: &Arc<Mutex<Game>>, path: &str) { log::error!( "Player {} has reached the Finish space and won on turn {}!", current_player_number, - game.turn_count + number_to_pretty_string(game.turn_count) ); break; } @@ -129,15 +143,7 @@ fn game_loop(game: &Arc<Mutex<Game>>, path: &str) { "Player {} has a new high score of {} on turn {}", current_player_number, current_space, - game.turn_count - .to_string() - .as_bytes() - .rchunks(3) - .rev() - .map(std::str::from_utf8) - .collect::<Result<Vec<&str>, _>>() - .unwrap() - .join(",") + number_to_pretty_string(game.turn_count) ); game.players[current_player_number].high_score = current_space; save_game(&game, path); @@ -160,7 +166,7 @@ fn game_loop(game: &Arc<Mutex<Game>>, path: &str) { log::debug!( "Player {} rolled a 5 again on turn {} gets to stay on space {}", current_player_number, - game.turn_count, + number_to_pretty_string(game.turn_count), current_space ); } else { @@ -177,7 +183,7 @@ fn game_loop(game: &Arc<Mutex<Game>>, path: &str) { log::debug!( "Player {} ends turn {} on space {}", current_player_number, - game.turn_count, + number_to_pretty_string(game.turn_count), current_space ); } |