Search for next block to place in 2D
This commit is contained in:
@@ -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 [
|
||||
|
||||
Reference in New Issue
Block a user