Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

Ovid (2709)

  (email not shown publicly)
AOL IM: ovidperl (Add Buddy, Send Message)

Stuff with the Perl Foundation. A couple of patches in the Perl core. A few CPAN modules. That about sums it up.

Journal of Ovid (2709)

Saturday October 29, 2005
01:52 PM

Modeling the World Via Text Adventures

[ #27365 ]

I've been ranting a bit about real-world modeling and databases. The real-world is not relational so I want to be able to create a hierarchical model in a database. Unfortunately, autarch had the cheek to point out that the real world is not hierarchical either.

Damn it, he's right. So I decided that in order for me to get a better handle on the problem space I need to create the model of a world. So far it's pretty simplistic but I can put items in other items and take them out again.

sub put {
    my ( $self, $thing ) = @_;
    if ( $self->contains($thing) ) {
        die "\u$thing is already inside of $self.\n";
    elsif ( !$self->capacity ) {
        die "You can't put anything in $self.\n";
    elsif ( $self->curr_capacity < $thing->size ) {
        die "There's not enough room to fit $thing inside of $self.\n";
    else {
        $self->{gwt_contains}{$thing} = $thing;
        return $self;

sub take {
    my ($self, $thing) = @_;
    if ( ! $self->contains($thing) ) {
        die "\u$thing is not inside of $self.\n";
    return delete $self->{gwt_contains}{$thing};

In order to make this work, I have a World object and the world is populated by Things. A thing is abstract and corresponds to a class. For a given thing class, each concrete thing must have a unique set of adjectives which describe it.

my $world = Games::World->new;
    name  => 'box',
    class => 'Games::World::Thing::Box'

my $box = Games::World::Thing::Box->new({
    adjectives => 'red',
    size       => 15,
    capacity   => 12,

my $large_box = Games::World::Thing::Box->new({
    adjectives => ['red', 'large'],
    size       => 25,
    capacity   => 20,

I can now put the red box inside of the large red box but I can't put the large red box inside of the red box. Then things start to get difficult. What if I create an item with a capacity to hold the large box but the size to fix in the smaller box? Can I stick the large box in the new thing and then shove it into the smaller box? What happens? You probably get Zork.

adjectives is also a problem. In reality, I should probably list distinguishing properties such as size, color, weight, location, etc. Then the world should simply figure out how to describe and uniquely identify an item. Descriptions should be based on visible characteristics such as color, size and location. However, if someone tries to lift something which is too heavy, even if it's a small red box, then they find out more characteristics. Modeling a world is very difficult and I need to be able to ensure that I do not create two things which cannot be differentiated.

I should add that part of the reason I've put the Higher Order Perl parser on the CPAN is my goal of slapping a natural language interface over all of this. I really hadn't set out to make a text adventure (this time), but it really does give me insight into the problems I'm trying to solve.

Note: this is all pretty similar to Games::3D but the code Tels wrote is specifically for 3D rendering in game engines. It does a lot of the things I want, but doesn't do others.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • Why don't you try some programming in Inform? It's a little different paradigm than most programming languages I've seen, and might help you think about things differently?

    J. David works really hard, has a passion for writing good software, and knows many of the world's best Perl programmers
    • I've thought about that. Rael was telling me about his experiments with Inform and he was thinking about using that or something similar to make a natural language interface for some of the stuff he was doing. If I recall correctly, it was basically something which (for example), if someone sent you an invitation for a meeting, you could type "accept the invitation" and your calendar would automatically be updated and a message would be sent back saying you had accepted.

      As for why I didn't go that route