From 8225206ec52fbd8123c95cbcb2f389fddd4715ea Mon Sep 17 00:00:00 2001 From: Daniel Olsen Date: Sun, 16 May 2021 00:23:45 +0200 Subject: [PATCH] cache --- Cargo.lock | 18 ++++++++++++++++++ Cargo.toml | 1 + src/azul.rs | 27 +++++++++++++++++++++++---- src/main.rs | 10 +++++----- 4 files changed, 47 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 84e83e6..4e1b65f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,5 +1,16 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. +[[package]] +name = "ahash" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f200cbb1e856866d9eade941cf3aa0c5d7dd36f74311c4273b494f4ef036957" +dependencies = [ + "getrandom", + "once_cell", + "version_check", +] + [[package]] name = "async-mutex" version = "1.4.0" @@ -256,6 +267,7 @@ checksum = "b16bd47d9e329435e309c58469fe0791c2d0d1ba96ec0954152a5ae2b04387dc" name = "mercury" version = "0.1.0" dependencies = [ + "ahash", "cached", "coz", "modular-bitfield", @@ -419,6 +431,12 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564" +[[package]] +name = "version_check" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5fecdca9a5291cc2b8dcf7dc02453fee791a280f3743cb0905f8822ae463b3fe" + [[package]] name = "wasi" version = "0.9.0+wasi-snapshot-preview1" diff --git a/Cargo.toml b/Cargo.toml index 56f5246..3983d83 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,6 +12,7 @@ coz = "0.1" tinyvec = "1.1.0" cached = "0.23.0" +ahash = "0.7.2" modular-bitfield = "0.11.2" diff --git a/src/azul.rs b/src/azul.rs index 97e15bf..5218779 100644 --- a/src/azul.rs +++ b/src/azul.rs @@ -1,4 +1,4 @@ -use std::ops::{Deref, DerefMut}; +use std::{hash::Hash, ops::{Deref, DerefMut}}; use rand::prelude::*; use rand::distributions::WeightedIndex; //use smallvec::{SmallVec, smallvec}; @@ -23,8 +23,9 @@ pub fn size_of_stuff() { } -#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)] pub enum Tile { +// None, Start, Blue, Yellow, @@ -35,6 +36,7 @@ pub enum Tile { impl Default for Tile { fn default() -> Self { +// Tile::None Tile::Blue } } @@ -50,6 +52,15 @@ impl IntoIterator for Tile { } } +/*impl From> for Tile { + fn from(option: Option) -> Tile { + match option { + Option::None => Tile::None, + Some(tile) => tile + } + } +}*/ + pub struct TileIter { current: Tile } @@ -207,7 +218,7 @@ impl From> for Bag { } -#[derive(Default, Debug, Copy, PartialEq, Eq, Hash)] +#[derive(Default, Debug, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)] struct Factory (tinyvec::ArrayVec<[Tile; 4]>); impl Clone for Factory { //#[no_alloc] @@ -229,7 +240,6 @@ impl DerefMut for Factory { } - #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] struct Market (tinyvec::ArrayVec<[Tile; 28]>); impl Default for Market { @@ -418,7 +428,9 @@ impl Game { factory.push(tile); } } + factory.sort_unstable(); }; + self.factories.sort_unstable(); Ok(()) } fn score(&mut self) -> Result<(), &'static str> { @@ -579,6 +591,13 @@ impl Game { self.player = (self.player + 1) % self.boards.len(); } */ + + self.factories.sort_unstable(); + self.market.sort(); + for board in &mut self.boards { + board.floor.sort_unstable(); + } + self.player = (self.player + 1) % self.boards.len() as u8; self.turn += 1; Ok(()) diff --git a/src/main.rs b/src/main.rs index 68dd1e3..955f3c7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -27,11 +27,11 @@ fn main() -> Result<(), &'static str> { game.fill(StdRng::from_rng(&mut rng).expect("rng error"))?; //println!("{:#?}", game); - game.do_move(GameMove(3, Tile::Red, 3))?; - game.do_move(GameMove(1, Tile::Yellow, 2))?; + game.do_move(GameMove(2, Tile::Red, 3))?; + game.do_move(GameMove(5, Tile::Yellow, 2))?; - game.do_move(GameMove(4, Tile::Blue, 2))?; - game.do_move(GameMove(0, Tile::Black, 4))?; + game.do_move(GameMove(3, Tile::Blue, 2))?; + //game.do_move(GameMove(0, Tile::Black, 4))?; //game.do_move(GameMove(5, Tile::Black, 1))?; //game.do_move(GameMove(0, Tile::Blue, 3))?; @@ -95,7 +95,7 @@ fn calculate_options() -> Result<(), &'static str> { Ok(()) } -#[cached(size=15_000_000, key = "Game", convert = r#"{ _game }"#)] +#[cached(size=25_000_000, key = "Game", convert = r#"{ _game }"#)] fn count_options(_game: Game, depth: u8, treshold: u8) -> u128 { let mut sum = 0; let mut all_failed = true;