diff --git a/index.html b/index.html index c83ce2a..525ed3c 100644 --- a/index.html +++ b/index.html @@ -54,7 +54,7 @@
- +
@@ -1959,7 +1959,7 @@ W, H = 15, 7 offset = P(curses.COLS//2 - W//2, curses.LINES//2 - H//2) while True: screen.erase() - curses.textpad.rectangle(screen, offset.y-1, offset.x-1, offset.y+H, offset.x+W) + curses.textpad.rectangle(screen, offset.y-1, offset.x-1, offset.y+H, offset.x+W) for id_, p in state.items(): screen.addstr(offset.y + (p.y - state['*'].y + H//2) % H, offset.x + (p.x - state['*'].x + W//2) % W, str(id_)) @@ -2935,7 +2935,7 @@ $ deactivate # Deactivates the activ diff --git a/parse.js b/parse.js index f8c54c0..b78ba3a 100755 --- a/parse.js +++ b/parse.js @@ -124,14 +124,14 @@ const MATCH_EXAMPLE = const COROUTINES = 'import asyncio, collections, curses, curses.textpad, enum, random, time\n' + '\n' + - 'P = collections.namedtuple(\'P\', \'x y\') # Position\n' + - 'D = enum.Enum(\'D\', \'n e s w\') # Direction\n' + - 'W, H = 15, 7 # Width, Height\n' + + 'P = collections.namedtuple(\'P\', \'x y\') # Position\n' + + 'D = enum.Enum(\'D\', \'n e s w\') # Direction\n' + + 'W, H = 15, 7 # Width, Height\n' + '\n' + 'def main(screen):\n' + - ' curses.curs_set(0) # Makes cursor invisible.\n' + - ' screen.nodelay(True) # Makes getch() non-blocking.\n' + - ' asyncio.run(main_coroutine(screen)) # Starts running asyncio code.\n' + + ' curses.curs_set(0) # Makes cursor invisible.\n' + + ' screen.nodelay(True) # Makes getch() non-blocking.\n' + + ' asyncio.run(main_coroutine(screen)) # Starts running asyncio code.\n' + '\n' + 'async def main_coroutine(screen):\n' + ' moves = asyncio.Queue()\n' + @@ -150,18 +150,15 @@ const COROUTINES = 'async def human_controller(screen, moves):\n' + ' while True:\n' + ' key_mappings = {258: D.s, 259: D.n, 260: D.w, 261: D.e}\n' + - ' ch = screen.getch()\n' + - ' if d := key_mappings.get(ch):\n' + + ' if d := key_mappings.get(screen.getch()):\n' + ' moves.put_nowait((\'*\', d))\n' + ' await asyncio.sleep(0.005)\n' + '\n' + 'async def model(moves, state):\n' + ' while state[\'*\'] not in (state[id_] for id_ in range(10)):\n' + ' id_, d = await moves.get()\n' + - ' x, y = state[id_]\n' + ' deltas = {D.n: P(0, -1), D.e: P(1, 0), D.s: P(0, 1), D.w: P(-1, 0)}\n' + - ' dx, dy = deltas[d]\n' + - ' state[id_] = P((x + dx) % W, (y + dy) % H)\n' + + ' state[id_] = P((state[id_].x + deltas[d].x) % W, (state[id_].y + deltas[d].y) % H)\n' + '\n' + 'async def view(state, screen):\n' + ' offset = P(curses.COLS//2 - W//2, curses.LINES//2 - H//2)\n' + @@ -169,18 +166,13 @@ const COROUTINES = ' screen.erase()\n' + ' curses.textpad.rectangle(screen, offset.y-1, offset.x-1, offset.y+H, offset.x+W)\n' + ' for id_, p in state.items():\n' + - ' screen.addstr(\n' + - ' offset.y + (p.y - state[\'*\'].y + H//2) % H,\n' + - ' offset.x + (p.x - state[\'*\'].x + W//2) % W,\n' + - ' str(id_)\n' + - ' )\n' + + ' screen.addstr(offset.y + (p.y - state[\'*\'].y + H//2) % H,\n' + + ' offset.x + (p.x - state[\'*\'].x + W//2) % W, str(id_))\n' + ' screen.refresh()\n' + ' await asyncio.sleep(0.005)\n' + '\n' + 'if __name__ == \'__main__\':\n' + - ' start_time = time.perf_counter()\n' + - ' curses.wrapper(main)\n' + - ' print(f\'You survived {time.perf_counter() - start_time:.2f} seconds.\')\n'; + ' curses.wrapper(main)\n'; const CURSES = '# $ pip3 install windows-curses\n' + @@ -829,7 +821,7 @@ function fixHighlights() { $(`code:contains(\'s\')`).html(STRUCT_FORMAT); $(`code:contains(match :)`).html(MATCH); $(`code:contains(>>> match Path)`).html(MATCH_EXAMPLE); - //$(`code:contains(import asyncio, collections, curses, curses.textpad, enum, random)`).html(COROUTINES); + $(`code:contains(import asyncio, collections, curses, curses.textpad, enum, random)`).html(COROUTINES); $(`code:contains(import curses, os)`).html(CURSES); $(`code:contains(pip3 install tqdm)`).html(PROGRESS_BAR); $(`code:contains(>>> logging.basicConfig()`).html(LOGGING_EXAMPLE);