more testing
This commit is contained in:
66
src/azul.rs
66
src/azul.rs
@@ -7,6 +7,9 @@ use rand::distributions::WeightedIndex;
|
||||
//#[global_allocator]
|
||||
//static A: AllocCounterSystem = AllocCounterSystem;
|
||||
|
||||
extern crate byte_strings;
|
||||
use ::byte_strings::concat_bytes;
|
||||
|
||||
pub fn size_of_stuff() {
|
||||
println!("size of azul game: {}", std::mem::size_of::<Game>());
|
||||
println!("size of azul tile: {}", std::mem::size_of::<Tile>());
|
||||
@@ -200,6 +203,15 @@ impl Bag {
|
||||
fn is_empty(&self) -> bool {
|
||||
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)]
|
||||
@@ -402,10 +414,8 @@ impl Board {
|
||||
}
|
||||
}
|
||||
|
||||
//#[repr(align(16))]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
pub struct Game {
|
||||
turn: u32,
|
||||
pub struct State {
|
||||
player: u8,
|
||||
box_top: Bag,
|
||||
bag: Bag,
|
||||
@@ -413,8 +423,8 @@ pub struct Game {
|
||||
factories: tinyvec::ArrayVec<[Factory; 5]>, // TODO set to 9?
|
||||
boards: tinyvec::ArrayVec<[Board; 2]> // TODO set to 4?
|
||||
}
|
||||
impl Game {
|
||||
pub fn new(players: u8) -> Result<Game, &'static str> {
|
||||
impl State {
|
||||
pub fn new(players: u8) -> Result<State, &'static str> {
|
||||
let n_factories = get_n_factories(players)?;
|
||||
let mut factories = tinyvec::ArrayVec::<[Factory; 5]>::new();
|
||||
for _ in 0..n_factories {
|
||||
@@ -426,8 +436,7 @@ impl Game {
|
||||
boards.push(Board::default());
|
||||
}
|
||||
|
||||
let game = Game {
|
||||
turn: 0,
|
||||
let game = State {
|
||||
player: 0,
|
||||
box_top: Bag {
|
||||
blue: 0,
|
||||
@@ -516,7 +525,6 @@ impl Game {
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
// #[no_alloc(forbid)]
|
||||
pub fn do_move(&mut self, game_move: GameMove) -> Result<(), &'static str> {
|
||||
let board = &mut self.boards[self.player as usize];
|
||||
match game_move {
|
||||
@@ -655,9 +663,47 @@ impl Game {
|
||||
}
|
||||
|
||||
self.player = (self.player + 1) % self.boards.len() as u8;
|
||||
self.turn += 1;
|
||||
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);
|
||||
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]
|
||||
|
||||
@@ -91,7 +91,7 @@ fn calculate_options() -> Result<(), &'static str> {
|
||||
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 {
|
||||
let before = std::time::Instant::now();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user