Here’s some code that works, I guess, but I think I am missing something to make it work more sensibly and generally. I’d like to be able to name several objects with the same name. But I would like to be able to disambiguate them, too.
[code]“happycats” by andrew
a cat is a kind of thing. a cat has a number called happiness.
Ace is a cat. He is in room 1. happiness of Ace is 5. Bob is a cat. He is in room 1. happiness of Bob is 6. Doc is a cat. He is in room 1. happiness of Doc is 7. Ike is a cat. He is in room 1. happiness of Ike is 8. Max is a cat. He is in room 1. happiness of Max is 9.
the happiest-cat is a cat that varies.
to decide which cat is the hc:
let X be Ace;
repeat with Q running through cats:
if happiness of Q > happiness of X:
now X is Q;
decide on X.
[It seems that we can’t understand “X” as a variable. And that makes sense. But is there another general way to do things?] [understand “happiest cat” as hc.] [understand “happiest cat” as happiest-cat.]
understand “happiest cat” as ace when ace is happiest-cat. understand “happiest cat” as bob when bob is happiest-cat. understand “happiest cat” as doc when doc is happiest-cat. understand “happiest cat” as ike when ike is happiest-cat. understand “happiest cat” as max when max is happiest-cat.
room 1 is a room.
when play begins: now happiest-cat is the hc;
every turn:
now happiest-cat is the hc;
say “([happiest-cat] is the happiest cat.)”;
report taking happiest-cat:
ignore the standard report taking rule;
say “[happiest-cat] purrs as you pick him up.” instead;
check taking a cat:
if noun is not happiest-cat:
say “He struggles and jumps back to the ground.” instead;
test cats with “take happiest cat”.[/code]
Basically I want a way to define the happiest cat and have the user be able to define a cat as such and not just by their name. Of course, in this example, it takes less typing to say Ace or Max or whatever. But I am sensing I’m missing something about how to use definitions. In particular, the “understand X as…” and the happiest-cat/hc definitions appear to be much more awkward in my code than I need to be. I’d like to use this for priorities for disambiguation, e.g. so you can remember your favorite or something.
What do I need to fix so my code flows better/makes more sense?