Ovid (publius_ovidius) wrote,
Ovid
publius_ovidius

  • Mood:

Modelling worlds

I went for another run today. Two and a half miles in 21 minutes. Certainly not my fastest time but I'm trying to avoid more injuries.

In other news, I'm writing software that allows one to arbitrarily model a world and agents in the world which can move around and freely interact with it. There's an interesting distinction between things in the world and the words to describe them. You might have a "box" and the word to describe that is, not surprisingly, "box". However, what if you have two boxes? You use adjectives such as "big" or "wooden" to describe them.

You also have verbs such as "take", "drop", "move", etc. Because Perl allows you to assign custom attributes to subroutines, it's fairly easy to implement verbs.

sub describe : Verb(look) {
    my $self = shift;
    my $adjectives = $self->_printable_list( $self->adjectives );
    return "$adjectives " . $name;  # this is actually cached
}

With that, the verb "describe" and its synonym "look" are automatically added to the vocabulary and you can just do this:

print $agent->describe($box);

However, because we automatically get synonyms, we can also do this:

print $agent->look($box);

That works because the Agent class has a can_do() method which checks to see which verbs or their synonyms are in the vocabulary and, if they exist, it calls the $box->describe method.

My goal is to eventually add an English grammar on top of this so that the user can run a shell and interact with the world in natural language. Of course, while this is clearly beneficial for text adventures, it actually can be used for any setting where the user wants to be able to model a world and interact with it. You could use this to set up a virtual text-based "work center" where your employees can wander from area to area in the world and communicate with other employees, take memos, etc. Of course, it's not that I think anyone will actually do that, but it's possible.

Tags: programming
Subscribe
  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 13 comments