Allow bot names 1-9 instead of 1-3

This commit is contained in:
Tanner committed 2026-11-19 17:23:42 +00:00
1 parent fb28fefc8a
commit 1dd02f887c
9 files changed
+75 -48

No files matched your search

+2 -2
View File
@@ -73,8 +73,8 @@ The bot reads both the front and back of loaded signs. Use `!signs [distance]`
to inspect nearby text and coordinates; the default distance is 32 blocks. Sign to inspect nearby text and coordinates; the default distance is 32 blocks. Sign
matching is case-insensitive. For bot-addressed signs, the first word must be matching is case-insensitive. For bot-addressed signs, the first word must be
the bot's full name (for example, `mosfet1`) or its group name (for example, the bot's full name (for example, `mosfet1`) or its group name (for example,
`mosfet`, which addresses bots ending in `1`, `2`, or `3`). A colon after the `mosfet`, which addresses bots ending in any digit from `1` through `9`). A
address is optional. colon after the address is optional.
### Sand origin ### Sand origin
+6 -4
View File
@@ -1,6 +1,5 @@
import importlib import importlib
import collections import collections
import re
from math import floor, ceil, sqrt from math import floor, ceil, sqrt
from mosfet.info import blocks from mosfet.info import blocks
@@ -26,12 +25,15 @@ def phyp(p1, p2):
def bot_name_family(name): def bot_name_family(name):
"""Return a bot username with all digits removed, case-insensitively.""" """Return the group name for a bot ending in one digit from 1 to 9."""
return re.sub(r'\d', '', str(name)).casefold() name = str(name or '').casefold()
if len(name) > 1 and name[-1] in '123456789':
return name[:-1]
return name
def find_nearby_bots(global_state, position, distance): def find_nearby_bots(global_state, position, distance):
"""Find nearby online bots sharing this bot's digits-stripped name.""" """Find nearby online bots sharing this bot's numbered name family."""
own_name = str(global_state.get('name', '') or '') own_name = str(global_state.get('name', '') or '')
family = bot_name_family(own_name) family = bot_name_family(own_name)
if not family: if not family:
+6 -30
View File
@@ -125,11 +125,7 @@ class World:
def find_throw_signs(self, center, bot_name, distance=105): def find_throw_signs(self, center, bot_name, distance=105):
"""Find nearby signs directing this bot to throw an item at them.""" """Find nearby signs directing this bot to throw an item at them."""
bot_name = str(bot_name).casefold() bot_name = str(bot_name).casefold()
group_name = (bot_name[:-1] if len(bot_name) > 1 and addresses = {bot_name, utils.bot_name_family(bot_name)}
bot_name[-1] in '123' else None)
addresses = {bot_name}
if group_name:
addresses.add(group_name)
result = [] result = []
for sign in self.find_signs(center, distance): for sign in self.find_signs(center, distance):
@@ -163,11 +159,7 @@ class World:
def find_sand_origins(self, center, bot_name, distance=200): def find_sand_origins(self, center, bot_name, distance=200):
"""Find signs addressed to this bot that designate a sand origin.""" """Find signs addressed to this bot that designate a sand origin."""
bot_name = str(bot_name).casefold() bot_name = str(bot_name).casefold()
group_name = (bot_name[:-1] if len(bot_name) > 1 and addresses = {bot_name, utils.bot_name_family(bot_name)}
bot_name[-1] in '123' else None)
addresses = {bot_name}
if group_name:
addresses.add(group_name)
result = [] result = []
for sign in self.find_signs(center, distance): for sign in self.find_signs(center, distance):
@@ -188,11 +180,7 @@ class World:
def find_safety_signs(self, center, bot_name, distance=80): def find_safety_signs(self, center, bot_name, distance=80):
"""Find nearby signs addressed to this bot that mark safe refuges.""" """Find nearby signs addressed to this bot that mark safe refuges."""
bot_name = str(bot_name).casefold() bot_name = str(bot_name).casefold()
group_name = (bot_name[:-1] if len(bot_name) > 1 and addresses = {bot_name, utils.bot_name_family(bot_name)}
bot_name[-1] in '123' else None)
addresses = {bot_name}
if group_name:
addresses.add(group_name)
result = [] result = []
for sign in self.find_signs(center, distance): for sign in self.find_signs(center, distance):
@@ -360,11 +348,7 @@ class World:
def find_cache_chests(self, center, bot_name, distance=105): def find_cache_chests(self, center, bot_name, distance=105):
"""Find bot/group-addressed general cache chests from signs.""" """Find bot/group-addressed general cache chests from signs."""
bot_name = str(bot_name).casefold() bot_name = str(bot_name).casefold()
group_name = (bot_name[:-1] if len(bot_name) > 1 and addresses = {bot_name, utils.bot_name_family(bot_name)}
bot_name[-1] in '123' else None)
addresses = {bot_name}
if group_name:
addresses.add(group_name)
grouped = {} grouped = {}
for sign in self.find_signs(center, distance): for sign in self.find_signs(center, distance):
@@ -392,11 +376,7 @@ class World:
def find_supply_chests(self, center, bot_name, distance=80): def find_supply_chests(self, center, bot_name, distance=80):
"""Find chests whose sign is addressed to this bot's supplies.""" """Find chests whose sign is addressed to this bot's supplies."""
bot_name = str(bot_name).casefold() bot_name = str(bot_name).casefold()
group_name = (bot_name[:-1] if len(bot_name) > 1 and addresses = {bot_name, utils.bot_name_family(bot_name)}
bot_name[-1] in '123' else None)
addresses = {bot_name}
if group_name:
addresses.add(group_name)
grouped = {} grouped = {}
sign_offsets = ( sign_offsets = (
@@ -442,11 +422,7 @@ class World:
def sign_policies(self, bot_name, distance=None): def sign_policies(self, bot_name, distance=None):
"""Parse sign policies addressed to this bot or its numbered group.""" """Parse sign policies addressed to this bot or its numbered group."""
bot_name = str(bot_name).casefold() bot_name = str(bot_name).casefold()
group_name = (bot_name[:-1] if len(bot_name) > 1 and addresses = {bot_name, utils.bot_name_family(bot_name)}
bot_name[-1] in '123' else None)
addresses = {bot_name}
if group_name:
addresses.add(group_name)
center = utils.pint(self.g.pos) center = utils.pint(self.g.pos)
policies = [] policies = []
+7
View File
@@ -41,6 +41,13 @@ class TestInventoryCommands(unittest.TestCase):
self.commands.handle_chat(('CHAT', 'tester', 'mosfet1: 1drop')) self.commands.handle_chat(('CHAT', 'tester', 'mosfet1: 1drop'))
self.assertEqual(self.chat.sent, ['ok']) self.assertEqual(self.chat.sent, ['ok'])
def test_command_prefix_uses_the_ninth_bot_number(self):
self.commands.g.name = 'mosfet9'
self.commands.handle_chat(('CHAT', 'tester', 'mosfet9: 9drop'))
self.assertEqual(self.chat.sent, ['ok'])
def test_dump_command_starts_dump_for_item_id(self): def test_dump_command_starts_dump_for_item_id(self):
self.commands.handle_chat(('CHAT', 'tester', 'mosfet1: 1dump 62')) self.commands.handle_chat(('CHAT', 'tester', 'mosfet1: 1dump 62'))
self.assertEqual(self.game.dump_item, 62) self.assertEqual(self.game.dump_item, 62)
+10 -8
View File
@@ -5,11 +5,13 @@ from mosfet import utils
class NearbyBotTests(unittest.TestCase): class NearbyBotTests(unittest.TestCase):
def test_family_removes_every_digit(self): def test_family_strips_only_a_valid_single_digit_suffix(self):
self.assertEqual(utils.bot_name_family('foo1'), 'foo') for suffix in range(1, 10):
self.assertEqual(utils.bot_name_family('foo2'), 'foo') self.assertEqual(
self.assertEqual(utils.bot_name_family('bar1'), 'bar') utils.bot_name_family('foo{}'.format(suffix)), 'foo')
self.assertEqual(utils.bot_name_family('bar123'), 'bar') self.assertEqual(utils.bot_name_family('FOO9'), 'foo')
self.assertEqual(utils.bot_name_family('bar123'), 'bar12')
self.assertEqual(utils.bot_name_family('foo10'), 'foo10')
def test_finds_only_nearby_other_bots_in_same_name_family(self): def test_finds_only_nearby_other_bots_in_same_name_family(self):
global_state = Munch( global_state = Munch(
@@ -22,7 +24,7 @@ class NearbyBotTests(unittest.TestCase):
}, },
player_names={ player_names={
'self': 'bar1', 'self': 'bar1',
'bar-uuid': 'bar123', 'bar-uuid': 'bar9',
'foo-uuid': 'foo2', 'foo-uuid': 'foo2',
'far-uuid': 'bar2', 'far-uuid': 'bar2',
}) })
@@ -30,12 +32,12 @@ class NearbyBotTests(unittest.TestCase):
nearby = utils.find_nearby_bots( nearby = utils.find_nearby_bots(
global_state, (0, 64, 0), 4) global_state, (0, 64, 0), 4)
self.assertEqual([bot['name'] for bot in nearby], ['bar123']) self.assertEqual([bot['name'] for bot in nearby], ['bar9'])
self.assertEqual(nearby[0]['distance'], 3.0) self.assertEqual(nearby[0]['distance'], 3.0)
def test_returns_no_matches_without_a_bot_name_family(self): def test_returns_no_matches_without_a_bot_name_family(self):
self.assertEqual(utils.find_nearby_bots( self.assertEqual(utils.find_nearby_bots(
Munch(name='123', players={}, player_names={}), Munch(name='', players={}, player_names={}),
(0, 64, 0), 4), []) (0, 64, 0), 4), [])
+3 -1
View File
@@ -48,8 +48,10 @@ class SafetySignTests(unittest.TestCase):
self.assertEqual(bot2[1]['normal'], (-1.0, 0.0, 0.0)) self.assertEqual(bot2[1]['normal'], (-1.0, 0.0, 0.0))
self.assertEqual([sign['position'] for sign in world.find_safety_signs( self.assertEqual([sign['position'] for sign in world.find_safety_signs(
(0, 64, 0), 'mosfet1', 10)], [group_sign]) (0, 64, 0), 'mosfet1', 10)], [group_sign])
self.assertEqual([sign['position'] for sign in world.find_safety_signs(
(0, 64, 0), 'mosfet9', 10)], [group_sign])
self.assertEqual(world.find_safety_signs( self.assertEqual(world.find_safety_signs(
(0, 64, 0), 'mosfet4', 10), []) (0, 64, 0), 'mosfet10', 10), [])
def test_safety_openings_try_text_facing_standable_positions_first(self): def test_safety_openings_try_text_facing_standable_positions_first(self):
sign_pos = (0, 64, 0) sign_pos = (0, 64, 0)
+34 -2
View File
@@ -93,10 +93,11 @@ class SignReadingTests(unittest.TestCase):
'mosfet', 'stay within25', 'square', '', 'mosfet', 'stay within25', 'square', '',
]}}}, ]}}},
}), pos=(0, 64, 0))) }), pos=(0, 64, 0)))
for bot_name in ('mosfet1', 'mosfet2', 'mosfet3'): for bot_num in range(1, 10):
bot_name = 'mosfet{}'.format(bot_num)
self.assertEqual([p['shape'] for p in self.assertEqual([p['shape'] for p in
group_world.sign_policies(bot_name)], ['square']) group_world.sign_policies(bot_name)], ['square'])
self.assertEqual(group_world.sign_policies('mosfet4'), []) self.assertEqual(group_world.sign_policies('mosfet10'), [])
individual_world = World(Munch(chunks=Munch(block_entities={ individual_world = World(Munch(chunks=Munch(block_entities={
(1, 64, 0): {'data': {'front_text': {'messages': [ (1, 64, 0): {'data': {'front_text': {'messages': [
@@ -131,6 +132,37 @@ class SignReadingTests(unittest.TestCase):
world.find_sand_origins((0, 64, 0), 'mosfet2')], world.find_sand_origins((0, 64, 0), 'mosfet2')],
[(1, 64, 0), (2, 64, 0)], [(1, 64, 0), (2, 64, 0)],
) )
self.assertEqual(
[origin['position'] for origin in
world.find_sand_origins((0, 64, 0), 'mosfet9')],
[(1, 64, 0)],
)
self.assertEqual(
world.find_sand_origins((0, 64, 0), 'mosfet10'), [])
def test_supply_sign_group_address_includes_bot_nine_only(self):
sign_pos = (0, 64, 0)
chest_pos = (1, 64, 0)
sign_state = blocks.MCD_BLOCKS['oak_wall_sign']['minStateId']
chest_state = next(
state for state in blocks.CHEST_IDS
if blocks.PROPS[state].get('type') == 'single')
block_states = {sign_pos: sign_state, chest_pos: chest_state}
chunks = Munch(
block_entities={sign_pos: {'data': {'front_text': {
'messages': ['mosfet supplies', '', '', ''],
}}}},
index={},
get_block_at=lambda *pos: block_states.get(tuple(pos), blocks.AIR),
)
world = World(Munch(chunks=chunks))
supplies = world.find_supply_chests(sign_pos, 'mosfet9', 10)
self.assertEqual(len(supplies), 1)
self.assertEqual(supplies[0]['positions'], (chest_pos,))
self.assertEqual(world.find_supply_chests(
sign_pos, 'mosfet10', 10), [])
def test_sign_policies_read_any_distance_within_loaded_signs(self): def test_sign_policies_read_any_distance_within_loaded_signs(self):
position = (100, 64, 0) position = (100, 64, 0)
+3 -1
View File
@@ -99,7 +99,9 @@ class StorageLabelTests(unittest.TestCase):
self.assertEqual(group_caches[0]['position'], side_chest) self.assertEqual(group_caches[0]['position'], side_chest)
self.assertEqual(group_caches[0]['positions'], (side_chest,)) self.assertEqual(group_caches[0]['positions'], (side_chest,))
self.assertEqual(world.find_cache_chests( self.assertEqual(world.find_cache_chests(
sign_pos, 'mosfet4', 10), []) sign_pos, 'mosfet9', 10), group_caches)
self.assertEqual(world.find_cache_chests(
sign_pos, 'mosfet10', 10), [])
def test_side_chest_takes_priority_over_chest_below_sign(self): def test_side_chest_takes_priority_over_chest_below_sign(self):
sign_pos = (0, 64, 0) sign_pos = (0, 64, 0)
+4
View File
@@ -64,6 +64,10 @@ class ThrowSignTests(unittest.TestCase):
bot1 = world.find_throw_signs((0, 64, 0), 'mosfet1', 10) bot1 = world.find_throw_signs((0, 64, 0), 'mosfet1', 10)
self.assertEqual([sign['position'] for sign in bot1], [group_sign]) self.assertEqual([sign['position'] for sign in bot1], [group_sign])
bot9 = world.find_throw_signs((0, 64, 0), 'mosfet9', 10)
self.assertEqual([sign['position'] for sign in bot9], [group_sign])
self.assertEqual(world.find_throw_signs(
(0, 64, 0), 'mosfet10', 10), [])
def test_throw_accepts_unqualified_items_and_species_log_labels(self): def test_throw_accepts_unqualified_items_and_species_log_labels(self):
single_item_sign = (0, 64, 0) single_item_sign = (0, 64, 0)