Skip to content

Commit 4539dd0

Browse files
Minor fix for fuzzy exit name match (#402)
##Summary This PR enhances the exit navigation system by implementing priority checking for standard compass direction abbreviations before falling back to fuzzy matching. The changes ensure that players can reliably use common direction shortcuts (n, s, e, w, ne, nw, se, sw) without ambiguity from custom exit names. ##Changes - Integrated the keywords system to resolve direction aliases (e.g., "n" → "north") before fuzzy matching - Added priority checking for exact direction matches across regular exits, temporary exits, and mutator exits - Preserved fuzzy matching behavior for non-standard exit names (portals, gates, custom exits) - Removed hardcoded direction validation in favor of the centralized keywords system ##Technical Details The FindExitByName method now follows this logic: 1. First attempts to resolve input as a direction alias via keywords.TryDirectionAlias() 2. If a direction alias is found, checks for exact matches only (no fuzzy matching) 3. Falls back to existing fuzzy matching for all other exit types This approach provides deterministic behavior for standard directions while maintaining flexibility for custom exit names.
1 parent 44284cf commit 4539dd0

File tree

1 file changed

+26
-12
lines changed

1 file changed

+26
-12
lines changed

internal/rooms/rooms.go

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"github.com/GoMudEngine/GoMud/internal/exit"
1616
"github.com/GoMudEngine/GoMud/internal/gametime"
1717
"github.com/GoMudEngine/GoMud/internal/items"
18+
"github.com/GoMudEngine/GoMud/internal/keywords"
1819
"github.com/GoMudEngine/GoMud/internal/mobs"
1920
"github.com/GoMudEngine/GoMud/internal/mutators"
2021
"github.com/GoMudEngine/GoMud/internal/users"
@@ -29,6 +30,7 @@ var (
2930
"*": defaultMapSymbol,
3031
//"•": "*",
3132
}
33+
3234
)
3335

3436
type FindFlag uint16
@@ -1716,6 +1718,29 @@ func (r *Room) FindNoun(noun string) (foundNoun string, nounDescription string)
17161718

17171719
func (r *Room) FindExitByName(exitNameSearch string) (exitName string, exitRoomId int) {
17181720

1721+
// Check for direction aliases from keywords.yaml first
1722+
fullDirection := keywords.TryDirectionAlias(exitNameSearch)
1723+
if fullDirection != exitNameSearch {
1724+
// A direction alias was found, check if this exact direction exists
1725+
if exitInfo, ok := r.Exits[fullDirection]; ok {
1726+
return fullDirection, exitInfo.RoomId
1727+
}
1728+
// Check temporary exits
1729+
if tempExit, ok := r.ExitsTemp[fullDirection]; ok {
1730+
return fullDirection, tempExit.RoomId
1731+
}
1732+
// Check mutator exits
1733+
for mut := range r.ActiveMutators {
1734+
spec := mut.GetSpec()
1735+
if exitInfo, ok := spec.Exits[fullDirection]; ok {
1736+
return fullDirection, exitInfo.RoomId
1737+
}
1738+
}
1739+
// Direction alias used but exit doesn't exist
1740+
return ``, 0
1741+
}
1742+
1743+
// Build list of all exits for fuzzy matching
17191744
exitNames := []string{}
17201745
for exitName, _ := range r.Exits {
17211746
exitNames = append(exitNames, exitName)
@@ -1734,21 +1759,10 @@ func (r *Room) FindExitByName(exitNameSearch string) (exitName string, exitRoomI
17341759
}
17351760
}
17361761

1762+
// Use fuzzy matching for all exits
17371763
exactMatch, closeMatch := util.FindMatchIn(exitNameSearch, exitNames...)
17381764

17391765
if len(exactMatch) == 0 {
1740-
1741-
exactMatchesRequired := []string{
1742-
`southeast`, `southwest`,
1743-
`northeast`, `northwest`,
1744-
}
1745-
// Do not allow prefix matches on southwest etc
1746-
for _, requiredCloseMatchTerm := range exactMatchesRequired {
1747-
if requiredCloseMatchTerm == closeMatch {
1748-
return "", 0
1749-
}
1750-
}
1751-
17521766
portalStr := `portal`
17531767
if strings.HasPrefix(closeMatch, exitNameSearch) {
17541768
exactMatch = closeMatch

0 commit comments

Comments
 (0)