bug fixes

This commit is contained in:
Daniel Olsen 2021-01-04 11:24:49 +01:00
parent 22af164a95
commit 706e33a12f
3 changed files with 23 additions and 16 deletions

View File

@ -1,4 +0,0 @@
startup time=1609744772805409109
runtime time=10083706
startup time=1609744984945886640
runtime time=10097224

View File

@ -16,7 +16,7 @@ pub enum Tile {
pub struct GameMove (pub usize, pub Tile, pub usize); pub struct GameMove (pub usize, pub Tile, pub usize);
impl Default for GameMove { impl Default for GameMove {
fn default() -> Self { fn default() -> Self {
GameMove(0, Tile::Blue, 0) GameMove(0, Tile::Blue, 1)
} }
} }
@ -348,6 +348,9 @@ impl Game {
} }
else if self.market.contains(&game_move.1) { else if self.market.contains(&game_move.1) {
let target = &mut board.patterns[game_move.2 - 1]; let target = &mut board.patterns[game_move.2 - 1];
if target.first().is_some() && target[0] != game_move.1 {
return Err("That pattern line already contains a different color")
}
let empty = game_move.2 - target.len(); let empty = game_move.2 - target.len();
if empty == 0 { if empty == 0 {
@ -400,6 +403,9 @@ impl Game {
}, },
1..=9 => { 1..=9 => {
let target = &mut board.patterns[game_move.2 - 1]; let target = &mut board.patterns[game_move.2 - 1];
if target.first().is_some() && target[0] != game_move.1 {
return Err("That pattern line already contains a different color")
}
let empty = game_move.2 - target.len(); let empty = game_move.2 - target.len();
if hand.len() <= empty { if hand.len() <= empty {
target.append(&mut hand); target.append(&mut hand);

View File

@ -1,24 +1,31 @@
mod azul; mod azul;
use azul::*; use azul::*;
fn main() -> Result<(), &'static str>{ fn main() -> Result<(), &'static str> {
for _ in 0..10000 {
run()?;
}
Ok(())
}
fn run() -> Result<(), &'static str> {
let mut game = Game::new(2)?; let mut game = Game::new(2)?;
game.fill()?; game.fill()?;
let mut all_err = false; let mut all_err = false;
while !all_err { while !all_err {
println!("{:#?}", game); //println!("{:#?}", game);
all_err = true; all_err = true;
let mut game_move:Option<GameMove> = Some(GameMove::default()); let mut game_move:Option<GameMove> = Some(GameMove::default());
while let Some(mut i) = game_move { while let Some(mut i) = game_move {
match game.do_move(i) { match game.do_move(i) {
Err(e) => { Err(e) => {
println!("{:?}: {}", i, e); //println!("{:?}: {}", i, e);
game_move = i.next(); game_move = i.next();
}, },
Ok(g) => { Ok(g) => {
println!("{:?}", i); //println!("{:?}", i);
game = g; game = g;
all_err = false; all_err = false;
break; break;
@ -26,9 +33,6 @@ fn main() -> Result<(), &'static str>{
} }
} }
} }
let game2 = game.do_move(GameMove(1, Tile::Red, 1))?;
println!("{:#?}", game2);
Ok(()) Ok(())
} }
@ -60,14 +64,15 @@ impl Iterator for GameMove {
}; };
let tile = match _tile { let tile = match _tile {
None => { None => {
pattern += 1; match pattern {
6 => pattern = 0,
0 => return None,
_ => pattern = pattern + 1
};
Tile::Blue Tile::Blue
}, },
Some(x) => x Some(x) => x
}; };
if pattern > 6 {
return None
}
Some(GameMove(factory, tile, pattern)) Some(GameMove(factory, tile, pattern))
} }