From 648bbf9c61901271bb82723a931ddfefe1fb5525 Mon Sep 17 00:00:00 2001 From: CoCoSol007 Date: Wed, 14 Feb 2024 17:30:14 +0100 Subject: [PATCH] update calcule --- crates/border-wars/src/hex.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/border-wars/src/hex.rs b/crates/border-wars/src/hex.rs index c775ded..0f9aa3a 100644 --- a/crates/border-wars/src/hex.rs +++ b/crates/border-wars/src/hex.rs @@ -47,12 +47,12 @@ impl HexPosition { /// ``` pub fn distance_to(&self, other: &Self) -> T { // Calculate the difference between the q and r coordinates. - let dq = self.q - other.q; - let dr = self.r - other.r; - let dz = self.q + self.r - other.q - other.r; + let dq = (self.q - other.q).abs(); + let dr = (self.r - other.r).abs(); + let ds = dq + dr; // Manhattan distance = (abs(dq) + abs(dr) + abs(ds)) / 2 - (dq.abs() + dr.abs() + dz.abs()) / (T::one() + T::one()) + (dq + dr + ds) / (T::one() + T::one()) } }