{"id":126,"date":"2026-03-13T15:44:45","date_gmt":"2026-03-13T15:44:45","guid":{"rendered":"https:\/\/theroyalscode.com\/students\/l_rankins\/?p=126"},"modified":"2026-03-13T15:44:45","modified_gmt":"2026-03-13T15:44:45","slug":"chat-21-path-maddness","status":"publish","type":"post","link":"https:\/\/theroyalscode.com\/students\/l_rankins\/2026\/03\/13\/chat-21-path-maddness\/","title":{"rendered":"CHAT 21: PATH MADDNESS"},"content":{"rendered":"\n<p><strong>Today I made a pathfinding thingamajig<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import time\n\nmaze = &#91;\n    &#91;\"#\", \"O\", \"#\", \"#\", \"#\", \"#\", \"#\", \"#\", \"#\"],\n    &#91;\"#\", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \"#\"],\n    &#91;\"#\", \" \", \"#\", \"#\", \" \", \"#\", \"#\", \" \", \"#\"],\n    &#91;\"#\", \" \", \"#\", \" \", \" \", \" \", \"#\", \" \", \"#\"],\n    &#91;\"#\", \" \", \"#\", \" \", \"#\", \" \", \"#\", \" \", \"#\"],\n    &#91;\"#\", \" \", \"#\", \" \", \"#\", \" \", \"#\", \" \", \"#\"],\n    &#91;\"#\", \" \", \"#\", \" \", \"#\", \" \", \"#\", \"#\", \"#\"],\n    &#91;\"#\", \" \", \" \", \" \", \" \", \" \", \" \", \" \", \"#\"],\n    &#91;\"#\", \"#\", \"#\", \"#\", \"#\", \"#\", \"#\", \"X\", \"#\"]\n]\n\n\ndef print_maze(maze, stdscr, path=&#91;]):\n    BLUE = curses.color_pair(1)\n    RED = curses.color_pair(2)\n\n    for i, row in enumerate(maze):\n        for j, value in enumerate(row):\n            if (i, j) in path:\n                stdscr.addstr(i, j*2, \"X\", RED)\n            else:\n                stdscr.addstr(i, j*2, value, BLUE)\n\n\ndef find_start(maze, start):\n    for i, row in enumerate(maze):\n        for j, value in enumerate(row):\n            if value == start:\n                return i, j\n\n    return None\n<\/code><\/pre>\n\n\n\n<p><strong>This is the code that assembles the maze and the path finding path.<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>def find_path(maze, stdscr):\n    start = \"O\"\n    end = \"X\"\n    start_pos = find_start(maze, start)\n\n    q = queue.Queue()\n    q.put((start_pos, &#91;start_pos]))\n\n    visited = set()\n\n    while not q.empty():\n        current_pos, path = q.get()\n        row, col = current_pos\n\n        stdscr.clear()\n        print_maze(maze, stdscr, path)\n        time.sleep(0.2)\n        stdscr.refresh()\n\n        if maze&#91;row]&#91;col] == end:\n            return path\n\n        neighbors = find_neighbors(maze, row, col)\n        for neighbor in neighbors:\n            if neighbor in visited:\n                continue\n\n            r, c = neighbor\n            if maze&#91;r]&#91;c] == \"#\":\n                continue\n\n            new_path = path + &#91;neighbor]\n            q.put((neighbor, new_path))\n            visited.add(neighbor)<\/code><\/pre>\n\n\n\n<p><strong>This is the code that makes the pathfinder.<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>def find_neighbors(maze, row, col):\n    neighbors = &#91;]\n\n    if row > 0:  # UP\n        neighbors.append((row - 1, col))\n    if row + 1 &lt; len(maze):  # DOWN\n        neighbors.append((row + 1, col))\n    if col > 0:  # LEFT\n        neighbors.append((row, col - 1))\n    if col + 1 &lt; len(maze&#91;0]):  # RIGHT\n        neighbors.append((row, col + 1))\n\n    return neighbors\n\n\ndef main(stdscr):\n    curses.init_pair(1, curses.COLOR_BLUE, curses.COLOR_BLACK)\n    curses.init_pair(2, curses.COLOR_RED, curses.COLOR_BLACK)\n\n    find_path(maze, stdscr)\n    stdscr.getch()\n\n\nwrapper(main)\n<\/code><\/pre>\n\n\n\n<p><strong>This is the code that makes up the brain for the pathfinder.<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"140\" height=\"181\" src=\"https:\/\/theroyalscode.com\/students\/l_rankins\/wp-content\/uploads\/2026\/03\/Screenshot-2026-03-13-114402.png\" alt=\"\" class=\"wp-image-127\"\/><\/figure>\n\n\n\n<p><strong>an example of what it does.<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Today I made a pathfinding thingamajig This is the code that assembles the maze and the path finding path. This [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[1],"tags":[],"class_list":["post-126","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/theroyalscode.com\/students\/l_rankins\/wp-json\/wp\/v2\/posts\/126","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/theroyalscode.com\/students\/l_rankins\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/theroyalscode.com\/students\/l_rankins\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/theroyalscode.com\/students\/l_rankins\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/theroyalscode.com\/students\/l_rankins\/wp-json\/wp\/v2\/comments?post=126"}],"version-history":[{"count":1,"href":"https:\/\/theroyalscode.com\/students\/l_rankins\/wp-json\/wp\/v2\/posts\/126\/revisions"}],"predecessor-version":[{"id":128,"href":"https:\/\/theroyalscode.com\/students\/l_rankins\/wp-json\/wp\/v2\/posts\/126\/revisions\/128"}],"wp:attachment":[{"href":"https:\/\/theroyalscode.com\/students\/l_rankins\/wp-json\/wp\/v2\/media?parent=126"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/theroyalscode.com\/students\/l_rankins\/wp-json\/wp\/v2\/categories?post=126"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/theroyalscode.com\/students\/l_rankins\/wp-json\/wp\/v2\/tags?post=126"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}