Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ MUSHclient ➜ Python ➜ reversing speedwalk strings

reversing speedwalk strings

It is now over 60 days since the last post. This thread is closed.     Refresh page


Posted by Arthur Dent   (6 posts)  Bio
Date Wed 26 May 2004 02:38 PM (UTC)
Message
I wrote this little python function to reverse speedwalk strings of the form:

4we3(sw)2(up)3e(in)(down)(out)(ne)

It handles e,w,s,n,ne,se,nw,sw,up,down,in and out. It doesn't handle other nonstandard directions. It's not the most efficient code, but it works for me.


import string

def reverseSpeedWalkStr(str):
    str=str.lower()

    #remove whitespace
    strippedstr=''
    for eachchar in str:
        if eachchar != " ":
            strippedstr=strippedstr+eachchar

    #add spaces between commands
    spacedstr=strippedstr.replace("(sw)","(SW) ")
    spacedstr=spacedstr.replace("(se)","(SE) ")
    spacedstr=spacedstr.replace("(nw)","(NW) ")
    spacedstr=spacedstr.replace("(ne)","(NE) ")
    spacedstr=spacedstr.replace("(up)","(UP) ")
    spacedstr=spacedstr.replace("(down)","(DOWN) ")
    spacedstr=spacedstr.replace("(in)","(OUT) ")
    spacedstr=spacedstr.replace("w","W ")
    spcadedstr=spacedstr.replace("e","E ")
    spacedstr=spacedstr.replace("s","S ")
    spacedstr=spacedstr.replace("n","N ")
     
    #reverse order of commands 
    strlist=spacedstr.split()
    strlist.reverse()
    reversedstr=string.join(strlist)+' '

    #swap direction
    swappedstr=reversedstr.replace("(NE) ","(SW)")
    swappedstr=swappedstr.replace("(NW) ","(SE)")
    swappedstr=swappedstr.replace("(SE) ","(NW)")
    swappedstr=swappedstr.replace("(SW) ","(NE)")
    swappedstr=swappedstr.replace("(DOWN) ","(UP)")
    swappedstr=swappedstr.replace("(UP) ","(DOWN)")
    swappedstr=swappedstr.replace("(OUT) ","(IN)")
    swappedstr=swappedstr.replace("W ","e")
    swappedstr=swappedstr.replace("E ","w")
    swappedstr=swappedstr.replace("S ","n")
    swappedstr=swappedstr.replace("N ","s")

    swappedstr=swappedstr.lower()
    return(swappedstr)
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #1 on Wed 26 May 2004 09:53 PM (UTC)
Message
See ReverseSpeedwalk.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


11,837 views.

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.