some more optimization, deheapifying
This commit is contained in:
+36
-9
@@ -2,11 +2,29 @@ mod azul;
|
||||
use azul::*;
|
||||
use rand::prelude::*;
|
||||
|
||||
//#[global_allocator]
|
||||
//static GLOBAL: jemallocator::Jemalloc = jemallocator::Jemalloc;
|
||||
|
||||
//#[global_allocator]
|
||||
//static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;
|
||||
|
||||
|
||||
fn main() -> Result<(), &'static str> {
|
||||
|
||||
let rng = StdRng::seed_from_u64(42);
|
||||
let game = Game::new(2, rng)?;
|
||||
let mut game = Game::new(2, rng)?;
|
||||
game.fill()?;
|
||||
println!("{:#?}", game);
|
||||
println!("{}", count_options(game, 0));
|
||||
|
||||
game.do_move(GameMove(1, Tile::Red, 2))?;
|
||||
game.do_move(GameMove(4, Tile::Red, 2))?;
|
||||
|
||||
game.do_move(GameMove(2, Tile::Red, 1))?;
|
||||
|
||||
println!("{}", count_options(game, 0, 2));
|
||||
|
||||
|
||||
// calculate_options()?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -37,17 +55,21 @@ fn run(rng: StdRng) -> Result<(), &'static str> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn calculate_options() -> Result<(), String> {
|
||||
let game = complicated()?;
|
||||
fn calculate_options() -> Result<(), &'static str> {
|
||||
let mut game = complicated()?;
|
||||
println!("{:#?}", game);
|
||||
|
||||
println!("{}", count_options(game, 0));
|
||||
// We know how many possibilities there are the first round...
|
||||
game.do_move(GameMove(1, Tile::Blue, 0))?;
|
||||
|
||||
let options = count_options(game, 0, 4);
|
||||
println!("{}", options * 20 * 6);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn count_options(game: Game, depth: u8) -> u128 {
|
||||
fn count_options(game: Game, depth: u8, treshold: u8) -> u128 {
|
||||
coz::scope!("count option");
|
||||
let mut sum = 0;
|
||||
let i = GameMove::default();
|
||||
let mut all_failed = true;
|
||||
@@ -56,16 +78,21 @@ fn count_options(game: Game, depth: u8) -> u128 {
|
||||
let mut new_game = game.clone();
|
||||
let r = new_game.do_move(game_move);
|
||||
match r {
|
||||
Ok(_) => sum += {/*println!("{}", depth);*/ all_failed = false; count_options(new_game, depth + 1)},
|
||||
Ok(_) => sum += {/*println!("{}", depth);*/ all_failed = false; coz::progress!("OK"); count_options(new_game, depth + 1, treshold)},
|
||||
Err(_) => continue
|
||||
};
|
||||
};
|
||||
|
||||
if all_failed {
|
||||
//println!("{}: ALL FAILED!", depth);
|
||||
if depth <= treshold {
|
||||
println!("{}: ALL FAILED!", depth);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
if depth <= treshold {
|
||||
println!("{}: sum: {}", depth, sum);
|
||||
}
|
||||
return sum;
|
||||
|
||||
/*game_move.iter_mut().map(|x| {
|
||||
|
||||
Reference in New Issue
Block a user