Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » zMUD General Discussion
Akira
Newbie


Joined: 15 Dec 2002
Posts: 8
Location: USA

PostPosted: Sun Dec 15, 2002 4:44 pm   

variables to weave spells
 
Hello all
I have a question about making a script for a Mud I play on to weave all possible weaves. Ok, the way this works is in the Mud I play (Dragons gate) a magic user has to figure out spell weaves to gain a spell. There are two types of runes, elemental runes and shape runes. The command to weave a spell is weave elemental rune shape rune and it might look something like this Weave cold touch with cold as the elemental rune and touch as the shape rune making the spell chill touch. Some spells will have more then one elemental rune, such as the spell Weave air translocation aura. This weave creates the Vortex of air spell.

My question is, is there a way to make a script using variables to check every possible weave. If so how? Ok, Let me give you a little more information to start with. There are 22 elemental runes and 25 shape runes. Each spell will have one shape rune and as many as three elemental runes (maybe even more). If you weave a spell correctly, you will get the message: You have learned this combination as # 1.

There is no difference if you already know the weave or not except for the number of the weave. I have 20 spells already learned so a new spell would get the message: You have learned this combination as #21.
I believe there is a limit to how many spells you can learn, so what I would like is a script to weave spells until I get the message You have learned this combination as #21. Capture the weave combination then use the command forget 21 to forget that weave and to keep going until I have gone threw every combination.
Anyone that wants to help me tackle this, your help is greatly appreciated.
Reply with quote
LightBulb
MASTER


Joined: 28 Nov 2000
Posts: 4817
Location: USA

