-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.rs
45 lines (42 loc) · 1.62 KB
/
main.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/// Runs all the known seeds to get the best score for each.
use std::env;
use std::io::Write;
use std::time::{Instant};
use nostradamus::game_message::{default_game_settings};
use nostradamus::game_random::{GameRandom, OBSERVED_SEEDS};
use nostradamus::planner::{Planner};
use nostradamus::seedrandom::SeedRandom;
fn main() {
let first_id = 0;
let (constants, cannon) = default_game_settings();
let mut scores = Vec::new();
let mut seeds: Vec<Vec<u8>> = Vec::new();
if env::args().len() == 2 {
seeds.push(env::args().nth(1).unwrap().into_bytes());
} else {
seeds.extend(
OBSERVED_SEEDS.iter().map(|&s| s.iter().cloned().collect::<Vec<u8>>())
.collect::<Vec<Vec<u8>>>());
}
let longest_seed = seeds.iter().map(|s| s.len()).max().unwrap();
for seed in seeds {
print!("Seed {:0length$} = ",
String::from_utf8(seed.iter().cloned().collect()).unwrap(),
length=longest_seed);
std::io::stdout().flush().unwrap();
let start = Instant::now();
let random = GameRandom::new(SeedRandom::from_seed(&seed));
let mut planner = Planner::new(first_id, &cannon, &constants, random);
while !planner.is_done() {
if planner.game_state.tick % 50 == 0 {
println!("Tick: {}", planner.game_state.tick);
}
planner.next_action();
}
let score = planner.game_state.score;
let duration = start.elapsed();
println!("{} (took {:?})", score, duration);
scores.push(score);
}
println!("Max score: {}", scores.iter().max().unwrap());
}