[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

[QUIZ] Story Generator (#96

James Gray

9/29/2006 1:02:00 PM

The three rules of Ruby Quiz:

1. Please do not post any solutions or spoiler discussion for this quiz until
48 hours have passed from the time on this message.

2. Support Ruby Quiz by submitting ideas as often as you can:

http://www.rub...

3. Enjoy!

Suggestion: A [QUIZ] in the subject of emails about the problem helps everyone
on Ruby Talk follow the discussion. Please reply to the original quiz message,
if you can.

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

by Morton Goldberg

[ Editor's Note:

I realize we've done a similar quiz in the past, but read on and give this one a
chance. It has a pretty different spin than Markov Chains.

--JEG2 ]

The Dwemthy's Array RPG example in Why's (Poignant) Guide to Ruby[1] was my
introduction to Ruby metaprogramming. While it's an excellent introduction to
metaprogramming, it's not much of an RPG, so I thought I'd have a go at
improving it. But a funny thing happened when I started coding: the RPG turned
in a story generator. Here are a couple of stories generated by my current
version.

The first story is fairly typical of the shorter ones. The rabbit gets past the
BogusFox only to fall to the Jabberwocky.

A BogusFox emerges from the gloom and cries out,"Hail, Rabbit,
prepare to die!"
"I fear you not, BogusFox!"
Rabbit [25] and BogusFox [50] fight.
Rabbit attacks BogusFox with magick sword.
Fighting lowers BogusFox life force by 9.
BogusFox suffered a minor wound.
BogusFox swings his axe.
Fighting lowers Rabbit life force by 7.
Rabbit was wounded.
Rabbit [18] and BogusFox [41] fight.
Rabbit attacks BogusFox with magick sword.
Fighting lowers BogusFox life force by 43.
BogusFox dies.
Eating magick lettuce adds 7 to Rabbit life force.
A Jabberwocky emerges from the gloom and cries out,"Ah, a tasty Rabbit!"
"I fear you not, Jabberwocky!"
Rabbit [25] and Jabberwocky [100] fight.
Rabbit attacks Jabberwocky with magick sword.
Fighting lowers Jabberwocky life force by 63.
Jabberwocky was seriously wounded but carries on.
Jabberwocky attacks Rabbit with teeth and claws.
Fighting lowers Rabbit life force by 33.
Rabbit dies.
It's over. It's all over.

The second story is an example proving that low probability events do occur. The
rabbit actually wins! And what's truly amazing is that he kills every monster
with a single stroke of his magick sword. Talk about luck!

A BogusFox emerges from the gloom and cries out,"Hail, Rabbit,
prepare to die!"
"I fear you not, BogusFox!"
Rabbit [25] and BogusFox [50] fight.
Rabbit attacks BogusFox with magick sword.
Fighting lowers BogusFox life force by 59.
BogusFox dies.
Eating magick lettuce adds 37 to Rabbit life force.
A Jabberwocky emerges from the gloom and cries out,"Ah, a tasty Rabbit!"
"I fear you not, Jabberwocky!"
Rabbit [62] and Jabberwocky [100] fight.
Rabbit attacks Jabberwocky with magick sword.
Fighting lowers Jabberwocky life force by 155.
Jabberwocky dies.
Eating magick lettuce adds 46 to Rabbit life force.
A DemonAngel emerges from the gloom and cries out,"Rabbit, I will
eat your soul!"
"I fear you not, DemonAngel!"
Rabbit [108] and DemonAngel [540] fight.
Rabbit attacks DemonAngel with magick sword.
Fighting lowers DemonAngel life force by 600.
DemonAngel dies.
Eating magick lettuce adds 20 to Rabbit life force.
A ViciousGreenFungus emerges from the gloom and cries out,"No Rabbit
has ever left my presence alive."
"I fear you not, ViciousGreenFungus!"
Rabbit [128] and ViciousGreenFungus [320] fight.
Rabbit attacks ViciousGreenFungus with magick sword.
Fighting lowers ViciousGreenFungus life force by 390.
ViciousGreenFungus dies.
Eating magick lettuce adds 35 to Rabbit life force.
A Dragon emerges from the gloom and cries out,"A brave Rabbit burns
just as well as a timid one."
"I fear you not, Dragon!"
Rabbit [163] and Dragon [1340] fight.
Rabbit attacks Dragon with magick sword.
Fighting lowers Dragon life force by 1436.
Dragon dies.
Eating magick lettuce adds 44 to Rabbit life force.
It's over. It's all over.

The secret of the rabbit's magick sword will be revealed when my story generated
is posted.

"It's hardly literature," you say. I agree. "It's needs more work," you say.
Again, I agree. But it does tell a story. Don't you root for the rabbit? Don't
you feel just a little sad when he's killed (as he almost always is)? And isn't
it wonderful when, once in a hundred runs or so, he actually kills the dragon
and completes his quest?

Story generators can be a lot of fun. Even addictive. It's fascinating to create
your own world. And they are completely open-ended. You can always find ways to
tweak them, either to improve the readability of the output or to improve the
plot.

In this quiz, I ask you to write your own story generator. You can start with
Dwemthy's Array, as I did, or invent your own characters and plot. The only
requirement is that the generator must produce a different story each time it is
run.

1: http://qa.poignantguide.net/chapter-6.htm...

26 Answers

James Gray

9/29/2006 1:38:00 PM

0

On Sep 29, 2006, at 8:18 AM, Robert Dober wrote:

> On 9/29/06, Ruby Quiz <james@grayproductions.net> wrote:
>>
>> The three rules of Ruby Quiz:
>>
>> <snip>
> The Quiz ittself might be too much work to do for me, but reading
> it was
> already an enourmous pleasure.

I too was worried it was too much effort before I ran it, but Morton
sent me his solution and it's not out-of-line with past quizzes.

We're not going for Pulitzer Prize winning publications here. Keep
it simple and see what you can get with a moderate effort.

Morton gives a great suggestion for where to steal code that will get
you started, but even without that you have a lot of options.
Remember grade school English? A subject, verb, and object is all
you really need.

Think outside the box. If your stories turn out comical, list that
as a feature in the quiz submission message, not a bug. ;)

James Edward Gray II

P.S. For those of you that try this, posting generated stories is
not a spoiler!

Morton Goldberg

9/30/2006 4:16:00 AM

0

On Sep 29, 2006, at 9:18 AM, Robert Dober wrote:

> The Quiz ittself might be too much work to do for me, but reading
> it was
> already an enourmous pleasure.
> What a Funny, Great Idea!

I glad you like the idea. Please give it a try. It doesn't require
complex code, and it is even more fun to code this up than it is to
read the results.

Here is a surefire recipe for success :)

