[Home] [Downloads] [Search] [Help/forum]


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Python
. . -> [Subject]  reversing speedwalk strings

reversing speedwalk strings

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


Posted by Arthur Dent   (6 posts)  [Biography] 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)
[Go to top] top

Posted by Nick Gammon   Australia  (22,989 posts)  [Biography] 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
[Go to top] 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.


10,815 views.

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

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

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

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at HostDash]