diff --git a/84_Super_Star_Trek/rust/src/model.rs b/84_Super_Star_Trek/rust/src/model.rs index 1bb5ef8e..1e4359ed 100644 --- a/84_Super_Star_Trek/rust/src/model.rs +++ b/84_Super_Star_Trek/rust/src/model.rs @@ -162,9 +162,8 @@ impl Pos { pub fn direction(&self, other: Pos) -> f32 { // this is a replication of the original BASIC code - let dy = other.0 as f32 - self.0 as f32; - let dx = other.1 as f32 - self.1 as f32; - // note i actually use x,y, but the calculation assumes y,x so they're flipped above + let dx = other.0 as f32 - self.0 as f32; + let dy = other.1 as f32 - self.1 as f32; let dx_dominant = dx.abs() > dy.abs(); let frac = if dx_dominant { dy / dx } else { -dx / dy }; @@ -214,15 +213,15 @@ impl Display for Pos { } pub const COURSES : [(f32, f32); 9] = [ - (1., 0.), - (1., -1.), - (0., -1.), - (-1., -1.), - (-1., 0.), - (-1., 1.), (0., 1.), + (-1., 1.), + (-1., 0.), + (-1., -1.), + (0., -1.), + (1., -1.), + (1., 0.), (1., 1.), - (1., 0.), // course 9 is equal to course 1 + (0., 1.), // course 9 is equal to course 1 ]; #[derive(PartialEq)] diff --git a/84_Super_Star_Trek/rust/src/view.rs b/84_Super_Star_Trek/rust/src/view.rs index 7e8aa399..1cc2d202 100644 --- a/84_Super_Star_Trek/rust/src/view.rs +++ b/84_Super_Star_Trek/rust/src/view.rs @@ -226,7 +226,7 @@ const SUB_REGION_NAMES: [&str; 4] = ["I", "II", "III", "IV"]; fn quadrant_name(quadrant: Pos) -> String { format!("{} {}", - REGION_NAMES[((quadrant.1 << 1) + (quadrant.0 >> 2)) as usize], + REGION_NAMES[((quadrant.0 << 1) + (quadrant.1 >> 2)) as usize], SUB_REGION_NAMES[(quadrant.1 % 4) as usize]) } @@ -264,8 +264,8 @@ pub fn short_range_scan(model: &Galaxy) { ]; println!("{:-^33}", ""); - for y in 0..=7 { - for x in 0..=7 { + for x in 0..=7 { + for y in 0..=7 { let pos = Pos(x, y); if &pos == &model.enterprise.sector { print!("<*> ") @@ -278,7 +278,7 @@ pub fn short_range_scan(model: &Galaxy) { } } } - println!("{:>9}{}", "", data[y as usize]) + println!("{:>9}{}", "", data[x as usize]) } println!("{:-^33}", ""); } @@ -419,8 +419,8 @@ pub fn long_range_scan(galaxy: &Galaxy) -> Vec { println!("Long range scan for quadrant {}", galaxy.enterprise.quadrant); println!("{:-^19}", ""); - for y in cy - 1..=cy + 1 { - for x in cx - 1..=cx + 1 { + for x in cx - 1..=cx + 1 { + for y in cy - 1..=cy + 1 { let mut klingons = "*".into(); let mut star_bases = "*".into(); let mut stars = "*".into(); @@ -478,9 +478,9 @@ pub fn galaxy_scanned_map(galaxy: &Galaxy) { "Computer record of galaxy for quadrant {} 1 2 3 4 5 6 7 8 ----- ----- ----- ----- ----- ----- ----- -----", galaxy.enterprise.quadrant); - for y in 0..8 { - print!("{} ", y+1); - for x in 0..8 { + for x in 0..8 { + print!("{} ", x+1); + for y in 0..8 { let pos = Pos(x, y); if galaxy.scanned.contains(&pos) { let quadrant = &galaxy.quadrants[pos.as_index()];