Don't pick up bed items near other bots
This commit is contained in:
1 parent
032b4cfd33
commit
185cefced9
4 files changed
+142
-1
No files matched your search
@@ -52,6 +52,46 @@ class GroundSupplyTests(unittest.TestCase):
|
||||
self.assertEqual(state.target_items, (items.CHEST_ID,))
|
||||
self.assertIs(state.state.__func__, state.find_ground_items.__func__)
|
||||
|
||||
def test_grab_supplies_leaves_bed_drop_near_sibling_bot(self):
|
||||
bed = Munch(
|
||||
entity_id=13, item_id=next(iter(items.BED_IDS)),
|
||||
x=1.0, y=64.0, z=0.0)
|
||||
|
||||
class FakeWorld:
|
||||
@staticmethod
|
||||
def find_objects(_item_ids):
|
||||
return [bed]
|
||||
|
||||
@staticmethod
|
||||
def path_to_place(*_args):
|
||||
raise AssertionError('must not path to another bot\'s bed')
|
||||
|
||||
class FakeGame:
|
||||
@staticmethod
|
||||
def count_items(_item_ids):
|
||||
return 0
|
||||
|
||||
g = Munch(
|
||||
name='mosfet1', pos=(0.5, 64.0, 0.5), world=FakeWorld(),
|
||||
game=FakeGame(), players={
|
||||
2: Munch(player_uuid='other-uuid', x=2.0, y=64.0, z=0.0),
|
||||
}, player_names={'other-uuid': 'mosfet2'}, objects={13: bed},
|
||||
path=[], ground_stack_counts={},
|
||||
)
|
||||
state = GrabSuppliesStates(g)
|
||||
state.checked_ground_items = set()
|
||||
state.checked_ground_groups = set()
|
||||
state.ground_stack_counts = {}
|
||||
state.target_items = tuple(items.BED_IDS)
|
||||
state.target_maximum_stacks = 1
|
||||
|
||||
self.assertFalse(state._has_nearby_ground_items(
|
||||
state.target_items, state.target_maximum_stacks))
|
||||
state.find_ground_items()
|
||||
|
||||
self.assertIn(state.target_items, state.checked_ground_groups)
|
||||
self.assertIs(state.state.__func__, state.check_supplies.__func__)
|
||||
|
||||
def test_supply_selection_uses_only_addressed_supply_chests(self):
|
||||
position = (4, 64, 0)
|
||||
chest_record = {
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
import unittest
|
||||
from munch import Munch
|
||||
|
||||
from mosfet import utils
|
||||
|
||||
|
||||
class NearbyBotTests(unittest.TestCase):
|
||||
def test_family_removes_every_digit(self):
|
||||
self.assertEqual(utils.bot_name_family('foo1'), 'foo')
|
||||
self.assertEqual(utils.bot_name_family('foo2'), 'foo')
|
||||
self.assertEqual(utils.bot_name_family('bar1'), 'bar')
|
||||
self.assertEqual(utils.bot_name_family('bar123'), 'bar')
|
||||
|
||||
def test_finds_only_nearby_other_bots_in_same_name_family(self):
|
||||
global_state = Munch(
|
||||
name='bar1',
|
||||
players={
|
||||
1: Munch(player_uuid='self', x=0, y=64, z=0),
|
||||
2: Munch(player_uuid='bar-uuid', x=3, y=64, z=0),
|
||||
3: Munch(player_uuid='foo-uuid', x=1, y=64, z=0),
|
||||
4: Munch(player_uuid='far-uuid', x=4.01, y=64, z=0),
|
||||
},
|
||||
player_names={
|
||||
'self': 'bar1',
|
||||
'bar-uuid': 'bar123',
|
||||
'foo-uuid': 'foo2',
|
||||
'far-uuid': 'bar2',
|
||||
})
|
||||
|
||||
nearby = utils.find_nearby_bots(
|
||||
global_state, (0, 64, 0), 4)
|
||||
|
||||
self.assertEqual([bot['name'] for bot in nearby], ['bar123'])
|
||||
self.assertEqual(nearby[0]['distance'], 3.0)
|
||||
|
||||
def test_returns_no_matches_without_a_bot_name_family(self):
|
||||
self.assertEqual(utils.find_nearby_bots(
|
||||
Munch(name='123', players={}, player_names={}),
|
||||
(0, 64, 0), 4), [])
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user