This commit is contained in:
Daniel Olsen 2021-05-16 00:23:45 +02:00
parent f6822b377d
commit 8225206ec5
4 changed files with 47 additions and 9 deletions

18
Cargo.lock generated
View File

@ -1,5 +1,16 @@
# This file is automatically @generated by Cargo. # This file is automatically @generated by Cargo.
# It is not intended for manual editing. # 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]] [[package]]
name = "async-mutex" name = "async-mutex"
version = "1.4.0" version = "1.4.0"
@ -256,6 +267,7 @@ checksum = "b16bd47d9e329435e309c58469fe0791c2d0d1ba96ec0954152a5ae2b04387dc"
name = "mercury" name = "mercury"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"ahash",
"cached", "cached",
"coz", "coz",
"modular-bitfield", "modular-bitfield",
@ -419,6 +431,12 @@ version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564" checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564"
[[package]]
name = "version_check"
version = "0.9.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5fecdca9a5291cc2b8dcf7dc02453fee791a280f3743cb0905f8822ae463b3fe"
[[package]] [[package]]
name = "wasi" name = "wasi"
version = "0.9.0+wasi-snapshot-preview1" version = "0.9.0+wasi-snapshot-preview1"

View File

@ -12,6 +12,7 @@ coz = "0.1"
tinyvec = "1.1.0" tinyvec = "1.1.0"
cached = "0.23.0" cached = "0.23.0"
ahash = "0.7.2"
modular-bitfield = "0.11.2" modular-bitfield = "0.11.2"

View File

@ -1,4 +1,4 @@
use std::ops::{Deref, DerefMut}; use std::{hash::Hash, ops::{Deref, DerefMut}};
use rand::prelude::*; use rand::prelude::*;
use rand::distributions::WeightedIndex; use rand::distributions::WeightedIndex;
//use smallvec::{SmallVec, smallvec}; //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 { pub enum Tile {
// None,
Start, Start,
Blue, Blue,
Yellow, Yellow,
@ -35,6 +36,7 @@ pub enum Tile {
impl Default for Tile { impl Default for Tile {
fn default() -> Self { fn default() -> Self {
// Tile::None
Tile::Blue 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 { pub struct TileIter {
current: Tile 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]>); struct Factory (tinyvec::ArrayVec<[Tile; 4]>);
impl Clone for Factory { impl Clone for Factory {
//#[no_alloc] //#[no_alloc]
@ -229,7 +240,6 @@ impl DerefMut for Factory {
} }
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
struct Market (tinyvec::ArrayVec<[Tile; 28]>); struct Market (tinyvec::ArrayVec<[Tile; 28]>);
impl Default for Market { impl Default for Market {
@ -418,7 +428,9 @@ impl Game {
factory.push(tile); factory.push(tile);
} }
} }
factory.sort_unstable();
}; };
self.factories.sort_unstable();
Ok(()) Ok(())
} }
fn score(&mut self) -> Result<(), &'static str> { fn score(&mut self) -> Result<(), &'static str> {
@ -579,6 +591,13 @@ impl Game {
self.player = (self.player + 1) % self.boards.len(); 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.player = (self.player + 1) % self.boards.len() as u8;
self.turn += 1; self.turn += 1;
Ok(()) Ok(())

View File

@ -27,11 +27,11 @@ fn main() -> Result<(), &'static str> {
game.fill(StdRng::from_rng(&mut rng).expect("rng error"))?; game.fill(StdRng::from_rng(&mut rng).expect("rng error"))?;
//println!("{:#?}", game); //println!("{:#?}", game);
game.do_move(GameMove(3, Tile::Red, 3))?; game.do_move(GameMove(2, Tile::Red, 3))?;
game.do_move(GameMove(1, Tile::Yellow, 2))?; game.do_move(GameMove(5, Tile::Yellow, 2))?;
game.do_move(GameMove(4, Tile::Blue, 2))?; game.do_move(GameMove(3, Tile::Blue, 2))?;
game.do_move(GameMove(0, Tile::Black, 4))?; //game.do_move(GameMove(0, Tile::Black, 4))?;
//game.do_move(GameMove(5, Tile::Black, 1))?; //game.do_move(GameMove(5, Tile::Black, 1))?;
//game.do_move(GameMove(0, Tile::Blue, 3))?; //game.do_move(GameMove(0, Tile::Blue, 3))?;
@ -95,7 +95,7 @@ fn calculate_options() -> Result<(), &'static str> {
Ok(()) 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 { fn count_options(_game: Game, depth: u8, treshold: u8) -> u128 {
let mut sum = 0; let mut sum = 0;
let mut all_failed = true; let mut all_failed = true;