cache
This commit is contained in:
27
src/azul.rs
27
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<Option<Tile>> for Tile {
|
||||
fn from(option: Option<Tile>) -> Tile {
|
||||
match option {
|
||||
Option::None => Tile::None,
|
||||
Some(tile) => tile
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
pub struct TileIter {
|
||||
current: Tile
|
||||
}
|
||||
@@ -207,7 +218,7 @@ impl From<tinyvec::ArrayVec<[Tile; 128]>> 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(())
|
||||
|
||||
10
src/main.rs
10
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;
|
||||
|
||||
Reference in New Issue
Block a user