Fix None directions and duplicate exits in start location generation #109
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "copilot/fix-directions-start-location"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
During "anything" story start location generation, exits were created with
direction: null, producing descriptions like "To the None you see Winding Way" and causingTypeError: '<' not supported between instances of 'NoneType' and 'str'when sorting exits inLocation.look(). Additionally, LLM-generated JSON sometimes contained duplicate exit entries, resulting in multiple identical exits in the location.Root Causes
Four related issues in
tale/parse_utils.py:_select_non_occupied_direction()only checked 4 cardinal directions, returningNoneimplicitly when all occupiedopposite_direction()didn't handle diagonal directions, returningNonefor unknown inputsparse_generated_exits()appended opposite directions withoutNonechecksparse_generated_exits()processed all exits without deduplication, allowing duplicate entriesChanges
Extended direction handling
_select_non_occupied_direction(): Check 10 directions (north/south/east/west/northeast/northwest/southeast/southwest/up/down) with fallback to 'north'opposite_direction(): Added diagonal direction mappings (northeast↔southwest, northwest↔southeast)Added None safety in exit generation
Added duplicate exit filtering
Tests
Added
test_parse_utils_none_direction.pywith 7 test cases covering:Files Changed
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.
@copilot This seems to work better. I've noticed it might create duplicate items in the exits list, though:
Can you make sure there are no duplicates, possibly by using sets instead of lists?
...
Fixed in commit
ea035d4. Added set-based deduplication that tracks seen exits using (name, direction) tuples. Duplicate exits with the same name and direction are now skipped during processing. The exit names are normalized (lowercased and "the " is stripped) to ensure proper comparison.