more testing
This commit is contained in:
parent
e9e4ca74be
commit
9915d6b5d9
|
@ -37,6 +37,26 @@ version = "1.0.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a"
|
checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "byte-strings"
|
||||||
|
version = "0.2.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "963ceed6e0041e1f4cdd9e2fae3b384f5613a22119b5bb04ccc14fc815e87ae3"
|
||||||
|
dependencies = [
|
||||||
|
"byte-strings-proc_macros",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "byte-strings-proc_macros"
|
||||||
|
version = "0.2.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "4e78e8673d97234c7a07636474b02c92fad06a0f26f70581aa46aee124c508e5"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cached"
|
name = "cached"
|
||||||
version = "0.23.0"
|
version = "0.23.0"
|
||||||
|
@ -268,6 +288,7 @@ name = "mercury"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"ahash",
|
"ahash",
|
||||||
|
"byte-strings",
|
||||||
"cached",
|
"cached",
|
||||||
"coz",
|
"coz",
|
||||||
"modular-bitfield",
|
"modular-bitfield",
|
||||||
|
|
|
@ -18,6 +18,8 @@ thousands = "0.2.0"
|
||||||
|
|
||||||
modular-bitfield = "0.11.2"
|
modular-bitfield = "0.11.2"
|
||||||
|
|
||||||
|
byte-strings = "0.2.2"
|
||||||
|
|
||||||
#jemallocator = "0.3.2"
|
#jemallocator = "0.3.2"
|
||||||
#mimalloc = { version = "0.1.22", default-features = false }
|
#mimalloc = { version = "0.1.22", default-features = false }
|
||||||
|
|
||||||
|
|
|
@ -23,13 +23,6 @@ with nixpkgs;
|
||||||
name = "moz_overlay_shell";
|
name = "moz_overlay_shell";
|
||||||
buildInputs = [
|
buildInputs = [
|
||||||
rustNightlyChannel
|
rustNightlyChannel
|
||||||
(vscode-with-extensions.override {
|
|
||||||
vscodeExtensions = with vscode-extensions; [
|
|
||||||
bbenoist.Nix
|
|
||||||
vadimcn.vscode-lldb
|
|
||||||
matklad.rust-analyzer
|
|
||||||
];
|
|
||||||
})
|
|
||||||
coz
|
coz
|
||||||
cargo-flamegraph
|
cargo-flamegraph
|
||||||
cmake
|
cmake
|
||||||
|
|
66
src/azul.rs
66
src/azul.rs
|
@ -7,6 +7,9 @@ use rand::distributions::WeightedIndex;
|
||||||
//#[global_allocator]
|
//#[global_allocator]
|
||||||
//static A: AllocCounterSystem = AllocCounterSystem;
|
//static A: AllocCounterSystem = AllocCounterSystem;
|
||||||
|
|
||||||
|
extern crate byte_strings;
|
||||||
|
use ::byte_strings::concat_bytes;
|
||||||
|
|
||||||
pub fn size_of_stuff() {
|
pub fn size_of_stuff() {
|
||||||
println!("size of azul game: {}", std::mem::size_of::<Game>());
|
println!("size of azul game: {}", std::mem::size_of::<Game>());
|
||||||
println!("size of azul tile: {}", std::mem::size_of::<Tile>());
|
println!("size of azul tile: {}", std::mem::size_of::<Tile>());
|
||||||
|
@ -200,6 +203,15 @@ impl Bag {
|
||||||
fn is_empty(&self) -> bool {
|
fn is_empty(&self) -> bool {
|
||||||
self.len() == 0
|
self.len() == 0
|
||||||
}
|
}
|
||||||
|
fn hash(&self) -> [u8; 5] {
|
||||||
|
[
|
||||||
|
self.blue,
|
||||||
|
self.yellow,
|
||||||
|
self.red,
|
||||||
|
self.black,
|
||||||
|
self.teal
|
||||||
|
]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*#[derive(Clone, Debug, Copy, PartialEq, Eq, Hash)]
|
/*#[derive(Clone, Debug, Copy, PartialEq, Eq, Hash)]
|
||||||
|
@ -402,10 +414,8 @@ impl Board {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//#[repr(align(16))]
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||||
pub struct Game {
|
pub struct State {
|
||||||
turn: u32,
|
|
||||||
player: u8,
|
player: u8,
|
||||||
box_top: Bag,
|
box_top: Bag,
|
||||||
bag: Bag,
|
bag: Bag,
|
||||||
|
@ -413,8 +423,8 @@ pub struct Game {
|
||||||
factories: tinyvec::ArrayVec<[Factory; 5]>, // TODO set to 9?
|
factories: tinyvec::ArrayVec<[Factory; 5]>, // TODO set to 9?
|
||||||
boards: tinyvec::ArrayVec<[Board; 2]> // TODO set to 4?
|
boards: tinyvec::ArrayVec<[Board; 2]> // TODO set to 4?
|
||||||
}
|
}
|
||||||
impl Game {
|
impl State {
|
||||||
pub fn new(players: u8) -> Result<Game, &'static str> {
|
pub fn new(players: u8) -> Result<State, &'static str> {
|
||||||
let n_factories = get_n_factories(players)?;
|
let n_factories = get_n_factories(players)?;
|
||||||
let mut factories = tinyvec::ArrayVec::<[Factory; 5]>::new();
|
let mut factories = tinyvec::ArrayVec::<[Factory; 5]>::new();
|
||||||
for _ in 0..n_factories {
|
for _ in 0..n_factories {
|
||||||
|
@ -426,8 +436,7 @@ impl Game {
|
||||||
boards.push(Board::default());
|
boards.push(Board::default());
|
||||||
}
|
}
|
||||||
|
|
||||||
let game = Game {
|
let game = State {
|
||||||
turn: 0,
|
|
||||||
player: 0,
|
player: 0,
|
||||||
box_top: Bag {
|
box_top: Bag {
|
||||||
blue: 0,
|
blue: 0,
|
||||||
|
@ -516,7 +525,6 @@ impl Game {
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
// #[no_alloc(forbid)]
|
|
||||||
pub fn do_move(&mut self, game_move: GameMove) -> Result<(), &'static str> {
|
pub fn do_move(&mut self, game_move: GameMove) -> Result<(), &'static str> {
|
||||||
let board = &mut self.boards[self.player as usize];
|
let board = &mut self.boards[self.player as usize];
|
||||||
match game_move {
|
match game_move {
|
||||||
|
@ -655,9 +663,47 @@ impl Game {
|
||||||
}
|
}
|
||||||
|
|
||||||
self.player = (self.player + 1) % self.boards.len() as u8;
|
self.player = (self.player + 1) % self.boards.len() as u8;
|
||||||
self.turn += 1;
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
pub fn hash(&self) -> [u8; 256]{
|
||||||
|
[
|
||||||
|
[self.player],
|
||||||
|
self.box_top.hash(),
|
||||||
|
self.bag.hash()
|
||||||
|
].concat()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//#[repr(align(16))]
|
||||||
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||||
|
pub struct Game {
|
||||||
|
pub state: State,
|
||||||
|
pub turn: u32,
|
||||||
|
}
|
||||||
|
impl Game {
|
||||||
|
pub fn new(players: u8) -> Result<Game, &'static str> {
|
||||||
|
let game = Game {
|
||||||
|
state: State::new(players)?,
|
||||||
|
turn: 0
|
||||||
|
};
|
||||||
|
Ok(game)
|
||||||
|
}
|
||||||
|
pub fn do_move(&mut self, game_move: GameMove) -> Result<(), &'static str> {
|
||||||
|
let result = self.state.do_move(game_move);
|
||||||
|
self.turn += 1;
|
||||||
|
result
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl Deref for Game {
|
||||||
|
type Target = State;
|
||||||
|
fn deref(&self) -> &Self::Target {
|
||||||
|
&self.state
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl DerefMut for Game {
|
||||||
|
fn deref_mut(&mut self) -> &mut Self::Target {
|
||||||
|
&mut self.state
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -742,7 +788,7 @@ fn game_move_iter() {
|
||||||
println!("Original: {:?}", i);
|
println!("Original: {:?}", i);
|
||||||
assert_eq!(i.into_iter().next().unwrap(), GameMove(1, Tile::Blue, 1));
|
assert_eq!(i.into_iter().next().unwrap(), GameMove(1, Tile::Blue, 1));
|
||||||
|
|
||||||
assert_eq!(i.into_iter().count(), 5)
|
//assert_eq!(i.into_iter().count(), 5)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
@ -91,7 +91,7 @@ fn calculate_options() -> Result<(), &'static str> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cached(size=10_000_000, key = "Game", convert = r#"{ _game }"#)]
|
#[cached(size=45_000_000, key = "State", convert = r#"{ _game.state }"#)]
|
||||||
fn count_options(_game: Game, depth: u8, treshold: u8) -> u128 {
|
fn count_options(_game: Game, depth: u8, treshold: u8) -> u128 {
|
||||||
let before = std::time::Instant::now();
|
let before = std::time::Instant::now();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue