Fix critical bug
This commit is contained in:
parent
43c6eb4298
commit
673cbf8e89
36
src/main.rs
36
src/main.rs
@ -62,14 +62,14 @@ fn random_world(rng: &mut SmallRng, tris: &mut [Triangle], angles: &mut [f32], f
|
||||
world.tris.push((0, tri));
|
||||
world.normalize();
|
||||
} else {
|
||||
tri.0.x += 1.0;
|
||||
tri.1.x += 1.0;
|
||||
tri.2.x += 1.0;
|
||||
//tri.0.x += 1.0;
|
||||
//tri.1.x += 1.0;
|
||||
//tri.2.x += 1.0;
|
||||
for &delta in &[
|
||||
/*10.0, 5.0,*/ 1.0, 0.6, 0.32, 0.18, 0.1, 0.06, 0.03, 0.01
|
||||
] {
|
||||
//println!("moving {:?}", tri);
|
||||
//println!("world {:?}", world);
|
||||
//eprintln!("moving {:?}", tri);
|
||||
//eprintln!("world {:?}", world);
|
||||
let initial_state = world.tris[0..idx].iter().any(|(_, x)| x.intersects(&tri));
|
||||
let dx = if initial_state { delta } else { -delta };
|
||||
while world.tris[0..idx].iter().any(|(_, x)| x.intersects(&tri)) == initial_state {
|
||||
@ -108,18 +108,26 @@ fn construct_world(tris: &[Triangle], angles: &[f32], flips: &[bool]) -> World {
|
||||
world.tris.push((0, tri));
|
||||
world.normalize();
|
||||
} else {
|
||||
tri.0.x += 1.0;
|
||||
tri.1.x += 1.0;
|
||||
tri.2.x += 1.0;
|
||||
//tri.0.x += 1.0;
|
||||
//tri.1.x += 1.0;
|
||||
//tri.2.x += 1.0;
|
||||
for &delta in &[
|
||||
/*10.0, 5.0,*/ 1.0, 0.6, 0.32, 0.18, 0.1, 0.06, 0.03, 0.01
|
||||
] {
|
||||
//eprintln!("moving {:?}", tri);
|
||||
//eprintln!("world {:?}", world);
|
||||
let initial_state = world.tris[0..idx].iter().any(|(_, x)| x.intersects(&tri));
|
||||
let dx = if initial_state { delta } else { -delta };
|
||||
while world.tris[0..idx].iter().any(|(_, x)| x.intersects(&tri)) == initial_state {
|
||||
tri.0.x += dx;
|
||||
tri.1.x += dx;
|
||||
tri.2.x += dx;
|
||||
if tri.0.x < -5000.0 {
|
||||
tri.0.x += 5000.0;
|
||||
tri.1.x += 5000.0;
|
||||
tri.2.x += 5000.0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
world.tris.push((0, tri));
|
||||
@ -132,6 +140,14 @@ fn construct_world(tris: &[Triangle], angles: &[f32], flips: &[bool]) -> World {
|
||||
|
||||
fn main() {
|
||||
let mut tris = input::read_input();
|
||||
for tri in &mut tris {
|
||||
tri.1.x -= tri.0.x;
|
||||
tri.2.x -= tri.0.x;
|
||||
tri.0.x = 0.0;
|
||||
tri.1.y -= tri.0.y;
|
||||
tri.2.y -= tri.0.y;
|
||||
tri.0.y = 0.0;
|
||||
}
|
||||
let mut angles = vec![0.0; tris.len()];
|
||||
let mut flips = vec![false; tris.len()];
|
||||
let mut rng = SmallRng::from_entropy();
|
||||
@ -143,7 +159,7 @@ fn main() {
|
||||
let mut random = random_world(&mut rng, &mut tris, &mut angles, &mut flips);
|
||||
loop {
|
||||
save_counter += 1;
|
||||
if save_counter % 100_000 == 0 {
|
||||
if save_counter % 1 == 0 {
|
||||
eprint!("\r[{}]", save_counter);
|
||||
}
|
||||
if random.width < best_width {
|
||||
@ -163,7 +179,7 @@ fn main() {
|
||||
random = random_world(&mut rng, &mut tris, &mut angles, &mut flips);
|
||||
if save_counter - last_improvement > 200_000 {
|
||||
// "restart"
|
||||
best_width += 5.0;
|
||||
best_width += 1000.0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user