|
Laurelhach Newbie
Joined: 25 Feb 2002 Posts: 6 Location: United Kingdom
|
Posted: Tue Mar 05, 2002 6:37 pm
Help with a puzzle |
I'm trying to create an automated solution for a puzzle, and would appreciate some help.
The puzzle involves putting different coloured rocks (there are 8 types) onto a fire, and then lighting it. If the rocks have been added in the correct order (4 at a time), the puzzle is solved.
Available rock colours are: red, blue, yellow, white, orange, green, black and purple
Here's some MUD output to demonstrate how it works:
- add red
You add the red coloured rock to the fire. Once you feel ready, you may light
the fire.
- add red
You add the red coloured rock to the fire. Once you feel ready, you may light
the fire.
- add red
You add the red coloured rock to the fire. Once you feel ready, you may light
the fire.
- add red
You add the red coloured rock to the fire. Once you feel ready, you may light
the fire.
- light fire
A bright red flame rises from the rocks.
The flames fizzle out with a shallow green glow.
Each time 4 rocks have been added, and the fire lit - a two line reaction will be seen. The first line represents whether any of the rocks in the sequence are correct, and the second line indicates whether this attempt was better than the last sequence tried. I shall call them reponse 1 and 2.
Response 1 can be any of the following:
You find that the rocks fail to give off any light.
(This means that the puzzle has not reset)
The rocks in the fireplace fail to catch any distinctive light.
(This means that none of the rocks which were added, are in the correct place in
the sequnce)
A bright red flame rises from the rocks.
(This means that one of the rocks added is in the correct place when
compared with the win the sequence)
A combination of red, and yellow flames rise from the rocks.
(This means that two of the rocks added are in the correct places when
compared with the win sequence)
A combination of red, yellow and blue flames rise from the rocks.
(This means that three of the rocks added are in the correct places when
compared with the win sequence)
Response 2 can be any of the following (and can generally be ignored):
The Puzzle has not reset.
The flames fizzle out with a shallow green glow.
The flames fizzle out, the remains glowing green, orange and purple.
Success results in the following:
The fire flares up suddenly as the perfect combination of rocks has been
reached. A great orange flame lurches out from the fire and engulfs the room,
whirling winds whipping up the frenzy about you. Then, from the centre of the
fireplace, a golden phoenix rises from the flames.
I'll give an example of how I last solved the puzzle where the win sequence was Red, Green, White, Blue:
Rocks Added & Response
======================
Red Red Red Red - A bright red flame rises from the rocks.
Blue Blue Blue Blue - A bright red flame rises from the rocks.
Yellow Yellow Yellow Yellow - The rocks in the fireplace fail to catch any distinctive light.
White White White White - A bright red flame rises from the rocks.
Orange Orange Orange Orange - The rocks in the fireplace fail to catch any distinctive light.
Green Green Green Green - A bright red flame rises from the rocks.
Black Black Black Black - The rocks in the fireplace fail to catch any distinctive light.
Purple Purple Purple Purple - The rocks in the fireplace fail to catch any distinctive light.
Red Red Blue Blue - A combination of red, and yellow flames rise from the rocks.
Blue Blue Red Red - The rocks in the fireplace fail to catch any distinctive light.
Red Blue Red Blue - A combination of red, and yellow flames rise from the rocks.
Blue Red Blue Red - The rocks in the fireplace fail to catch any distinctive light.
Red Green Purple Blue - A combination of red, yellow and blue flames rise from the rocks.
Red Green White Blue - Success!
I've been trying to automate this on my own, but haven't been able to come up with a solution which works - and would really appreciate some help.
Laurelhach |
|
|
|
Kjata GURU
Joined: 10 Oct 2000 Posts: 4379 Location: USA
|
Posted: Tue Mar 05, 2002 8:25 pm |
Maybe someone can come up with a better solution, but the way I'm thinking involves first finding out what colors are in the final solution, and then trying each of the colors in such a way that we find out which colors goes in what position. Finding out which colors are in the solution, will take as much as 8 combinations. Then, finding out which color goes into which position will take as much as 24 combinations. So, the complete solution should take no more than 32 combinations.
I'll write this and post it in a few hours, since right now I can't do it, plus I don't have zMUD with me now.
Kjata |
|
|
|
Kjata GURU
Joined: 10 Oct 2000 Posts: 4379 Location: USA
|
Posted: Wed Mar 06, 2002 2:10 am |
Ok, try this:
#VAR colors {red|blue|yellow|white|orange|green|black|purple|end}
#ALIAS solverocks {#VAR part 1;#VAR dummycolor "";#VAR rocks "";#VAR solution {""|""|""|""};#VAR color red;#T+ rocks;findcolors}
#ALIAS findcolors {#IF (@color = "end") {#VAR part 2;#VAR color %item(@rocks, 1);#DELNITEM rocks 1;#VAR pos 1;findsolution} {#4 add @color;light fire}}
#ALIAS findsolution {#IF (@pos > 4) {#IF (%item(@rocks, 1) = "") {#T- rocks;#FORALL @solution {add %i};light fire} {#VAR color %item(@rocks, 1);#DELNITEM rocks 1;#VAR pos 1;findsolution}} {#IF (%item(@solution, @pos) <> "") {#ADD pos 1;findsolution} {#REPEAT @pos-1 {add @dummycolor};add @color;#REPEAT 4-@pos {add @dummycolor};light fire}}}
#TRIGGER {A bright red flame rises from the rocks.} {#IF (@part = 2) {#VAR solution %replaceitem(@color, @pos, @solution);#VAR pos 5;findsolution} {#VAR rocks {%additem(@color, @rocks)};#IF (%numitems(@rocks) = 4) {#IF (!@dummycolor) {#VAR dummycolor %item(@colors, %ismember(@color, @colors) + 1)};#VAR color "end"} {#VAR color %item(@colors, %ismember(@color, @colors) + 1)};findcolors}} "rocks"
#TRIGGER {A combination of red, and yellow flames rise from the rocks.} {#VAR rocks {%additem(@color, @rocks)};#VAR rocks {%additem(@color, @rocks)};#IF (%numitems(@rocks) = 4) {#IF (!@dummycolor) {#VAR dummycolor %item(@colors, %ismember(@color, @colors) + 1)};#VAR color "end"} {#VAR color %item(@colors, %ismember(@color, @colors) + 1)};findcolors} "rocks"
#TRIGGER {A combination of red, yellow and blue flames rise from the rocks.} {#VAR rocks {%additem(@color, @rocks)};#VAR rocks {%additem(@color, @rocks)};#VAR rocks {%additem(@color, @rocks)};#IF (%numitems(@rocks) = 4) {#IF (!@dummycolor) {#VAR dummycolor %item(@colors, %ismember(@color, @colors) + 1)};#VAR color "end"} {#VAR color %item(@colors, %ismember(@color, @colors) + 1)};findcolors} "rocks"
#TRIGGER {The rocks in the fireplace fail to catch any distinctive light.} {#IF (@part = 2) {#ADD pos 1;findsolution} {#IF (!@dummycolor) {#VAR dummycolor @color};#VAR color %item(@colors, %ismember(@color, @colors) + 1);findcolors}} "rocks"
#TRIGGER {The fire flares up suddenly as the perfect combination of rocks} {#T- rocks;#ABORT 1} "rocks"
I tested it and it seems to work fine. There is an optimization that could be done that I didn't do here. It consists in checking to see if the current color that we want to know the position in the sequence is the last color to check (ie. we know the position of the other three colors). If this is the case, then we can put the color in the correct position without having to send the combination of the three dummy colors plus the correct color in the remaining position. I did not put it in since this will only make it do one combination less, but it shouldn't be hard to do it (just check to see if there is only one item with value "" in the solution list.)
Kjata |
|
|
|
Laurelhach Newbie
Joined: 25 Feb 2002 Posts: 6 Location: United Kingdom
|
Posted: Wed Mar 06, 2002 6:04 am |
Thanks for all you help so far!
After trying to understand the script, I gave it a go. It worked up until a point:
It seems that once you have discovered the colours and go to part 2 - adding one discovered colour and three dummies - that the following description is generated if the discovered colour is not in it's correct position:
The flames fizzle out with a shallow green glow.
Because none of the triggers kick in, processing stops. I've tried to add a variable to act as a flag which is changed each time the fire is lit, and each time one of the other triggers kicks in (in which case it gets cleared). And created another trigger based on the line given, which attempts to continue the process.
However, I've not been able to get it to work. I'm not sure I have fully understood your script completely yet - so would appreciate any additional help.
Thanks
Laurelhach |
|
|
|
Laurelhach Newbie
Joined: 25 Feb 2002 Posts: 6 Location: United Kingdom
|
Posted: Wed Mar 06, 2002 11:52 am |
After a bit of Monkeying about it's all working!
Thanks Kjata for all your help. I've learned a great deal from this exercise - things always seem easier to understand when you have good help on hand.
Again thanks!
Laurelhach |
|
|
|
Kjata GURU
Joined: 10 Oct 2000 Posts: 4379 Location: USA
|
Posted: Wed Mar 06, 2002 1:23 pm |
I just found out an error that will make the script not work when more than one of the same color is present in the solution. Change the part in the second trigger that says:
#VAR rocks {%additem(@color, @color, @rocks)}
to:
#VAR rocks {%additem(@color, @rocks)};#VAR rocks {%additem(@color, @rocks)}
and the part in the third trigger that says:
#VAR rocks {%additem(@color, @color, @color, @rocks)}
to:
#VAR rocks {%additem(@color, @rocks)};#VAR rocks {%additem(@color, @rocks)};#VAR rocks {%additem(@color, @rocks)}
I've also edited the script above to reflect these changes.
Kjata |
|
|
|
Laurelhach Newbie
Joined: 25 Feb 2002 Posts: 6 Location: United Kingdom
|
Posted: Wed Mar 06, 2002 5:13 pm |
You pre-empted my post!
It's all working great now. Thanks again.
Keep up the good work!
Laurelhach |
|
|
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|