From 642a66b14bb96481269598048080de8c23e44034 Mon Sep 17 00:00:00 2001 From: Lizzy <=> Date: Sun, 24 Mar 2024 21:15:51 -0500 Subject: [PATCH] Actually using cost constants now --- astar.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/astar.py b/astar.py index 27c6bd6..e48ed0a 100644 --- a/astar.py +++ b/astar.py @@ -35,6 +35,9 @@ class Render_Info: class Node: + COST_DIAGONAL = 14 + COST_LATERAL = 10 + PALETTE_MAP = { NodeStates.UNEXPLORED: Colors.GRAY.value, NodeStates.SEEN: Colors.BLUE.value, @@ -81,16 +84,16 @@ class Node: [abs(self.position.x - gposition.x), abs(self.position.y - gposition.y),] ) - self.gcost = 14 * lower + 10 * (higher-lower) + self.gcost = self.COST_DIAGONAL * lower + self.COST_LATERAL * (higher-lower) def calculate_scost(self, previous_node: 'Node'): #calculate scost. If path back to start is smaller, replace self.scost #and self.previous_node with node on shorter path. if self.position.x != previous_node.position.x and self.position.y != previous_node.position.y: - ds = 14 + ds = self.COST_DIAGONAL else: - ds = 10 + ds = self.COST_LATERAL potential_scost = ds + previous_node.scost @@ -125,9 +128,6 @@ class Node: class Board: - COST_DIAGONAL = 14 - COST_LATERAL = 10 - def __init__(self, dimensions: XYPair, wall_density: float, render_info: Render_Info): screen_dimensions = render_info.screen_dimensions padding = render_info.padding