Skip to content

Instantly share code, notes, and snippets.

@codl
Last active February 10, 2019 00:01
Show Gist options
  • Select an option

  • Save codl/8482fe1308b9cb28eaf4eba7e928b3aa to your computer and use it in GitHub Desktop.

Select an option

Save codl/8482fe1308b9cb28eaf4eba7e928b3aa to your computer and use it in GitHub Desktop.
"""
cave.py
this thing will tell you where to go to solve the infamous volcanic cave maze
in kingdom of loathing's "Me and My Nemesis" quest
it only has support for one of the layouts because i keep getting that one
if you need another layout you can either edit this scrips or just use the maps on kolwiki and leave me alone.
i will add support for more layouts as i encounter them
~ ~ ~
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.
In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
For more information, please refer to <http://unlicense.org/>
"""
import copy
LAYOUTS = []
LAYOUTS.append((
"""
o__o_________
____o_o_o__o_
o_o__o_o___o_
_________o___
__o________o_
_o_o_o___o___
____o_xo___o_
__o__________
_____o_o____o
_o____o__oo__
____o________
o_____o_____o
_o_____o__o__
""",
"""
_o__o________
_o_o___o_o__o
____________o
____o___o____
o____o_o_____
__o___o___o_o
__o___x_ooo__
____________o
___o_________
__o__o_______
_o______o__o_
___o_o__o__o_
_____________
""",
"""
__o_____o___o
_____o____o__
___o______o__
oo_____o_____
___oo_o______
o_______o__o_
_____ox_____o
___o_o__o_o__
_oo______o___
o___o__o____o
__o_______o__
____o____o___
__o_________o
""",
"""
______o__o_o_
_____________
_o____o__o___
___o_o_____o_
_o_______o__o
____o________
_o____x______
o___o__o_o___
o__________o_
___o____o____
___o__o_____o
_o________o__
___o_o__o____
""",
"""
_____o_o__o__
o_o__________
____o___o____
__o___o___o_o
________o_o__
_______o_____
o__o__x______
_o____o____o_
____o_o_o_o__
___________o_
o__o_o_o_o___
__o____o_____
o___o_o__o_o_
"""
))
STATES = list(map(lambda x: list(map(lambda y: list(y), x.strip().split())), (
LAYOUTS[0]
)))
RED = "\033[31;1;40m"
CYAN = "\033[36;1;40m"
CLEAR = "\033[0m"
# sanity checks
try:
# five map states
assert len(STATES) == 5
for state in STATES:
# 13 x 13 map
assert len(state) == 13
assert all(len(line) == 13 for line in state)
# middle is the goal
assert state[6][6] == "x"
except AssertionError as e:
print("your map all wack")
exit(1)
# key is (z, y, x), value is its parent
known = {
(4, 12, 6): None
}
# (z, y, x)
to_see = [(4, 12, 6)]
def step():
z, y, x = to_see.pop(0)
zz = (z+1)%5
for xx in range(max(0, x-1), min(13, x+2)):
for yy in range(max(0, y-1), min(13, y+2)):
if xx == x and yy == y:
continue
if(zz, yy, xx) in known:
continue
known[(zz, yy, xx)] = (z, y, x)
if STATES[zz][yy][xx] == "x":
steps = [(zz, yy, xx)]
while (4, 12, 6) not in steps:
steps.insert(0, known[steps[0]])
return steps;
elif STATES[zz][yy][xx] == "o":
to_see.append((zz, yy, xx))
# else we have lava, do nothing
return None
steps = None
while not steps:
steps = step()
print("damn bich u bout to do it in", len(steps), "steps")
for i in range(len(steps) - 1):
input("push button when u ready for step %s" % (i+1,))
print("its step", i+1)
z, y, x = steps[i]
zz, yy, xx = steps[i+1]
mapp = copy.deepcopy(STATES[zz])
mapp[y][x] = RED + "o" + CLEAR
mapp[yy][xx] = CYAN + "!" + CLEAR
print("\n".join(map(lambda x: "".join(x), mapp)))
print("congratulations")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment