summaryrefslogtreecommitdiffstats
path: root/crawlrc
diff options
context:
space:
mode:
authorjluehrs2 <jluehrs2@uiuc.edu>2008-10-29 20:31:10 -0500
committerjluehrs2 <jluehrs2@uiuc.edu>2008-10-29 20:31:10 -0500
commit879fcaadbcbe3913a7e7fe8a96b71de703305b7c (patch)
treef49db433e8330bb7f7fd40fcd06e279c3431c8e5 /crawlrc
parent87e59a3652423505eb5af1935592f423a0276040 (diff)
downloadconf-879fcaadbcbe3913a7e7fe8a96b71de703305b7c.tar.gz
conf-879fcaadbcbe3913a7e7fe8a96b71de703305b7c.zip
crawlrc lua examples/tests
Diffstat (limited to 'crawlrc')
-rw-r--r--crawlrc133
1 files changed, 133 insertions, 0 deletions
diff --git a/crawlrc b/crawlrc
index 12dcf67..7841cfa 100644
--- a/crawlrc
+++ b/crawlrc
@@ -295,3 +295,136 @@ mon_glyph = curse skull : lightmagenta
#use_fake_cursor = false
# }}}
# }}}
+fsim_mons = Dispater
+fsim_xl = 27
+# greedy_autoexplore should stop not only for ego/arts, but also for armor that
+# i can wear that i don't currently own any of (normal cloaks are useful if i
+# don't have a cloak yet)
+: function pray_prompt()
+: crawl.formatted_mpr("Really pray?", "prompt")
+: local res = crawl.getch()
+: if string.lower(string.char(res)) == "y" then
+: crawl.sendkeys("p")
+: end
+: end
+< do
+-- globals {{{
+local x, y = 1, 1
+local map = { [1] = { [1] = 'f' } }
+local last_move = ''
+local turns = 0
+local seen_a_monster = false
+-- }}}
+function vi_to_delta(key) -- {{{
+ local v2d = {
+ y = {-1, 1}, k = {0, 1}, u = {1, 1},
+ h = {-1, 0}, l = {1, 0},
+ b = {-1, -1}, j = {0, -1}, n = {1, -1},
+ }
+ return v2d[key]
+end -- }}}
+function delta_to_vi(dx, dy) -- {{{
+ local d2v = {
+ [-1] = { [-1] = 'b', [0] = 'h', [1] = 'y'},
+ [0] = { [-1] = 'j', [1] = 'k'},
+ [1] = { [-1] = 'n', [0] = 'l', [1] = 'u'},
+ }
+ return d2v[dx][dy]
+end -- }}}
+function reset() -- {{{
+ x, y = 1, 1
+ map = { [1] = { [1] = 'f' } }
+ last_move = ''
+ crawl.mpr("Reset!")
+end -- }}}
+function dijkstra() -- {{{
+ local stack = {}
+ local dist = {}
+ table.insert(stack, {pos = {x, y}, dist = 0, path = ''})
+ dist[x] = {[y] = 0}
+ while #stack ~= 0 do
+ table.sort(stack, function(a, b) return a.dist > b.dist end)
+ local node = table.remove(stack)
+ for _, deltas in pairs({{1,1},{1,0},{1,-1},{0,1},{0,-1},{-1,1},{-1,0},{-1,-1}}) do
+ local dx, dy = unpack(deltas)
+ local nx, ny = node.pos[1] + dx, node.pos[2] + dy
+ local next_path = node.path .. delta_to_vi(dx, dy)
+ local next_dist = node.dist + 1
+ map[nx] = map[nx] or {}
+ dist[nx] = dist[nx] or {}
+ if map[nx][ny] == nil then
+ return next_path:sub(1, 1)
+ elseif map[nx][ny] == 'f' and
+ (dist[nx][ny] == nil or dist[nx][ny] > next_dist) then
+ table.insert(stack, {pos = {nx, ny},
+ dist = next_dist,
+ path = next_path})
+ dist[nx][ny] = next_dist
+ end
+ end
+ end
+end -- }}}
+function update_turn() -- {{{
+ dt = you.turns() - turns
+ turns = you.turns()
+ local delta = vi_to_delta(last_move)
+ if delta == nil then return end
+ local dx, dy = unpack(delta)
+ if dt == 0 then
+ map[x + dx] = map[x + dx] or {}
+ map[x + dx][y + dy] = 'w'
+ else
+ for i = 1, dt do
+ map[x + i * dx] = map[x + i * dx] or {}
+ map[x + i * dx][y + i * dy] = 'f'
+ end
+ x = x + dx * dt
+ y = y + dy * dt
+ end
+end -- }}}
+function minotaur_in_view() -- {{{
+ return seen_a_monster
+end -- }}}
+function step_solve_lab(coro) -- {{{
+ update_turn()
+ last_move = dijkstra()
+ if last_move == nil then crawl.mpr("nil move!"); return end
+ --crawl.mpr("sending " .. last_move)
+ crawl.sendkeys(last_move)
+ if coro then return not minotaur_in_view() else return end
+end -- }}}
+function solve_lab() -- {{{
+ crawl.mpr("Solving lab...")
+ while true do coroutine.yield(step_solve_lab(true)) end
+ crawl.mpr("Minotaur!")
+end -- }}}
+local old_ch_mon_is_safe = ch_mon_is_safe
+function ch_mon_is_safe(...) -- {{{
+ seen_a_monster = true
+ return old_ch_mon_is_safe(...)
+end -- }}}
+end >
+< function test1()
+ crawl.sendkeys("j")
+ coroutine.yield(true)
+ crawl.sendkeys("j")
+ coroutine.yield(false)
+ end >
+< function test2()
+ crawl.sendkeys("j")
+ coroutine.yield(true)
+ crawl.sendkeys("j")
+ coroutine.yield(true)
+ crawl.sendkeys("j")
+ coroutine.yield(false)
+ end >
+< function test3()
+ crawl.sendkeys("j")
+ coroutine.yield(true)
+ crawl.sendkeys("j")
+ coroutine.yield(true)
+ crawl.sendkeys("j")
+ coroutine.yield(true)
+ crawl.sendkeys("j")
+ coroutine.yield(false)
+ end >