@@ -19,7 +19,7 @@ pub fn task1() {
|
||||
println!("Final full round was {}", round);
|
||||
println!(
|
||||
"Result: {}",
|
||||
game.units.iter().map(|it| it.health).sum::<i32>() * round as i32
|
||||
game.units.iter().map(|it| it.health).sum::<i32>() * round
|
||||
);
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ pub fn task2() {
|
||||
}
|
||||
println!(
|
||||
"Result: {}",
|
||||
game.units.iter().map(|it| it.health).sum::<i32>() * round as i32
|
||||
game.units.iter().map(|it| it.health).sum::<i32>() * round
|
||||
);
|
||||
}
|
||||
println!("Searching stopped with lowest win {:?}", lowest_win); // 7169 too low
|
||||
@@ -158,7 +158,7 @@ impl Game {
|
||||
from: Position,
|
||||
target_type: WarriorType,
|
||||
) -> Option<Position> {
|
||||
let mut map = Map::from_game(&self, from);
|
||||
let mut map = Map::from_game(self, from);
|
||||
|
||||
for unit in self.units.iter() {
|
||||
if unit.warrior_type == target_type {
|
||||
@@ -199,13 +199,8 @@ impl Game {
|
||||
// } else {
|
||||
// None
|
||||
// }
|
||||
let map = Map::from_game(&self, from);
|
||||
if let Some(path) = map.shortest_path(from, to) {
|
||||
// println!("{:?}", path);
|
||||
Some(*path.get(1).unwrap_or(&from))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
let map = Map::from_game(self, from);
|
||||
map.shortest_path(from, to).map(|path| *path.get(1).unwrap_or(&from))
|
||||
}
|
||||
|
||||
/// Returns true if a full round was played, false if the round aborted because all
|
||||
@@ -284,7 +279,7 @@ impl Game {
|
||||
}
|
||||
curr += 1;
|
||||
}
|
||||
return true;
|
||||
true
|
||||
}
|
||||
|
||||
fn from_input(input: &Vec<&str>, goblin_attack: i32, elve_attack: i32) -> Self {
|
||||
@@ -354,7 +349,7 @@ impl Display for Game {
|
||||
}
|
||||
}
|
||||
f.write_str(&line)?;
|
||||
f.write_str(&"\n")?;
|
||||
f.write_str("\n")?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
@@ -387,7 +382,7 @@ impl Display for Map {
|
||||
});
|
||||
}
|
||||
f.write_str(&line)?;
|
||||
f.write_str(&"\n")?;
|
||||
f.write_str("\n")?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
@@ -411,7 +406,7 @@ impl Map {
|
||||
}
|
||||
fields[clear.0][clear.1] = MapTile::Empty;
|
||||
Map {
|
||||
fields: fields,
|
||||
fields,
|
||||
width: game.width,
|
||||
height: game.height,
|
||||
}
|
||||
@@ -487,10 +482,6 @@ impl Map {
|
||||
}
|
||||
|
||||
candidates.sort_unstable();
|
||||
if let Some(x) = candidates.first() {
|
||||
Some(*x)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
candidates.first().copied()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user