Skip to content

Commit 16fcdba

Browse files
committed
fix tests
1 parent 10ec5c9 commit 16fcdba

File tree

4 files changed

+27
-5
lines changed

4 files changed

+27
-5
lines changed

tale/driver.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,7 @@ def go_through_exit(self, player: player.Player, direction: str, evoke: bool=Tru
645645
except errors.LocationIntegrityError:
646646
# fail silently
647647
pass
648-
elif random.random() < 1:
648+
elif random.random() < 0.2 and isinstance(self.story, DynamicStory):
649649
dynamic_story = typing.cast(DynamicStory, self.story)
650650
zone = dynamic_story.find_zone(location=xt.target.name)
651651
self.llm_util.generate_random_spawn(xt.target, zone.get_info())

tale/llm/requests/build_location.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ def build_prompt(self, args: dict) -> str:
2727
spawn_chance = 0.25
2828
spawn = random.random() < spawn_chance
2929
if spawn:
30+
mood = zone_info.get('mood', 0)
31+
if isinstance(mood, str):
32+
num_mood = parse_utils.mood_int_from_string(mood)
33+
else:
34+
num_mood = mood
3035
num_mood = (int) (random.gauss(zone_info.get('mood', 0), 2))
3136
level = (int) (random.gauss(zone_info.get('level', 1), 2))
3237
mood_string = parse_utils.mood_string_from_int(num_mood)

tale/parse_utils.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ def _init_weapon(item: dict):
220220
short_descr=item.get('short_descr', ''),
221221
descr=item.get('descr', ''),
222222
wc=item.get('wc', 1),
223-
weapon_type=item.get('type', WeaponType.UNARMED),
223+
weapon_type=WeaponType[item.get('weapon_type', WeaponType.UNARMED.name)],
224224
base_damage=item.get('base_damage', random.randint(1,3)),
225225
bonus_damage=item.get('bonus_damage', 0),
226226
weight=item.get('weight', 1),
@@ -449,6 +449,22 @@ def mood_string_from_int(mood: int):
449449
else:
450450
return f' slightly {base_mood}'
451451

452+
def mood_string_to_int(mood: str):
453+
""" Returns an int from a mood description"""
454+
if mood.startswith('uttermost'):
455+
return 5 if mood.endswith('friendly') else -5
456+
if mood.startswith('extremely'):
457+
return 4 if mood.endswith('friendly') else -4
458+
if mood.startswith('very'):
459+
return 3 if mood.endswith('friendly') else -3
460+
if mood.startswith('friendly'):
461+
return 2
462+
if mood.startswith('hostile'):
463+
return -2
464+
if mood.startswith('neutral'):
465+
return 0
466+
return 1 if mood.endswith('friendly') else -1
467+
452468
def replace_items_with_world_items(items: list, world_items: dict) -> list:
453469
""" Replaces items in a list with world items"""
454470
new_items = []

tests/test_llm_utils.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from tale import mud_context, weapon_type
55
from tale import zone
66
from tale import util
7-
from tale.base import Location
7+
from tale.base import Item, Location, Weapon
88
from tale.coord import Coord
99
from tale.json_story import JsonStory
1010
from tale.llm.llm_utils import LlmUtil
@@ -233,17 +233,18 @@ def test_generate_start_zone(self):
233233
assert(result.races == ['human', 'elf', 'dwarf'])
234234

235235
def test_generate_world_items(self):
236-
self.llm_util._world_building.io_util.response = '{"items":[{"name": "sword", "type": "Weapon", "value": 100}, {"name": "shield", "type": "Armor", "value": 60}]}'
236+
self.llm_util._world_building.io_util.response = '{"items":[{"name": "sword", "type": "Weapon","value": 100}, {"name": "shield", "type": "Armor", "value": 60}]}'
237237
result = self.llm_util._world_building.generate_world_items(story_context='',
238238
story_type='',
239239
world_mood=0,
240240
world_info='')
241241
assert(len(result) == 2)
242242
sword = result.get('sword')
243243
assert(sword.name == 'sword')
244-
assert(sword.type == weapon_type.WeaponType.ONE_HANDED)
244+
assert(isinstance(sword, Weapon))
245245
shield = result.get('shield')
246246
assert(shield.name == 'shield')
247+
assert(isinstance(shield, Item))
247248

248249
def test_generate_world_creatures(self):
249250
# mostly for coverage

0 commit comments

Comments
 (0)