remove bandaid stones, TODO: fix astar
This commit is contained in:
parent
d3ffe50c91
commit
d16267826d
@ -37,7 +37,7 @@ class Search:
|
|||||||
cost = 0
|
cost = 0
|
||||||
# cost += 10 if stones[node.state[0], node.state[1]] == 1 else 1
|
# 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 += 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:
|
if node.parent:
|
||||||
node = node.parent
|
node = node.parent
|
||||||
@ -48,7 +48,7 @@ class Search:
|
|||||||
return abs(node.state[0] - goal[0]) + abs(node.state[1] - goal[1])
|
return abs(node.state[0] - goal[0]) + abs(node.state[1] - goal[1])
|
||||||
|
|
||||||
#bandaid to know about stones
|
#bandaid to know about stones
|
||||||
def astarsearch(self, istate, goaltest, stones, flowers):
|
def astarsearch(self, istate, goaltest, cStones, cFlowers):
|
||||||
|
|
||||||
#to be expanded
|
#to be expanded
|
||||||
def cost_old(x, y):
|
def cost_old(x, y):
|
||||||
@ -62,6 +62,11 @@ class Search:
|
|||||||
y = istate[1]
|
y = istate[1]
|
||||||
angle = istate[2]
|
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]), cost_old(x, y))] # queue (moves/states to check)
|
||||||
fringe = [(Node([x, y, angle]))] # 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)
|
fringe[0].distance = self.cost(fringe[0], stones, goaltest, flowers)
|
||||||
|
@ -31,8 +31,6 @@ class Blocks:
|
|||||||
|
|
||||||
self.soil = soil.Soil()
|
self.soil = soil.Soil()
|
||||||
|
|
||||||
self.stones = set()
|
|
||||||
#bandaid to let astar know about stones
|
|
||||||
|
|
||||||
def locate_blocks(self, blocks_number, cell_number, body):
|
def locate_blocks(self, blocks_number, cell_number, body):
|
||||||
for i in range(blocks_number):
|
for i in range(blocks_number):
|
||||||
@ -53,8 +51,6 @@ class Blocks:
|
|||||||
self.parent_screen.blit(self.alive_leaf_image, (x, y))
|
self.parent_screen.blit(self.alive_leaf_image, (x, y))
|
||||||
if color == 'stone':
|
if color == 'stone':
|
||||||
self.parent_screen.blit(self.stone_image, (x, y))
|
self.parent_screen.blit(self.stone_image, (x, y))
|
||||||
#bandaid to let astar know about stones
|
|
||||||
self.stones.add((x, y))
|
|
||||||
if color == 'flower':
|
if color == 'flower':
|
||||||
self.parent_screen.blit(self.flower_image, (x, y))
|
self.parent_screen.blit(self.flower_image, (x, y))
|
||||||
if color == 'fawn_seed':
|
if color == 'fawn_seed':
|
||||||
|
2
main.py
2
main.py
@ -108,7 +108,7 @@ class Game:
|
|||||||
angles = {0: 'UP', 90: 'RIGHT', 270: 'LEFT', 180: 'DOWN'}
|
angles = {0: 'UP', 90: 'RIGHT', 270: 'LEFT', 180: 'DOWN'}
|
||||||
#bandaid to know about stones
|
#bandaid to know about stones
|
||||||
tractor_next_moves = astar_search_object.astarsearch(
|
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:
|
else:
|
||||||
self.tractor.move(tractor_next_moves.pop(0)[0], self.cell_size, self.cell_number)
|
self.tractor.move(tractor_next_moves.pop(0)[0], self.cell_size, self.cell_number)
|
||||||
elif event.type == QUIT:
|
elif event.type == QUIT:
|
||||||
|
Loading…
Reference in New Issue
Block a user