Reverse order slices are found, fix bugs

This commit is contained in:
Tanner Collin 2020-12-02 00:02:26 -07:00
parent b7295b4beb
commit 00846538e8
2 changed files with 29 additions and 26 deletions

18
game.py
View File

@ -211,19 +211,17 @@ class MCWorld:
return False return False
def find_sand_slice(self, center, distance, skip_to=(0, 0)): def find_sand_slice(self, center, distance, bad_slices=[]):
# returns the centre coord of the next 5x5x1 slice that still has # returns the centre coord of the next 5x5x1 slice that still has
# diggable sand in it. lower slices are only valid if there's an # diggable sand in it. lower slices are only valid if there's an
# adjacent slice farther at the same level. this should ensure an # adjacent slice farther at the same level. this should ensure an
# upside down pyramid gets excavated so the edges are still climbable # upside down pyramid gets excavated so the edges are still climbable
skip_vertical, skip_spiral = skip_to for v in count():
for v in count(skip_vertical):
peak = utils.padd(center, (0, 20-v, 0)) peak = utils.padd(center, (0, 20-v, 0))
slices = []
layer = 0 layer = 0
start_step = skip_spiral if v == skip_vertical else 0 for step in count():
for step in count(start_step):
offset = utils.spiral(step) offset = utils.spiral(step)
layer = max(layer, *offset) layer = max(layer, *offset)
offset = utils.pmul(offset, 3) offset = utils.pmul(offset, 3)
@ -233,10 +231,12 @@ class MCWorld:
if utils.phyp(center, check) >= distance: if utils.phyp(center, check) >= distance:
break break
if self.check_sand_slice(check): if self.check_sand_slice(check) and check not in bad_slices:
return (v-1, step+1), check slices.append(check)
if v > 40: if len(slices):
return slices[-1]
elif v > 40:
return None, None return None, None

37
jobs.py
View File

@ -305,13 +305,13 @@ class GatherSandStates:
print('Finding new slice...') print('Finding new slice...')
w = self.g.world w = self.g.world
#o = utils.padd(self.origin, (0, 10, 0))
print('using origin', self.origin) print('using origin', self.origin)
self.skip, s = w.find_sand_slice(self.origin, 50) s = w.find_sand_slice(self.origin, 50, self.bad_slices)
print('Found slice:', s, 'skip:', self.skip) print('Found slice:', s)
if s: if s:
self.slice = s self.slice = s
#self.bad_slices.append(s)
self.state = self.find_new_sand self.state = self.find_new_sand
else: else:
print('No slices remaining.') print('No slices remaining.')
@ -385,8 +385,8 @@ class GatherSandStates:
self.state = self.idle self.state = self.idle
self.origin = utils.pint(self.g.pos) self.origin = utils.pint(self.g.pos)
self.skip = (0, 0)
self.slice = None self.slice = None
self.bad_slices = []
self.sand = None self.sand = None
self.bad_sand = [] self.bad_sand = []
self.wait_time = 0 self.wait_time = 0
@ -422,11 +422,13 @@ class GrabSandStates:
if utils.phyp(p, s_pos) > 6: if utils.phyp(p, s_pos) > 6:
continue continue
if s.entity_id in self.eid_blacklist:
continue
# skip if the sand is floating # skip if the sand is floating
if self.g.chunks.get_block_at(*check) in {0}: if self.g.chunks.get_block_at(*check) in {0}:
continue continue
if s.entity_id in self.eid_blacklist:
continue
self.eid_blacklist.append(s.entity_id)
navpath = w.path_to_place(p, s_pos) navpath = w.path_to_place(p, s_pos)
@ -434,16 +436,17 @@ class GrabSandStates:
self.g.path = navpath self.g.path = navpath
self.state = self.going_to_sand self.state = self.going_to_sand
self.sand = s_pos self.sand = s_pos
self.eid_blacklist.append(s.entity_id)
print('Going to sand', self.sand) print('Going to sand', self.sand)
return return
else:
print('Cant get to sand', self.sand)
print('Cant get to any more sand, aborting') print('Cant get to any more sand, aborting')
self.state = self.cleanup self.state = self.cleanup
def going_to_sand(self): def going_to_sand(self):
if utils.pint(self.g.pos) == self.sand: if utils.pint(self.g.pos) == self.sand:
self.state = self.find_sand self.state = self.cleanup
def cleanup(self): def cleanup(self):
self.g.look_at = None self.g.look_at = None
@ -607,7 +610,7 @@ class CacheItemsStates:
if not len(self.trapped_chests): if not len(self.trapped_chests):
print('No trapped chests') print('No trapped chests')
self.state = self.find_cache_spot self.state = self.select_chest
return return
chest = self.trapped_chests[0] chest = self.trapped_chests[0]
@ -634,6 +637,14 @@ class CacheItemsStates:
self.state = self.open_chest self.state = self.open_chest
def select_chest(self):
if self.g.game.select_item(items.CHEST_ID):
self.g.look_at = utils.padd(self.area, path.BLOCK_BELOW)
self.state = self.find_cache_spot
else:
print('No chest, aborting')
self.state = self.cleanup
def find_cache_spot(self): def find_cache_spot(self):
print('Finding a chest spot...') print('Finding a chest spot...')
w = self.g.world w = self.g.world
@ -667,15 +678,7 @@ class CacheItemsStates:
def going_to_area(self): def going_to_area(self):
if utils.pint(self.g.pos) == self.opening: if utils.pint(self.g.pos) == self.opening:
self.g.look_at = self.area self.g.look_at = self.area
self.state = self.select_chest
def select_chest(self):
if self.g.game.select_item(items.CHEST_ID):
self.g.look_at = utils.padd(self.area, path.BLOCK_BELOW)
self.state = self.place_chest self.state = self.place_chest
else:
print('No chest, aborting')
self.state = self.cleanup
def place_chest(self): def place_chest(self):
self.g.game.place_block(self.area, BlockFace.TOP) self.g.game.place_block(self.area, BlockFace.TOP)