From 1fc89b08dad6e580ad4638d9a8f5dfe29a0c384e Mon Sep 17 00:00:00 2001 From: CoCoSol007 Date: Wed, 14 Feb 2024 01:12:27 +0100 Subject: [PATCH] add "distance_to" fonction --- crates/border-wars/src/hex.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/crates/border-wars/src/hex.rs b/crates/border-wars/src/hex.rs index 4cc18ed..79969ad 100644 --- a/crates/border-wars/src/hex.rs +++ b/crates/border-wars/src/hex.rs @@ -35,8 +35,10 @@ pub struct HexPosition { impl HexPosition { /// Returns the distance between two "HexPosition" pub fn distance_to(&self, other: &HexPosition) -> f32 { - - 1. + ((self.q - other.q).abs() + + (self.r - other.r).abs() + + (self.q + self.r - other.q - other.r).abs()) as f32 + / 2. } /// Returns all positions in a given range