1. To a handful of goofy characters, add a list of silly things for
them to do
2. Season with your favorite cliches -- cliches are a key ingredient
3. Stir in a text editor until a suitably turgid consistency is reached
4. Run in a Ruby interpreter until done

Regards, Morton

Rick DeNatale

9/30/2006 2:08:00 PM

0

On 9/30/06, Morton Goldberg <m_goldberg@ameritech.net> wrote:

> Here is a surefire recipe for success :)
>
> 1. To a handful of goofy characters, add a list of silly things for
> them to do
> 2. Season with your favorite cliches -- cliches are a key ingredient

Anyone else here old enough to remember MadLibs?


--
Rick DeNatale

My blog on Ruby
http://talklikeaduck.denh...

M. Edward (Ed) Borasky

9/30/2006 3:14:00 PM

0

Rick DeNatale wrote:
> On 9/30/06, Morton Goldberg <m_goldberg@ameritech.net> wrote:
>
>> Here is a surefire recipe for success :)
>>
>> 1. To a handful of goofy characters, add a list of silly things for
>> them to do
>> 2. Season with your favorite cliches -- cliches are a key ingredient
>
> Anyone else here old enough to remember MadLibs?
>
>
Roger Price ... of course. Do you remember Droodles?

James Gray

9/30/2006 3:22:00 PM

0

On Sep 30, 2006, at 9:08 AM, Rick DeNatale wrote:

> On 9/30/06, Morton Goldberg <m_goldberg@ameritech.net> wrote:
>
>> Here is a surefire recipe for success :)
>>
>> 1. To a handful of goofy characters, add a list of silly things for
>> them to do
>> 2. Season with your favorite cliches -- cliches are a key ingredient
>
> Anyone else here old enough to remember MadLibs?

Sure:

http://www.rubyquiz.com/q...

James Edward Gray II

James Gray

9/30/2006 3:54:00 PM

0

On Sep 29, 2006, at 11:15 PM, Morton Goldberg wrote:

> It doesn't require complex code, and it is even more fun to code
> this up than it is to read the results.

I agree. I'm at 22 lines of code and I'm already laughing:

James kills Ruby. Ruby falls in love with James. James falls in
love
with James. Ruby slays James! James cries.

Shakespeare would be jealous for sure.

James Edward Gray II

Morton Goldberg

9/30/2006 6:28:00 PM

0

On Sep 30, 2006, at 11:14 AM, M. Edward (Ed) Borasky wrote:

> Roger Price ... of course. Do you remember Droodles?

Sure, this is one my favorites:

+-------------------+
| |
| |
| |
| . . |
| |
| |
| |
+-------------------+

Polar Bear in a Snowstorm

Regards, Morton



MonkeeSage

9/30/2006 8:19:00 PM

0

Mine is based on the 80's movie, Legend. My favorite output so far is:

"The Lord of Darkness undulates Princess Lily as the rain falls."

Oh my! Naughty Lord of Darkness! Heh.

Regards,
Jordan

Jim Menard

10/1/2006 1:47:00 AM

0

On 9/30/06, MonkeeSage <MonkeeSage@gmail.com> wrote:
> Mine is based on the 80's movie, Legend. My favorite output so far is:
>
> "The Lord of Darkness undulates Princess Lily as the rain falls."
>
> Oh my! Naughty Lord of Darkness! Heh.
>
> Regards,
> Jordan

The approach I've taken is to modify my solution to Ruby Quiz #49 (the
Lisp Game) so it plays itself. The output is a random "story" that's
all plot and no characterization.

Jim
--
Jim Menard, jimm@io.com, jim.menard@gmail.com
http://www.io...

Leslie Viljoen

10/1/2006 10:08:00 AM

0

On 9/29/06, James Edward Gray II <james@grayproductions.net> wrote:
> P.S. For those of you that try this, posting generated stories is
> not a spoiler!

In a parallel universe in the land of Atlantis there was a tireless
Botanist named
Goldilocks. Goldilocks lived there with her loyal Armadillo Barbara,
and the two were never apart.

The land of Atlantis was in meyhem because of the repulsive
influence of a evil witch named Argonagas.

Goldilocks and Barbara came up with a daring plan - Barbara would
distract the witch, giving Goldilocks the opportinuty to attack unseen.

They rode bravely into battle and Goldilocks sliced the evil witch in
strips with her portable angle-grinder while Barbara created a
diversion by screaming synonyms!
Goldilocks and Barbara became the heroes of Atlantis and lived happily
ever after.

THE END.