update cost and evaluation function
This commit is contained in:
parent
7098fa397e
commit
799e8df4d3
@ -57,14 +57,16 @@ class AStar(Graphsearch):
|
||||
break
|
||||
|
||||
@staticmethod
|
||||
def g(board: Board, node: Node) -> int:
|
||||
def g(board: Board, node: Node) -> tuple[int,int]:
|
||||
"""cost function"""
|
||||
result = 0
|
||||
i = 0
|
||||
while node.get_node() is not None:
|
||||
field = board.get_field(node.get_x(), node.get_y())
|
||||
result += field.get_value()
|
||||
node = node.get_node()
|
||||
return result
|
||||
i += 1
|
||||
return result, i
|
||||
|
||||
@staticmethod
|
||||
def h(node: Node) -> int:
|
||||
@ -75,7 +77,8 @@ class AStar(Graphsearch):
|
||||
@staticmethod
|
||||
def f(board: Board, node: Node) -> int:
|
||||
"""evaluation function"""
|
||||
return AStar.g(board, node) + AStar.h(node) + VALUE_OF_MOVEMENT
|
||||
cost_value, amount_of_moves = AStar.g(board, node)
|
||||
return cost_value + AStar.h(node) + amount_of_moves * VALUE_OF_MOVEMENT
|
||||
|
||||
@staticmethod
|
||||
def search(fringe: PriorityQueue, explored: Queue, istate: Node,
|
||||
|
Loading…
Reference in New Issue
Block a user