Created
October 26, 2011 18:35
-
-
Save dbieber/1317314 to your computer and use it in GitHub Desktop.
Zork for Tropo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def getInput(): | |
#return raw_input() | |
return ask("Input", { | |
"choices":"http://hosting.tropo.com/97257/www/grammar/zork_grammar.grxml", | |
"timeout":60 | |
}).value | |
def speak(x): | |
val = x.replace("<br />", " ").replace("<br>", " ") | |
#print val | |
say(val) | |
from cookielib import CookieJar | |
import urllib, urllib2 | |
from urllib2 import urlopen | |
cj = CookieJar() | |
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj)) | |
intro = urlopen("http://thcnet.net/zork/").read() | |
start = intro.rfind("You are in") | |
end = intro.rfind('<form name="prompt"') - 7 | |
speak(intro[start:end]) | |
while(True): | |
x = getInput() | |
d = urllib.urlencode({ | |
"inputPrompt":x | |
}) | |
result = opener.open("http://thcnet.net/zork/index.php", d).read() | |
start = result.rfind(x+"<") + len(x) + 10 | |
end = result.find('<form name="prompt"') - 7 | |
speak(result[start:end]) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version= "1.0"?> | |
<grammar mode="voice" | |
type="application/srgs+xml" | |
root="root_rule" | |
tag-format="semantics/1.0" | |
version="1.0" | |
xml:lang="en-US" | |
xmlns="http://www.w3.org/2001/06/grammar"> | |
<rule id="root_rule" scope="public"> | |
<one-of> | |
<item> zork </item> | |
<item> repent </item> | |
<item> inventory </item> | |
<item> look </item> | |
<item> | |
<item repeat="0-1"> smell </item> | |
<item repeat="0-1"> open </item> | |
<item repeat="0-1"> close </item> | |
<item repeat="0-1"> take </item> | |
<item repeat="0-1"> drop </item> | |
<item repeat="0-1"> look at </item> | |
<item repeat="0-1"> look in </item> | |
<item repeat="0-1"> look under </item> | |
<item repeat="0-1"> examine </item> | |
<item repeat="0-1"> use </item> | |
<item repeat="0-1"> read </item> | |
<item repeat="0-1"> drink </item> | |
<item repeat="0-1"> enter </item> | |
<item repeat="0-1"> count </item> | |
<item repeat="0-1"> what is </item> | |
<item repeat="0-1"> find </item> | |
<item repeat="0-1"> listen </item> | |
<one-of> | |
<item> all </item> | |
<item> everything </item> | |
<item> mailbox </item> | |
<item> hands </item> | |
<item> house </item> | |
<item> teeth </item> | |
<item> me </item> | |
<item> Troll </item> | |
<item> matches </item> | |
<item> window </item> | |
<item> egg </item> | |
<item> leaflet </item> | |
<item> leaves </item> | |
<item> pile of leaves </item> | |
<item> grating </item> | |
<item> tree </item> | |
<item> sword </item> | |
<item> gems </item> | |
<item> door </item> | |
<item> rug </item> | |
<item> oil </item> | |
<item> grue </item> | |
<item> zork </item> | |
<item> zorkmin </item> | |
<item> this </item> | |
</one-of> | |
</item> | |
<item> | |
<item repeat="0-1"> walk </item> | |
<item repeat="0-1"> go </item> | |
<item repeat="0-1"> climb </item> | |
<item repeat="0-1"> look </item> | |
<item repeat="0-1"> jump </item> | |
<one-of> | |
<item> around </item> | |
<item> behind house </item> | |
<item> north </item> | |
<item> south </item> | |
<item> east </item> | |
<item> west </item> | |
<item> north east </item> | |
<item> north west </item> | |
<item> south east </item> | |
<item> south west </item> | |
<item> up </item> | |
<item> upstairs </item> | |
<item> down </item> | |
<item> down into canyon </item> | |
<item> downstairs </item> | |
<item> tree </item> | |
<item> through passage </item> | |
<item> through door </item> | |
</one-of> | |
</item> | |
</one-of> | |
</rule> | |
</grammar> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment