From 673cbf8e895b87042bb91255e277cc57c0c6465e Mon Sep 17 00:00:00 2001 From: Arne Keller Date: Fri, 26 Apr 2019 23:16:04 +0200 Subject: [PATCH] Fix critical bug --- src/main.rs | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/src/main.rs b/src/main.rs index f982b9b..06b4348 100644 --- a/src/main.rs +++ b/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; } } }