Search for next block to place in 2D

This commit is contained in:
2020-12-06 23:53:28 +00:00
parent bce868a522
commit 86846a5c02
2 changed files with 55 additions and 36 deletions
+27
View File
@@ -107,6 +107,33 @@ def break_time(block_id, held_item=0, in_water=False, on_ground=True, enchantmen
return time
def search_2d(distance=0):
def get_neighbors(x,y,z):
return [
(x+1, y+0, z+0),
#(x+1, y+0, z+1),
(x+0, y+0, z-1),
#(x-1, y+0, z+1),
(x-1, y+0, z+0),
#(x-1, y+0, z-1),
(x+0, y+0, z+1),
#(x+1, y+0, z-1),
]
to_visit = collections.deque([(0, 0, 0)])
visited = set()
while to_visit:
cur = to_visit.pop()
if cur in visited:
continue
if distance and hypot(*cur) > distance:
continue
for neighbor in get_neighbors(*cur):
to_visit.appendleft(neighbor)
visited.add(cur)
yield cur
def search_3d(distance=0, y_limit=0):
def get_neighbors(x,y,z):
return [