PostPosted: Sun Dec 15, 2002 5:39 pm   
 
  • Make a list variable containing all the elemental runes (@elements).

  • Make a list variable containing all the shape runes (@shapes).

  • Make a numeric variable to track which elemental variable you are using, start at 1 (@element1).

  • Make a numeric variable to track which shape variable you are using, start at 0 (@shape1).

  • Make a variable (@weave21) to stop everything whenever a new weave has been discovered. Set to 0.

  • Make an alias which will add 1 to @shape1. If @shape1 is more than the number of shapes (use %numitems(@shapes)) set @shape1 to 1 and add 1 to @element1. If @element1 is more than the number of elements end (by setting @weave21 to 2). Otherwise, weave %item(@elements, @element1) %item(@shapes, @shape1).

  • Make a trigger to set @weave21 to 1 whenever a new weave is discovered.

  • Use an alarm to do the alias every few seconds if @weave21 is 0 (this should avoid looping errors)

  • This will stop whenever a new weave has been found, so that you can write down the combination of runes and spellname and then forget it. Set @weave21 to 0 when you are ready to continue. It will also stop when you've exhausted all the possibilities for one elemental rune.

  • When you've finished all the possibilities (@weave21 = 2), add another variable (@element2) starting at 1, and reset @element1 to 1 and @shape1 to 0. Then rewrite the alias to do two elemental runes every time. The new alias should add to @shape1 every time, it should add to @element1 whenever @shape1 reaches the limit, and it should add to @element2 whenever @element1 reaches the limit.

  • After you've exhausted all the possible weaves with two elementals, add another variable (@element3) and redo the alias to use 3 elements every time.

  • You can pause execution at any time by setting @weave21 to any non-zero value. I'd recommend using 3, that way you'd know if @weave21 is 1 you found a new weave, if @weave21 is 2 you've reached the end of the current number of elements, and if @weave21 is 3 you stopped it.


  • Be prepared to spend a lot of time on this. The math is pretty simple, 22 elementals and 25 shapes means:
    elemental shape = 22*25 = 5500
    elemental elemental shape = 22*22*25 = 121,000
    elemental elemental elemental shape = 22*22*22*25 = 2,662,000
    Total = 5500 + 121,000 + 2,662,000 = 2,788,500

    LightBulb
    Senior Member
    Reply with quote
    Charbal
    GURU


    Joined: 15 Jun 2001
    Posts: 654
    Location: USA

    PostPosted: Wed Dec 18, 2002 6:35 am   
     
    The math may not be so simple as Lightbulb makes it. His method assumes that it is possible to have the same spell element in multiple places and that the correct order is necessary (ie, must be element1, element2, element3; the spell wouldn't work if you did element3, element2, element1).

    If a spell will only have a given element once and they are order independent, we actually have:

    C(22,3)*25+C(22,2)*25+C(22,1)*25=22!/(19!*3!)*25+22!/(20!*2!)*25+22*25
    = 44825 combinations.

    If this is the case, I could write up the script to iterate through these combinations fairly easily.

    Another possibility is that they are order independent but the same element can occur multiple times. This would use combinations with replacement and the number of things to check would be greater: 57475.

    These numbers are probably closer to something that is feasible for testing.



     - Charbal
    Reply with quote
    LightBulb
    MASTER


    Joined: 28 Nov 2000
    Posts: 4817
    Location: USA

    PostPosted: Wed Dec 18, 2002 5:01 pm   
     
    Yes, I assumed that elements could repeat and that the order mattered. More important, I made a mistake in my first multiplication (it should be 550 instead of 5500), and then used that figure for the later calculations, so the entire sum is probably off by a factor of 10.

    LightBulb
    Senior Member
    Reply with quote
    Akira
    Newbie


    Joined: 15 Dec 2002
    Posts: 8
    Location: USA

    PostPosted: Thu Dec 19, 2002 8:33 am   
     
    Thanks for the replys guys but I think I should have said before that I have very, and I repeat VERY little exp with making Zmud scripts. I made 3 variables one called @shape that has all the shape runes in it and two called @el1 and @el2. The two @el1 and @el2 variables are exactly the same. both with all the elemental runes. It's at this point where I'm totally stuck. I have no idea how I would be able to weave @el1 @el2 @shape over and over again making the value change each time and then capture the correct weaves.

    Could someone write something out that would do this so I could edit it to work for me? I have no idea what things like alarms or %numitems are and I have the feeling if I did I probably wouldn't be asking for help.heh.
    Reply with quote
    Charbal
    GURU


    Joined: 15 Jun 2001
    Posts: 654
    Location: USA

    PostPosted: Thu Dec 19, 2002 8:58 am   
     
    Can you clarify some things for us so we know the best way to implement this?

    First of all, is the order of the elementals important in casting the spell?
    Is Weave air translocation aura the same as Weave translocation air aura?

    Could a single elemental occur twice in a spell?
    Something like Weave air air translocation?



     - Charbal
    Reply with quote
    LightBulb
    MASTER


    Joined: 28 Nov 2000
    Posts: 4817
    Location: USA

    PostPosted: Thu Dec 19, 2002 3:50 pm   
     
    I gave a pretty thorough outline, did you look up things like alarms and %numitems?

    Make a list variable containing all the elemental runes (@elements).
    You've done this -- @el1
    Correct form would be
    #VAR el1 {cold|air|translocation}
    but would include all elemental runes

    Make a list variable containing all the shape runes (@shapes).
    You've done this -- @shape
    Correct form would be similar to the element list

    Make a numeric variable to track which elemental variable you are using, start at 1 (@element1).
    #VAR element1 1

    Make a numeric variable to track which shape variable you are using, start at 0 (@shape1).
    #VAR shape1 0

    Make a variable (@weave21) to stop everything whenever a new weave has been discovered. Set to 0.
    #VAR weave21 0

    Make an alias which will add 1 to @shape1. If @shape1 is more than the number of shapes (use %numitems(@shapes)) set @shape1 to 1 and add 1 to @element1. If @element1 is more than the number of elements end (by setting @weave21 to 2). Otherwise, weave %item(@elements, @element1) %item(@shapes, @shape1).
    #AL weaver1 {#ADD shape1 1;#IF (@shape1 > %numitems(@shape)) {#VAR shape1 1;#ADD element1 1};#IF (@element1 > %numitems(@el1)) {#VAR weave21 2;#BEEP;#SHOW Finished the 'elemental shape' weaves} {weave %item(@el1, @element1) %item(@shape, @shape1)};#NOOP}

    Make a trigger to set @weave21 to 1 whenever a new weave is discovered.
    #TR {You have learned this combination as ~#21} {#VAR weave21 1;#BEEP;#SHOW New spell!}

    Use an alarm to do the alias every few seconds if @weave21 is 0 (this should avoid looping errors)
    #ALA *4 {#IF (@weave21 = 0) {weaver1}} {weaver}
    You can make this happen more often by using a smaller number (*2 would be twice as often as *4). *4 is every 4 seconds, *2 would be every 2 seconds. I was fairly generous with the time (I think) because I don't know how long it takes to do a weave. I added the class parameter (weaver) to provide another method of disabling the alarm.

    This will stop whenever a new weave has been found, so that you can write down the combination of runes and spellname and then forget it. Set @weave21 to 0 when you are ready to continue. It will also stop when you've exhausted all the possibilities for one elemental rune.
    When new combination is found, write it down. Then type in
    forget 21
    #VAR weave21 0


    When you've finished all the possibilities (@weave21 = 2), add another variable (@element2) starting at 1, and reset @element1 to 1 and @shape1 to 0. Then rewrite the alias to do two elemental runes every time. The new alias should add to @shape1 every time, it should add to @element1 whenever @shape1 reaches the limit, and it should add to @element2 whenever @element1 reaches the limit.
    After you've finished all the 'elemental shape' weaves, type in
    #VAR element2 1
    #VAR element1 1
    #VAR shape1 0
    #AL weaver1 {#ADD shape1 1;#IF (@shape1 > %numitems(@shape)) {#VAR shape1 1;#ADD element1 1};#IF (@element1 > %numitems(@el1)) {#VAR element1 1;#ADD element2 1};#IF (@element2 > %numitems(@el1)) {#VAR weave21 2;#BEEP;#SHOW Finished the 'elemental elemental shape' weaves} {weave %item(@el1, @element1) %item(@el1, @element2) %item(@shape, @shape1)};#NOOP}
    #VAR weave21 0


    After you've exhausted all the possible weaves with two elementals, add another variable (@element3) and redo the alias to use 3 elements every time.
    By this point, you should be able to make the needed changes yourself

    You can pause execution at any time by setting @weave21 to any non-zero value. I'd recommend using 3, that way you'd know if @weave21 is 1 you found a new weave, if @weave21 is 2 you've reached the end of the current number of elements, and if @weave21 is 3 you stopped it.
    Pause the routine by typing:
    #VAR weave21 3
    Resume by typing:
    #VAR weave21 0
    You can also stop it by typing:
    #T- weaver
    and you would then restart it by typing:
    #T+ weaver

    LightBulb
    Senior Member
    Reply with quote
    MattLofton
    GURU


    Joined: 23 Dec 2000
    Posts: 4834
    Location: USA

    PostPosted: Thu Dec 19, 2002 11:44 pm   
     
    quote:

    Can you clarify some things for us so we know the best way to implement this?

    First of all, is the order of the elementals important in casting the spell?
    Is Weave air translocation aura the same as Weave translocation air aura?

    Could a single elemental occur twice in a spell?
    Something like Weave air air translocation?



     - Charbal



    Since I play the same mud, here's the 411:

    1)rune location matters, HOLY FIRE SPHERE is not the same as FIRE HOLY SPHERE, and in fact they could very well be two very different spells.

    2)elements can only be used once in a weave, and so FIRE FIRE AURA will either never be a spell or will default to something like FIRE AURA.

    Also, there are only three levels of weaves:

    element shape
    element element shape
    element element element shape


    li'l shmoe of Dragon's Gate MUD
    Reply with quote
    Charbal
    GURU


    Joined: 15 Jun 2001
    Posts: 654
    Location: USA

    PostPosted: Fri Dec 20, 2002 9:34 pm   
     
    Thanks for the clarifications, MattLofton.

    I think this should do it:

    #CLASS WeaveCollector
    #VAR NonTrivial 0
    #VAR Perm %array()
    #VAR ShapeCounter 1
    #VAR ArrIndex 0
    #VAR TempList %null
    #VAR Output %null
    #ALIAS StartPermutations {#VAR Perm %array();#LOOP 1,%1 {#NOOP %arrset(Perm,%i-1,%i)};#VAR ShapeCounter 1;TryWeave}
    #ALIAS NextNonDuplicatePermutation {#VAR ArrIndex %arrhigh(Perm);#NOOP %arrset(Perm,@ArrIndex,%eval(%arrget(Perm,@ArrIndex)+1));#WHILE (%arrget(Perm,@ArrIndex) > %numitems(@Elementals)) {#NOOP %arrset(Perm,@ArrIndex,1);#ADD ArrIndex -1;#IF (@ArrIndex >= 0) {#NOOP %arrset(Perm,@ArrIndex,%eval(%arrget(Perm,@ArrIndex)+1))}};#VAR TempList %null;#LOOP 0,%arrhigh(Perm) {#ADDI TempList %arrget(Perm,%i)};#IF (%numitems(@TempList) < %arrhigh(Perm)+1) {NextNonDuplicatePermutation}}
    #ALIAS TryPermutation {#VAR NonTrivial 0;#LOOP 0,%arrhigh(Perm) {#IF (%arrget(Perm,%i) <> %i + 1) {#VAR NonTrivial 1}};#IF (@NonTrivial = 0) {#SAY Finished testing the indicated number of elementals.} {#VAR ShapeCounter 1;TryWeave}}
    #ALIAS TryWeave {#VAR Output "Weave ";#LOOP 0,%arrhigh(Perm) {#VAR Output %concat(@Output, %item(@Elementals, %arrget(Perm,%i)), " ")};#VAR Output %concat(@Output, %item(@Shapes, @ShapeCounter));#EXEC {@Output}}
    #ALIAS NextWeave {#IF (@ShapeCounter = %numitems(@Shapes)) {NextNonDuplicatePermutation;TryPermutation} {#ADD ShapeCounter 1;TryWeave}}
    #VAR Elementals {air|earth|fire|water|heart}
    #VAR Shapes {tetrahedron|cube|octahedron|dodecahedron|icosahedron}
    #TRIGGER {You try to use the indicated runes but fail.} {NextWeave}
    #TRIGGER {You have learned this combination as #(%d)} {#WINDOW FoundWeaves {@Output};#IF (%1 = 21) {forget 21};NextWeave}
    #CLASS 0



    Modify the Elementals and Shapes variables with the correct values and change the pattern for the failure trigger to whatever it actually should be.

    To start, do startpermutations x where x is the number of elementals to test at once.
    For example, you might start with startpermutations 1 and that will test all possible weaves with one elemental rune. After that's done, you can do startpermutations 2 and startpermutations 3 for the rest.

    When the script discovers a weave (regardless of whether you know it already or not) it puts it into a window named FoundWeaves.

    To pause, #T- WeaveCatcher
    To resume, #T+ WeaveCatcher;NextWeave

    Script theory: The array Perm stores the current elemental permutation as numbers representing members of @Elementals. This array is translated to the elemental runes itself and each shape is tested with it, one at a time. If a weave is found, it is put into the FoundWeaves window. Once all shapes have been tested, the Perm array is incremented to the next permutation and the process continues. Once the Perm array has gone through all possible permutations, the script will stop and tell you.


     - Charbal
    Reply with quote
    Akira
    Newbie


    Joined: 15 Dec 2002
    Posts: 8
    Location: USA

    PostPosted: Sat Dec 21, 2002 4:04 pm   
     
    Hi all back again and thanks for the great help. I tryed both of the examples here by Lightbulb and Charbal and I got the one by Lightbulb to work. There was a few minor problems but I managed to figure out what they were. First was very simple, In the mud I play I use the ` key as the seperator key so I had to go over everything and replace the ; with `. now it runs fine.
    The example written by Charbals looks like it would work much better except I had 2 problems with it and could not seem to figure out how to fix them. First problem was there is no message for a weave that is not a correct weave. This trigger will never fire,#TRIGGER {You try to use the indicated runes but fail.} {NextWeave}, So it dosen't go on to the next round.
    Second problem might be because of the first one not working properly. I tryed the example anyway to see how it would look and figured I could use the, To resume, #T+ WeaveCatcher;NextWeave command, to move on to the next weave but the output was a string of the hole @el1 value all at once. Hope that makes sense if you want to try and figure out what went wrong. The second one looked like it would work alot better with the capture and being able to set how many runes I weave. Just can't figure out how to fix it.

    P.S. the information from Mattlofton was correct, I'd be surpised if he dosen't have one of these already for himself.
    Reply with quote
    Akira
    Newbie


    Joined: 15 Dec 2002
    Posts: 8
    Location: USA

    PostPosted: Sat Dec 21, 2002 6:14 pm   
     
    I wrote this about Charbals example **but the output was a string of the hole @el1 value all at once.** But I figured out what that problem was just can't get it to do next weave now.
    Reply with quote
    Charbal
    GURU


    Joined: 15 Jun 2001
    Posts: 654
    Location: USA

    PostPosted: Sat Dec 21, 2002 7:01 pm   
     
    Okay... didn't know you didn't have a failure message. That makes things slightly more interesting. Is there any message at all that tells you that you are weaving or something?

    Like:
    You start to use the indicated runes...
    You have learned this combination as #21.
    or if you fail:
    You start to use the indicated runes...

    (previous line intentionally left blank :P)

    That would give rise to a multi-state trigger (assuming you are using 6.40)... first state is You start to use the indicated runes... second state is ^(*)$. The second state could check to see if it is the "You have learned..." text or just blank and in either case would go on to the next weave. If you aren't using 6.40, you'd just keep this second disabled until you wanted to use it (either by classes or trigger IDs).

    If you don't have in-progress text, an alarm would work. The problem with this is that it introduces additional delay... if it is set to 4 seconds, the test of each weave will take at least that long. Since there are 243,100 weaves to go through, this is about 11 days, 6 hours, 6 minutes, 40 seconds.

    If you use an alarm, you could use the value of the @NonTrivial variable with a few modifications... if this is not 0, execute the NextWeave alias. And make the startpermutations alias explicitly set it to 1.


     - Charbal
    Reply with quote
    Akira
    Newbie


    Joined: 15 Dec 2002
    Posts: 8
    Location: USA

    PostPosted: Sat Dec 21, 2002 7:14 pm   
     
    there is no message at all for a weave that is not a correst weave. Nothing happends. The only time you get a message is for a correct weave or if you weave a weave wrong like using 2 shapes and one element or not using a shape rune.
    Reply with quote
    Charbal
    GURU


    Joined: 15 Jun 2001
    Posts: 654
    Location: USA

    PostPosted: Sat Dec 21, 2002 7:54 pm   
     
    quote:

    there is no message at all for a weave that is not a correst weave. Nothing happends. The only time you get a message is for a correct weave or if you weave a weave wrong like using 2 shapes and one element or not using a shape rune.



    Okay, then we can use a command with a predictable output. Say score returns a line like "You have scored %d experience points." where %d is some number. Then if you add the command score after each weave is tried (so you'll have #EXEC {@Output};score instead of #EXEC {@Output} in the TryWeave alias) you can use the score line to gauge when you are finished with a weave. So make a trigger:
    #TRIGGER {You have scored %d experience points.} {NextWeave}

    Additionally, you'll have to take the NextWeave reference out of the "You have learned..." trigger so it doesn't go to the next weave twice (once for the learning text, again for the score text).


     - Charbal
    Reply with quote
    MattLofton
    GURU


    Joined: 23 Dec 2000
    Posts: 4834
    Location: USA

    PostPosted: Sun Dec 22, 2002 6:14 am   
     
    quote:

    quote:

    there is no message at all for a weave that is not a correst weave. Nothing happends. The only time you get a message is for a correct weave or if you weave a weave wrong like using 2 shapes and one element or not using a shape rune.



    Okay, then we can use a command with a predictable output. Say score returns a line like "You have scored %d experience points." where %d is some number. Then if you add the command score after each weave is tried (so you'll have #EXEC {@Output};score instead of #EXEC {@Output} in the TryWeave alias) you can use the score line to gauge when you are finished with a weave. So make a trigger:
    #TRIGGER {You have scored %d experience points.} {NextWeave}

    Additionally, you'll have to take the NextWeave reference out of the "You have learned..." trigger so it doesn't go to the next weave twice (once for the learning text, again for the score text).


     - Charbal



    Are you trying to keep this independent of the Echo commands option? If not, just flip that option on so you can see the commands you enter and use a state trigger.

    #trigger {weave *$} {}
    #cond {^>} {blah, blah, blah, invalid weave so try again}
    #cond {Congratulations, you've just won a million gold pieces!} {blah, blah, blah, valid weave}

    This only works with version 6.2x to 6.40+, but 6.40 is a public version so why not upgrade?

    li'l shmoe of Dragon's Gate MUD
    Reply with quote
    Charbal
    GURU


    Joined: 15 Jun 2001
    Posts: 654
    Location: USA

    PostPosted: Sun Dec 22, 2002 8:20 am   
     
    I was staying away from that option because of the other difficulties it creates... I'm assuming your ^> trigger is a prompt trigger of sorts. If there is any lag between you and the server, something like the following might happen:

    > Send a command to the MUD here

    Whoever has arrived from the west.

    >
    Whoever leaves east.

    > Response from command.

    If the response was a weave being learned, then the prompt and the weave response would both trigger the script to go on to the next weave. So the trigger starts to cast two weaves at a time for the forseeable future.

    When a weave is learned, the script puts the current value of @Output in the FoundWeaves window. However, if two weaves are being tested at once and the first is an actual weave, the runes for the second would be put into the FoundWeaves window since it would be the last one to modify @Output. This results in erroneous information being reported.

    Perhaps I'm misunderstanding you... I'm slightly ill at the moment and should likely go to bed. :P


     - Charbal
    Reply with quote
    Display posts from previous:   
    Post new topic   Reply to topic     Home » Forums » zMUD General Discussion All times are GMT
    Page 1 of 1

     
    Jump to:  
    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

    © 2009 Zugg Software. Hosted by Wolfpaw.net