Actually using cost constants now
This commit is contained in:
12
astar.py
12
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
|
||||
|
||||
Reference in New Issue
Block a user