Adventure Games and Interactive Fiction

More Accurate Entity Detection with Recursive Queries

by Gamefic on November 25, 2014

The Query::match method is pretty good at uniquely identifying entities when all the possibilities have unique names. If two items have the same name, however, unique matches are impossible. Right now I'm experimenting with a solution that solves the most common instance: portals named for compass directions.

Let's take an example of three rooms that connect to each other north and south:

room1 = make Room, :name => 'Room One'
room2 = make Room, :name => 'Room Two'
room1.connect room2, NORTH
room3 = make Room, :name => 'Room Three'
room2.connect room3, NORTH
door = pick("north")

The pick method will fail because it can't identify a unique entity named "north." There are two of them.

I rewrote Query::match to look for "in" among the description keywords. If it's found, it performs a new search with the remaining keywords. If this search finds an entity, it searches that entity's children using the keywords that preceded "in." Now Plot#pick will work for any of the following:

pick("north in room one")
pick("south in room two")
pick("south in three")

If the recursive search does not find a unique entity, the current search continues using "in" as the next keyword.

The new code is available in the GitHub repo on the "recursive-query-matches" branch.