remove bandaid stones, TODO: fix astar

This commit is contained in:
Szymon Szczubkowski 2023-05-15 16:58:23 +02:00
parent d3ffe50c91
commit d16267826d
3 changed files with 8 additions and 7 deletions

View File

@ -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)

View File

@ -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':

View File

@ -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: