From 61fa6d90c51a776e98f28a4b3970bdfb1a3e093b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Cupa=C5=82?= Date: Wed, 28 Apr 2021 08:50:58 +0200 Subject: [PATCH] update evaluation and cost function --- app/a_star.py | 9 +++------ config.py | 5 ++--- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/app/a_star.py b/app/a_star.py index bee1b2d..585047b 100644 --- a/app/a_star.py +++ b/app/a_star.py @@ -57,16 +57,14 @@ class AStar(Graphsearch): break @staticmethod - def g(board: Board, node: Node) -> tuple[int,int]: + def g(board: Board, node: Node) -> 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() - i += 1 - return result, i + return result @staticmethod def h(node: Node) -> int: @@ -77,8 +75,7 @@ class AStar(Graphsearch): @staticmethod def f(board: Board, node: Node) -> int: """evaluation function""" - cost_value, amount_of_moves = AStar.g(board, node) - return cost_value + AStar.h(node) + amount_of_moves * VALUE_OF_MOVEMENT + return AStar.g(board, node) + AStar.h(node) @staticmethod def search(fringe: PriorityQueue, explored: Queue, istate: Node, diff --git a/config.py b/config.py index 820d3c7..3b9c28d 100644 --- a/config.py +++ b/config.py @@ -11,7 +11,7 @@ __all__ = ( 'M_GO_FORWARD', 'M_ROTATE_LEFT', 'M_ROTATE_RIGHT', 'A_SOW', 'A_HARVEST', 'A_HYDRATE', 'A_FERTILIZE', 'A_DO_NOTHING', 'D_NORTH', 'D_EAST', 'D_SOUTH', 'D_WEST', - 'VALUE_OF_MOVEMENT', 'VALUE_OF_CROPS', 'VALUE_OF_PLANT', + 'VALUE_OF_CROPS', 'VALUE_OF_PLANT', 'VALUE_OF_SAND', 'VALUE_OF_CLAY' ) @@ -66,8 +66,7 @@ A_HYDRATE = "hydrate" A_FERTILIZE = "fertilize" A_DO_NOTHING = "do nothing" -# Costs movement and fields: -VALUE_OF_MOVEMENT = 4 +# Costs fields: VALUE_OF_CROPS = 1 VALUE_OF_PLANT = 3 VALUE_OF_SAND = 7