From d16267826d257b0ea4d5f88f60f27002915a1092 Mon Sep 17 00:00:00 2001 From: Szymon Szczubkowski Date: Mon, 15 May 2023 16:58:23 +0200 Subject: [PATCH] remove bandaid stones, TODO: fix astar --- astar_search.py | 9 +++++++-- blocks.py | 4 ---- main.py | 2 +- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/astar_search.py b/astar_search.py index 806afab4..223e343d 100644 --- a/astar_search.py +++ b/astar_search.py @@ -37,7 +37,7 @@ class Search: cost = 0 # cost += 10 if stones[node.state[0], node.state[1]] == 1 else 1 cost += 1000 if (node.state[0], node.state[1]) in stones else 1 - cost += 30 if ((node.state[0]), (node.state[1])) in flowers else 1 + cost += 300 if ((node.state[0]), (node.state[1])) in flowers else 1 if node.parent: node = node.parent @@ -48,7 +48,7 @@ class Search: return abs(node.state[0] - goal[0]) + abs(node.state[1] - goal[1]) #bandaid to know about stones - def astarsearch(self, istate, goaltest, stones, flowers): + def astarsearch(self, istate, goaltest, cStones, cFlowers): #to be expanded def cost_old(x, y): @@ -62,6 +62,11 @@ class Search: y = istate[1] angle = istate[2] + stones = [(x*50, y*50) for (x, y) in cStones] + flowers = [(x*50, y*50) for (x, y) in cFlowers] + + print(stones) + # fringe = [(Node([x, y, angle]), cost_old(x, y))] # queue (moves/states to check) fringe = [(Node([x, y, angle]))] # queue (moves/states to check) fringe[0].distance = self.cost(fringe[0], stones, goaltest, flowers) diff --git a/blocks.py b/blocks.py index 4c1f49dc..606da61d 100644 --- a/blocks.py +++ b/blocks.py @@ -31,8 +31,6 @@ class Blocks: self.soil = soil.Soil() - self.stones = set() - #bandaid to let astar know about stones def locate_blocks(self, blocks_number, cell_number, body): for i in range(blocks_number): @@ -53,8 +51,6 @@ class Blocks: self.parent_screen.blit(self.alive_leaf_image, (x, y)) if color == 'stone': self.parent_screen.blit(self.stone_image, (x, y)) - #bandaid to let astar know about stones - self.stones.add((x, y)) if color == 'flower': self.parent_screen.blit(self.flower_image, (x, y)) if color == 'fawn_seed': diff --git a/main.py b/main.py index 9f32a0ed..e3f233f5 100644 --- a/main.py +++ b/main.py @@ -108,7 +108,7 @@ class Game: angles = {0: 'UP', 90: 'RIGHT', 270: 'LEFT', 180: 'DOWN'} #bandaid to know about stones tractor_next_moves = astar_search_object.astarsearch( - [self.tractor.x, self.tractor.y, angles[self.tractor.angle]], [random_x, random_y], self.blocks.stones, self.flower_body) + [self.tractor.x, self.tractor.y, angles[self.tractor.angle]], [random_x, random_y], self.stone_body, self.flower_body) else: self.tractor.move(tractor_next_moves.pop(0)[0], self.cell_size, self.cell_number) elif event.type == QUIT: