{"id":11329,"date":"2021-06-20T18:22:50","date_gmt":"2021-06-20T09:22:50","guid":{"rendered":"https:\/\/kusakarism.info\/?p=11329"},"modified":"2021-07-28T20:15:37","modified_gmt":"2021-07-28T11:15:37","slug":"maze","status":"publish","type":"post","link":"https:\/\/kusakarism.info\/?p=11329","title":{"rendered":"\u300c\u8ff7\u8def\u300d\u3092\u81ea\u52d5\u751f\u6210\u3059\u308b\u30d7\u30ed\u30b0\u30e9\u30e0\uff0f\u5b66\u7fd2\u7528\u30b3\u30fc\u30c9"},"content":{"rendered":"<h2>\u6700\u7d42\u7684\u306b\u4f5c\u308a\u305f\u3044\u8ff7\u8def\u306f\u3002<\/h2>\n<p><span style=\"font-size: 14pt; color: #ff0000;\"><strong>\u305a\u3063\u3068\u5bb6\u306b\u5f15\u304d\u3053\u3082\u3063\u3066\u3044\u308b\u3068\u30fb\u30fb\u30fb<\/strong><\/span><br \/>\u305f\u307e\u306b\u306f\u5916\u306b\u51fa\u3066\u4f53\u3092\u52d5\u304b\u3057\u305f\u308a\u3057\u305f\u65b9\u304c\u3088\u3044\u306e\u304b\u306a\uff1f<br \/>\u306a\u3093\u3066\u8003\u3048\u305f\u308a\u3059\u308b\u3002<br \/>\u3061\u3087\u3063\u3068\u3057\u305f\u7f6a\u60aa\u611f\u3002<\/p>\n<p>\u3067\u3082\u3001\u5916\u51fa\u306f\u304a\u3063\u304f\u3046\u3060\u3002<br \/>\u3060\u304b\u3089\u3001\u5f15\u304d\u3053\u3082\u3063\u3066\u3044\u308b\u3002<\/p>\n<p>\u305d\u3053\u3067\u8003\u3048\u305f\u3002<\/p>\n<p>\uff13D\u8ff7\u8def\u3092\u4f5c\u3063\u3066\u3001\u5bb6\u306b\u5c45\u306a\u304c\u3089\u306b\u3057\u3066\u300c\u6563\u6b69\u300d\u6c17\u5206\u3092\u5473\u308f\u3048\u306a\u3044\u3060\u308d\u3046\u304b\u3002<\/p>\n<p>\u305d\u308c\u3067\u3001\u3053\u306e\u7f6a\u60aa\u611f\u304c\u306a\u304f\u306a\u308b\u306e\u304b\u306f\u7591\u554f\u3060\u3051\u308c\u3069\u3001\u3068\u3082\u304b\u304f\u304d\u3063\u304b\u3051\u306f\u305d\u3093\u306a\u611f\u3058\u3060\u3063\u305f\u3002<\/p>\n<p>\u307e\u3060\u3001\u7acb\u4f53\u7684\u306b\u30fb\u30fb\u30fb\u3068\u3044\u3046\u90e8\u5206\u306b\u3064\u3044\u3066\u306f\u3001\u3057\u3063\u304b\u308a\u3068\u3057\u305f\u65b9\u5411\u6027\u3082\u898b\u3048\u3066\u3044\u306a\u3044\u3093\u3060\u3051\u308c\u3069\u3001\u307e\u305a\u306f\u8ff7\u8def\u3092\u81ea\u52d5\u751f\u6210\u3059\u308b\u3068\u3053\u308d\u307e\u3067\u5b8c\u6210\u3055\u305b\u3066\u307f\u3088\u3046\u3002<\/p>\n<p><a href=\"https:\/\/youtu.be\/0qduvs-UdQE\"><img decoding=\"async\" src=\"https:\/\/kusakarism.info\/wp-content\/themes\/the-thor\/img\/dummy.gif\" data-layzr=\"https:\/\/kusakarism.info\/wp-content\/uploads\/2021\/06\/252ac743e9e3be7c9f3cba1813d0a5ab-400x225.jpg\" alt=\"\" width=\"400\" height=\"225\" class=\"alignnone wp-image-11330 size-medium\" \/><\/a><\/p>\n<p>\u4eca\u56de\u306e\u3084\u308a\u65b9\u306f\u3001<span style=\"color: #ff0000; font-size: 14pt;\"><strong>\u7a74\u6398\u308a\u6cd5<\/strong><\/span>\u3068\u3044\u3046\u3082\u306e\u3067\u3042\u308b\u3089\u3057\u3044\u3002<\/p>\n<p>\u7d30\u304b\u306a\u3068\u3053\u308d\u3067\u30dc\u30af\u306e\u3068\u306f\u7570\u306a\u308b\u70b9\u3082\u3042\u308b\u304c\u3001\u305f\u3076\u3093\u554f\u984c\u306f\u306a\u3044\u3060\u308d\u3046\u3002<br \/>\u50d5\u306f\u8ff7\u8def\u5c02\u9580\u5bb6\u3058\u3083\u306a\u3044\u304b\u3089\u3001\u308f\u304b\u3089\u3093\u3051\u308c\u3069\u3002<\/p>\n<h2>\u4eca\u56de\u3082\u52d5\u753b\u3067\u89e3\u8aac\u3002<\/h2>\n<p>YouTube\u3092\u306f\u3058\u3081\u3066\u307f\u3066\u601d\u3046\u3002<\/p>\n<p>\u3053\u3046\u3044\u3046\u7cfb\u306e\u89e3\u8aac\u3092\u6587\u5b57\u3067\u66f8\u304f\u306e\u306f\u3001\u7d50\u69cb\u9aa8\u304c\u6298\u308c\u308b\u3002<\/p>\n<p>\u305d\u3053\u3078\u884c\u304f\u3068\u52d5\u753b\u306f\u3044\u304f\u3076\u3093\u697d\u3060\u3002<\/p>\n<p>\u4eca\u56de\u3082\u89e3\u8aac\u306f\u52d5\u753b\u3067\u884c\u3053\u3046\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<p><span style=\"font-size: 14pt;\"><strong><span style=\"color: #ff0000;\">\u30bf\u30a4\u30e0\u30a2\u30c3\u30bf\u30af\u7de8\u306f\u30b3\u30c1\u30e9(\u2193)<\/span><br \/>\u672c\u6c17\u3067\u4f5c\u308b\u8ff7\u8def\u3002<\/strong><\/span><br \/><a href=\"https:\/\/youtu.be\/0qduvs-UdQE\">https:\/\/youtu.be\/0qduvs-UdQE<\/a><br \/><strong><span style=\"font-size: 14pt;\"><\/span><\/strong><\/p>\n<p><span style=\"font-size: 14pt;\"><strong><span style=\"color: #ff0000;\">\u89e3\u8aac\u7de8\u306f\u30b3\u30c1\u30e9(\u2193)<\/span><br \/><\/strong><\/span>\u7a74\u6398\u308a\u6cd5\u3067\u66f8\u3044\u305f\u30b3\u30fc\u30c9\u306e\u89e3\u8aac<br \/><a href=\"https:\/\/youtu.be\/iEOelFSQqlc\">https:\/\/youtu.be\/iEOelFSQqlc<\/a><\/p>\n<p><span style=\"font-size: 14pt;\"><strong><span style=\"color: #ff0000;\">\u30b5\u30f3\u30d7\u30eb\u30b3\u30fc\u30c9\u306f\u30b3\u30c1\u30e9(\u2193)<\/span><\/strong><\/span><\/p>\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-python\" data-file=\"maze.py\" data-lang=\"Python\"><code>####################   MAZE   ####################\n\nimport tkinter as tk\nimport random\nfrom tkinter import messagebox\n\nSIZE = 10       # 1\u30de\u30b9\u306e\u5927\u304d\u3055(\u30d4\u30af\u30bb\u30eb)\nCOLUMN = 101    # \u5217\u6570(\u5947\u6570\u3092\u63a8\u5968)\nROW = 51        # \u884c\u6570(\u5947\u6570\u3092\u63a8\u5968)\ndeparture = [[1, 1]]    # \u8ff7\u8def\u4f5c\u308a\u306e\u8d77\u70b9\n\nplayerX = 1, playerY = 1, beforeX = 1, beforeY = 1\n\n# \u30ea\u30b9\u30c8\u300cmaze\u300d\u4f5c\u6210\n# \u4e8c\u6b21\u5143\u914d\u5217\u3067\u300c\u58c1:WALL\u300d\u300c\u30d5\u30a3\u30fc\u30eb\u30c9:FIELD\u300d\u300c\u901a\u8def:PATH\u300d\nmaze = []\nfor y in range(ROW) :\n    sub = []\n    for x in range(COLUMN) :\n        if y==0 or y==ROW-1 or x==0 or x==COLUMN-1 :\n            sub.append(&quot;WALL&quot;)\n        else :\n            sub.append(&quot;FIELD&quot;)\n    maze.append(sub)\n\n# \u7a74\u6398\u308a\u95a2\u6570(\u30e9\u30f3\u30c0\u30e0\u306b\u901a\u8def\u3092\u6398\u308a\u9032\u3081\u3066&quot;PATH&quot;\u306b\u66f8\u304d\u63db\u3048\u308b)\ndef dig(x, y) :\n    maze[y][x] = &quot;PATH&quot;     # \u5f15\u6570\u3067\u6307\u5b9a\u3057\u305f\u30dd\u30a4\u30f3\u30c8\u3092\u66f8\u304d\u63db\u3048\n    # \u6398\u308a\u9032\u3081\u308b\u3053\u3068\u304c\u53ef\u80fd\u306a\u65b9\u5411\u3092\u30c1\u30a7\u30c3\u30af\n    canMove = []\n    if maze[y-1][x]==&quot;FIELD&quot; and maze[y-2][x]==&quot;FIELD&quot; :\n        canMove.append(&quot;UP&quot;)\n    if maze[y+1][x]==&quot;FIELD&quot; and maze[y+2][x]==&quot;FIELD&quot; :\n        canMove.append(&quot;DOWN&quot;)\n    if maze[y][x-1]==&quot;FIELD&quot; and maze[y][x-2]==&quot;FIELD&quot; :\n        canMove.append(&quot;LEFT&quot;)\n    if maze[y][x+1]==&quot;FIELD&quot; and maze[y][x+2]==&quot;FIELD&quot; :\n        canMove.append(&quot;RIGHT&quot;)\n    if len(canMove)==0 :    # \u53ef\u80fd\u306a\u65b9\u5411\u304c\u306a\u3051\u308c\u3070\u95a2\u6570\u3092\u629c\u3051\u308b\n        return\n    # \u30e9\u30f3\u30c0\u30e0\u306b\u65b9\u5411\u3092\u6c7a\u3081\u3066\u6398\u308a\u9032\u3080\n    direction = random.choice(canMove)\n    if direction==&quot;UP&quot; :\n        maze[y-1][x]=&quot;PATH&quot;\n        maze[y-2][x]=&quot;PATH&quot;\n        y -= 2\n    if direction==&quot;DOWN&quot; :\n        maze[y+1][x]=&quot;PATH&quot;\n        maze[y+2][x]=&quot;PATH&quot;\n        y += 2\n    if direction==&quot;LEFT&quot; :\n        maze[y][x-1]=&quot;PATH&quot;\n        maze[y][x-2]=&quot;PATH&quot;\n        x -= 2\n    if direction==&quot;RIGHT&quot; :\n        maze[y][x+1]=&quot;PATH&quot;\n        maze[y][x+2]=&quot;PATH&quot;\n        x += 2\n    departure.append([x, y])    # \u9032\u3093\u3060\u4f4d\u7f6e\u3092\u7a74\u6398\u308a\u306e\u8d77\u70b9\u306b\u8ffd\u52a0\n    dig(x, y)   # \u518d\u5e30(\u65b0\u305f\u306a\u5730\u70b9\u304b\u3089\u518d\u3073\u7a74\u6398\u308a)\n\n# \u30b2\u30fc\u30e0\u30d7\u30ec\u30a4\u7684\u306a\u30fb\u30fb\u30fb\n# \u30a4\u30d9\u30f3\u30c8\u95a2\u6570\ndef keyPress(event) :\n    global playerX,playerY,beforeX,beforeY\n    if event.keysym==&quot;Up&quot; and maze[playerY-1][playerX]==&quot;PATH&quot; :\n        beforeX = playerX\n        beforeY = playerY\n        playerY -=1\n    if event.keysym==&quot;Down&quot; and maze[playerY+1][playerX]==&quot;PATH&quot; :\n        beforeX = playerX\n        beforeY = playerY\n        playerY +=1\n    if event.keysym==&quot;Left&quot; and maze[playerY][playerX-1]==&quot;PATH&quot; :\n        beforeX = playerX\n        beforeY = playerY\n        playerX -=1\n    if event.keysym==&quot;Right&quot; and maze[playerY][playerX+1]==&quot;PATH&quot; :\n        beforeX = playerX\n        beforeY = playerY\n        playerX +=1\n# \u30d7\u30ec\u30a4\u30e4\u30fc\u79fb\u52d5\u3068\u30b4\u30fc\u30eb\ndef move() :\n    can.create_oval(beforeX*SIZE+1, beforeY*SIZE+1, (beforeX+1)*SIZE-1, (beforeY+1)*SIZE-1, fill=&quot;white&quot;, width=0)\n    can.create_oval(playerX*SIZE+2, playerY*SIZE+2, (playerX+1)*SIZE-2, (playerY+1)*SIZE-2, fill=&quot;blue&quot;)\n    if playerX==COLUMN-2 and playerY==ROW-2 :\n        messagebox.showinfo(&quot;Information&quot;, &quot;GOAL!!!!&quot;)\n        exit()\n    can.after(100, move)    # \u518d\u5e30\n    \n# \u30b2\u30fc\u30e0\u30a6\u30a4\u30f3\u30c9\u30a6\nwin = tk.Tk()\ncan = tk.Canvas(win, width=COLUMN*SIZE, height=ROW*SIZE)\ncan.pack()\n\nwhile len(departure)!=0 :   # \u65b0\u305f\u306a\u8d77\u70b9\u3092\u547c\u3073\u51fa\u3059\n    start = departure.pop(0)\n    x = start[0]\n    y = start[1]\n    dig(x, y)\n\nfor y in range(ROW):        # \u8ff7\u8def\u3092\u63cf\u753b\u3059\u308b\n    for x in range(COLUMN):\n        if maze[y][x]==&quot;PATH&quot; :\n            color = &quot;white&quot;\n        else :\n            color = &quot;black&quot;\n        can.create_rectangle(x*SIZE, y*SIZE, (x+1)*SIZE, (y+1)*SIZE, fill=color, width=0)\n\ncan.create_rectangle((COLUMN-2)*SIZE, (ROW-2)*SIZE, (COLUMN-1)*SIZE, (ROW-1)*SIZE ,fill=&quot;red&quot;)  # \u30b4\u30fc\u30eb\u4f4d\u7f6e\n\nmove()      # \u30d7\u30ec\u30a4\u30e4\u30fc\u79fb\u52d5\u95a2\u6570\u547c\u3073\u51fa\u3057\n\nwin.bind(&quot;&lt;Any-KeyPress&gt;&quot;, keyPress)    # \u30ad\u30fc\u30d7\u30ec\u30b9\u3092\u30d0\u30a4\u30f3\u30c9\n\nwin.mainloop()      # \u30a6\u30a4\u30f3\u30c9\u30a6\u30eb\u30fc\u30d7<\/code><\/pre><\/div>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6700\u7d42\u7684\u306b\u4f5c\u308a\u305f\u3044\u8ff7\u8def\u306f\u3002 \u305a\u3063\u3068\u5bb6\u306b\u5f15\u304d\u3053\u3082\u3063\u3066\u3044\u308b\u3068\u30fb\u30fb\u30fb\u305f\u307e\u306b\u306f\u5916\u306b\u51fa\u3066\u4f53\u3092\u52d5\u304b\u3057\u305f\u308a\u3057\u305f\u65b9\u304c\u3088\u3044\u306e\u304b\u306a\uff1f\u306a\u3093\u3066\u8003\u3048\u305f\u308a\u3059\u308b\u3002\u3061\u3087\u3063\u3068\u3057\u305f\u7f6a\u60aa\u611f\u3002 \u3067\u3082\u3001\u5916\u51fa\u306f\u304a\u3063\u304f\u3046\u3060\u3002\u3060\u304b\u3089\u3001\u5f15\u304d\u3053\u3082\u3063\u3066\u3044\u308b [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":11330,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[349,340,1],"tags":[337,304,338,344],"class_list":["post-11329","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python","category-programming","category-diary","tag-python","tag-youtube","tag-338","tag-344"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/kusakarism.info\/index.php?rest_route=\/wp\/v2\/posts\/11329","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kusakarism.info\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kusakarism.info\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kusakarism.info\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kusakarism.info\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=11329"}],"version-history":[{"count":7,"href":"https:\/\/kusakarism.info\/index.php?rest_route=\/wp\/v2\/posts\/11329\/revisions"}],"predecessor-version":[{"id":11337,"href":"https:\/\/kusakarism.info\/index.php?rest_route=\/wp\/v2\/posts\/11329\/revisions\/11337"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/kusakarism.info\/index.php?rest_route=\/wp\/v2\/media\/11330"}],"wp:attachment":[{"href":"https:\/\/kusakarism.info\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=11329"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kusakarism.info\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=11329"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kusakarism.info\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=11329"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}