Compare commits
2 Commits
d8452daddf
...
e545f09bb4
Author | SHA1 | Date | |
---|---|---|---|
e545f09bb4 | |||
6cb0fe1550 |
@ -217,11 +217,16 @@ impl Node {
|
|||||||
board: &mut simulation::Board,
|
board: &mut simulation::Board,
|
||||||
deadline: &Instant,
|
deadline: &Instant,
|
||||||
) -> Result<Option<SnakeToken>, DeadlineError> {
|
) -> Result<Option<SnakeToken>, DeadlineError> {
|
||||||
let winner = if self.statistic.played == 0 {
|
let stop_condition =
|
||||||
|
|board: &simulation::Board| board.alive_snakes() <= 1 || Instant::now() >= *deadline;
|
||||||
|
let winner = if stop_condition(board) {
|
||||||
|
if Instant::now() >= *deadline {
|
||||||
|
return Err(DeadlineError);
|
||||||
|
}
|
||||||
|
board.snakes().next()
|
||||||
|
} else if self.statistic.played == 0 {
|
||||||
// We didn't simulate a game for this node yet. Do that
|
// We didn't simulate a game for this node yet. Do that
|
||||||
board.simulate_until(&mut thread_rng(), |board| {
|
board.simulate_until(&mut thread_rng(), stop_condition);
|
||||||
board.alive_snakes() <= 1 || Instant::now() >= *deadline
|
|
||||||
});
|
|
||||||
if Instant::now() >= *deadline {
|
if Instant::now() >= *deadline {
|
||||||
return Err(DeadlineError);
|
return Err(DeadlineError);
|
||||||
}
|
}
|
||||||
@ -252,9 +257,6 @@ impl Node {
|
|||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
if Instant::now() >= *deadline {
|
|
||||||
return Err(DeadlineError);
|
|
||||||
}
|
|
||||||
board.simulate_actions(&actions, &mut thread_rng());
|
board.simulate_actions(&actions, &mut thread_rng());
|
||||||
let winner = self
|
let winner = self
|
||||||
.childs
|
.childs
|
||||||
|
@ -262,7 +262,6 @@ fn run_local_docker(port: u16) -> Result<Child, DynError> {
|
|||||||
"--env",
|
"--env",
|
||||||
format!("ROCKET_PORT={}", port).as_str(),
|
format!("ROCKET_PORT={}", port).as_str(),
|
||||||
"--network=host",
|
"--network=host",
|
||||||
"-i",
|
|
||||||
"--rm",
|
"--rm",
|
||||||
"local_snake",
|
"local_snake",
|
||||||
])
|
])
|
||||||
@ -293,7 +292,6 @@ fn run_production(port: u16) -> Result<Child, DynError> {
|
|||||||
"--env",
|
"--env",
|
||||||
format!("ROCKET_PORT={}", port).as_str(),
|
format!("ROCKET_PORT={}", port).as_str(),
|
||||||
"--network=host",
|
"--network=host",
|
||||||
"-i",
|
|
||||||
"--rm",
|
"--rm",
|
||||||
"docker.mkaenner.de/snake:latest",
|
"docker.mkaenner.de/snake:latest",
|
||||||
])
|
])
|
||||||
|
Loading…
Reference in New Issue
Block a user