{"id":3068,"date":"2021-01-25T08:39:51","date_gmt":"2021-01-24T23:39:51","guid":{"rendered":"http:\/\/itoshi.main.jp\/tech\/?p=3068"},"modified":"2021-01-28T23:46:13","modified_gmt":"2021-01-28T14:46:13","slug":"maze","status":"publish","type":"post","link":"http:\/\/itoshi.main.jp\/tech\/2021\/01\/25\/maze\/","title":{"rendered":"\u8ff7\u8def\u3092\u81ea\u52d5\u3067\u4f5c\u3063\u3066\u3001\u81ea\u52d5\u3067\u89e3\u304f"},"content":{"rendered":"<p>\u8ff7\u8def\u3092\u81ea\u52d5\u3067\u4f5c\u3063\u3066\u3001\u81ea\u52d5\u3067\u89e3\u304f\u3001\u305d\u3093\u306a\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u4f5c\u308a\u305f\u3044\u3068\u524d\u3005\u304b\u3089\u601d\u3063\u3066\u3044\u307e\u3057\u305f\u3002<\/p>\n<p>\u8a66\u884c\u932f\u8aa4\u3057\u306a\u304c\u3089\u4f5c\u3063\u3066\u307f\u308b\u3068\u3001\u306a\u3093\u3068\u3001<strong class=\"marker-yellow\">\u4f5c\u308b\u306e\u3082\u89e3\u304f\u306e\u3082\u540c\u3058\u30a2\u30eb\u30b4\u30ea\u30ba\u30e0\u3067\u3067\u304d\u308b<\/strong>\u3053\u3068\u304c\u5206\u304b\u308a\u307e\u3057\u305f\u3002<\/p>\n<p>youtube \u52d5\u753b\u306b\u3082up\u3057\u307e\u3057\u305f\u3002\u3053\u3061\u3089\u306f\u8ff7\u8def\u306e\u30b5\u30a4\u30ba\u3092\u5909\u3048\u306a\u304c\u3089\u3001\u8ff7\u8def\u3092\u4f5c\u3063\u3066\u3001\u305d\u308c\u3092\u89e3\u304f\u3001\u3092\u7e70\u308a\u8fd4\u3057\u307e\u3059\u3002<\/p>\n<p><iframe loading=\"lazy\" style=\"max-width:100%;\" width=\"560\" height=\"315\" src=\"https:\/\/www.youtube.com\/embed\/krAe6bm9SFY\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen><\/iframe><\/p>\n<p>\u30d7\u30ed\u30b0\u30e9\u30e0\u306f\u3001\u3053\u3061\u3089<br \/>\n<a href=\"https:\/\/github.com\/itoshin-tech\/maze\">https:\/\/github.com\/itoshin-tech\/maze<\/a><\/p>\n<h2>\u8ff7\u8def\u3092\u751f\u6210\u3059\u308b\u65b9\u6cd5<\/h2>\n<p>\u305d\u308c\u3067\u306f\u8ff7\u8def\u3092\u4f5c\u308b\u65b9\u6cd5\u3092\u8aac\u660e\u3057\u307e\u3059\u3002\u307e\u305a\u3001field\u3068\u3044\u30462\u6b21\u5143\u306e\u914d\u5217\u5909\u6570\u3092\u8003\u3048\u3001\u3053\u3053\u306b\u9053\u3092\u4f5c\u3063\u3066\u3044\u304f\u3068\u3057\u307e\u3059\u3002<\/p>\n<p>field\u306e\u8981\u7d20\u306f\u521d\u3081\u306f\u5168\u30660\u3067\u3059\u30020\u3092\u30d6\u30e9\u30f3\u30af\u3068\u547c\u3076\u3053\u3068\u306b\u3057\u307e\u3059\u3002\u3053\u3053\u306b\u3001\u9053\u306eid\uff082, 3, 4&#8230;\uff09\u3067\u66f8\u304d\u63db\u3048\u308b\u3053\u3068\u3067\u9053\u3092\u4f5c\u3063\u3066\u3044\u304d\u307e\u3059\u3002id\u304c2\u304b\u3089\u306a\u306e\u306f\u3001\u8ff7\u8def\u3092\u89e3\u304f\u65b9\u6cd5\u3068\u6574\u5408\u6027\u3092\u5f97\u308b\u305f\u3081\u3067\u6df1\u3044\u610f\u5473\u306f\u3042\u308a\u307e\u305b\u3093\u3002<\/p>\n<p>\u307e\u305a\u3001\u30b9\u30bf\u30fc\u30c8\u5730\u70b9\u3092\u30e9\u30f3\u30c0\u30e0\u306b\u6c7a\u3081\u3001\u305d\u306e\u8981\u7d20\u30922\u306b\u3057\u307e\u3059\u3002\u305d\u3057\u3066\u3001\u4e0a\u4e0b\u5de6\u53f3\u65b9\u5411\u306b\u4e00\u3064\u98db\u3070\u3057\u305f\u5148\u306e\u30bb\u30eb\u3092\u8abf\u3079\u307e\u3059\u3002\u30bb\u30eb\u304c\u30d6\u30e9\u30f3\u30af(0)\u3067\u3042\u308c\u3070\u3001\u305d\u3061\u3089\u306b\u9053\u3092\u4f38\u3070\u3059\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002\u9032\u3081\u308b\u65b9\u5411\u304c\u8907\u6570\u3042\u308b\u5834\u5408\u306b\u306f\u3001\u30e9\u30f3\u30c0\u30e0\u30671\u3064\u306e\u65b9\u5411\u3092\u9078\u3073\u307e\u3059\u3002<\/p>\n<p><a href=\"http:\/\/itoshi.main.jp\/tech\/wp-content\/uploads\/2021\/01\/01maze.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/itoshi.main.jp\/tech\/wp-content\/uploads\/2021\/01\/01maze.png\" alt=\"\" width=\"512\" height=\"418\" class=\"aligncenter size-full wp-image-3075\" srcset=\"http:\/\/itoshi.main.jp\/tech\/wp-content\/uploads\/2021\/01\/01maze.png 512w, http:\/\/itoshi.main.jp\/tech\/wp-content\/uploads\/2021\/01\/01maze-300x245.png 300w\" sizes=\"auto, (max-width: 512px) 100vw, 512px\" \/><\/a><\/p>\n<p>\u9078\u3093\u3060\u65b9\u5411\u306b\u9032\u307f\u307e\u3059\u3002\u4f38\u3070\u3057\u305f\u9053\u306b\u306fid\u3067\u3042\u308b2\u3092\u4ee3\u5165\u3057\u307e\u3059\u3002\u3053\u3053\u304b\u3089\u307e\u305f\u540c\u69d8\u306b\u30014\u65b9\u5411\u3092\u8abf\u3079\u3001\u30d6\u30e9\u30f3\u30af\u306e\u65b9\u5411\u306b\u9053\u3092\u4f38\u3070\u3057\u307e\u3059\u3002<\/p>\n<p><a href=\"http:\/\/itoshi.main.jp\/tech\/wp-content\/uploads\/2021\/01\/02maze.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/itoshi.main.jp\/tech\/wp-content\/uploads\/2021\/01\/02maze.png\" alt=\"\" width=\"512\" height=\"418\" class=\"aligncenter size-full wp-image-3076\" srcset=\"http:\/\/itoshi.main.jp\/tech\/wp-content\/uploads\/2021\/01\/02maze.png 512w, http:\/\/itoshi.main.jp\/tech\/wp-content\/uploads\/2021\/01\/02maze-300x245.png 300w\" sizes=\"auto, (max-width: 512px) 100vw, 512px\" \/><\/a><\/p>\n<p>\u3053\u308c\u3092\u7e70\u308a\u8fd4\u3057\u306a\u304c\u3089\u9053\u3092\u4f38\u3070\u3057\u3066\u3044\u304d\u307e\u3059\u304c\u3001\u3044\u305a\u308c\u9032\u3081\u306a\u304f\u306a\u308a\u307e\u3059\u3002<\/p>\n<p><a href=\"http:\/\/itoshi.main.jp\/tech\/wp-content\/uploads\/2021\/01\/03maze.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/itoshi.main.jp\/tech\/wp-content\/uploads\/2021\/01\/03maze.png\" alt=\"\" width=\"512\" height=\"418\" class=\"aligncenter size-full wp-image-3077\" \/><\/a><\/p>\n<p>\u9032\u3081\u306a\u304f\u306a\u3063\u305f\u3089\u3001\u4f5c\u3063\u3066\u304d\u305f\u9053\u3067\u3001\u5206\u5c90\u65b9\u5411\u3092\u9078\u3093\u3067\u304d\u305f\u5ea7\u6a19\u3092\u78ba\u8a8d\u3057\u307e\u3059\uff08\u30aa\u30ec\u30f3\u30b8\u306e\u67a0\uff09\u3002\u305d\u3057\u3066\u3001\u77e2\u5370\u3067\u793a\u3057\u305f(x=1, y=5)\u306e\u4f4d\u7f6e\u304b\u3089\u5206\u5c90\u3092\u4f38\u3070\u305d\u3046\u3068\u8003\u3048\u307e\u3059\u3002<\/p>\n<p><a href=\"http:\/\/itoshi.main.jp\/tech\/wp-content\/uploads\/2021\/01\/04maze.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/itoshi.main.jp\/tech\/wp-content\/uploads\/2021\/01\/04maze.png\" alt=\"\" width=\"512\" height=\"577\" class=\"aligncenter size-full wp-image-3078\" srcset=\"http:\/\/itoshi.main.jp\/tech\/wp-content\/uploads\/2021\/01\/04maze.png 512w, http:\/\/itoshi.main.jp\/tech\/wp-content\/uploads\/2021\/01\/04maze-266x300.png 266w\" sizes=\"auto, (max-width: 512px) 100vw, 512px\" \/><\/a><\/p>\n<p>\u3053\u3053\u3067\u5c11\u3057\u30d7\u30ed\u30b0\u30e9\u30e0\u306e\u3053\u3068\u3092\u8003\u3048\u307e\u3059\u3002<\/p>\n<p>\u4f5c\u308b\u95a2\u6570\u306f\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306a<strong class=\"marker-yellow\">fill_with_road()<\/strong>\u3068\u3044\u3046\u95a2\u6570\u3067\u3059\u3002\u3053\u306e\u95a2\u6570\u306f\u3001(x, y)\u306e\u5730\u70b9\u304b\u3089\u9053\u3092\u4f38\u3070\u3057\u30010\u306e\u9818\u57df\u3092\u9053\u3067\u6e80\u305f\u3059\u3001\u3068\u3044\u3046\u50cd\u304d\u3092\u60f3\u5b9a\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<p><a href=\"http:\/\/itoshi.main.jp\/tech\/wp-content\/uploads\/2021\/01\/fill_with_road.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/itoshi.main.jp\/tech\/wp-content\/uploads\/2021\/01\/fill_with_road.png\" alt=\"\" width=\"540\" height=\"419\" class=\"aligncenter size-full wp-image-3074\" srcset=\"http:\/\/itoshi.main.jp\/tech\/wp-content\/uploads\/2021\/01\/fill_with_road.png 540w, http:\/\/itoshi.main.jp\/tech\/wp-content\/uploads\/2021\/01\/fill_with_road-300x233.png 300w\" sizes=\"auto, (max-width: 540px) 100vw, 540px\" \/><\/a><\/p>\n<p>\u306f\u3058\u3081\u304b\u3089\u8003\u3048\u3066\u3001x=3, y=3 \u306e\u30b9\u30bf\u30fc\u30c8\u5730\u70b9\u3092\u30bb\u30c3\u30c8\u3057\u3066\u3001fill_with_road(x=3, y=3, id)\u3092\u5b9f\u884c\u3057\u305f\u3068\u60f3\u5b9a\u3057\u307e\u3059\u3002\u305d\u3057\u3066\u3001\u306f\u3058\u3081\u306e\u4e00\u672c\u9053\u3092\u4f38\u3070\u3057\u7d42\u3048\u3066\u3001(x=1, y=5)\u304b\u3089\u5206\u5c90\u3092\u4f38\u3070\u3059\u30d5\u30a7\u30fc\u30ba\u306b\u306a\u3063\u3066\u3044\u308b\u3068\u3057\u307e\u3059\u3002\u307e\u3060\u3001fill_with_road(x=3, y=3, id)\u306e\u4e2d\u3067\u3059\u3002<\/p>\n<p>(x=1, y=5)\u304b\u3089\u5206\u5c90\u3092\u4f5c\u308b\u305f\u3081\u306b\u3001\u3053\u306e\u7b87\u6240\u3092\u30b9\u30bf\u30fc\u30c8\u5730\u70b9\u3068\u3057\u305ffill_with_road(x=1, y=5, id=id+1)\u3092\u5b9f\u884c\u3057\u307e\u3059\u3002id\u306f\u4eca\u306eid\u304b\u3089\u4e00\u3064\u5897\u3084\u3059\u3057\u307e\u3059\uff08id \u3092\u5909\u3048\u308b\u306e\u306f\u5358\u306b\u30a2\u30eb\u30b4\u30ea\u30ba\u30e0\u306e\u52d5\u304d\u3092\u77e5\u308b\u305f\u3081\u3067\u3059\uff09\u3002\u3057\u3064\u3053\u3044\u3088\u3046\u3067\u3059\u304c\u3001\u3053\u308c\u306ffill_with_road(x=3, y=3, id)\u306e\u4e2d\u3067\u5b9f\u884c\u3057\u307e\u3059\u3002<\/p>\n<p>\u540c\u69d8\u306b\u3001fill_with_road(x=3, y=3, id)\u306e\u4e2d\u3067\u3001\u5168\u3066\u306e\u5206\u5c90\u304c\u3067\u304d\u308b\u53ef\u80fd\u6027\u306e\u3042\u308b\u30aa\u30ec\u30f3\u30b8\u306e\u7b87\u6240\u304b\u3089\u3001fill_with_road\u3092\u5b9f\u884c\u3057\u307e\u3059\u3002<\/p>\n<p>\u3053\u308c\u3067\u30a2\u30eb\u30b4\u30ea\u30ba\u30e0\u306e\u6982\u8981\u306f\u7d42\u308f\u308a\u3067\u3059\u3002<\/p>\n<p>\u3053\u306e\u3088\u3046\u306b\u3059\u308b\u3053\u3068\u3067\u3001\u5206\u5c90\u306e\u5148\u3067\u3082\u3001\u3055\u3089\u306a\u308b\u5206\u5c90\u304c\u8d77\u304d\u3001\u305d\u306e\u5148\u3067\u3082\u5206\u5c90\u3092\u8d77\u3053\u3059\u3053\u3068\u304c\u3067\u304d\u308b\u306e\u3067\u3059\u3002\u7406\u8ad6\u4e0a\u306f\u3001\u4f55\u6bb5\u968e\u3067\u3082\u5206\u5c90\u3092\u8d77\u3053\u3059\u3053\u3068\u304c\u3067\u304d\u308b\u306e\u3067\u3059\u3002<\/p>\n<p>\u3084\u3084\u3053\u3057\u3044\u306e\u3067\u3059\u304c\u9762\u767d\u3044\u3067\u3059\u3088\u306d\u3002\u3053\u306e\u3088\u3046\u306b\u3001\u95a2\u6570\u306e\u4e2d\u3067\u81ea\u5206\u81ea\u8eab\u306e\u95a2\u6570\u3092\u547c\u3076\u65b9\u6cd5\u3092<strong class=\"marker-yellow\">\u518d\u5e30<\/strong>\u3068\u547c\u3073\u307e\u3059\u3002<\/p>\n<p>\u4eca\u306e\u4f8b\u306e\u7d9a\u304d\u3092\u8003\u3048\u308b\u3068\u30013\u306e\u9053\u304c\u4f5c\u3089\u308c\u3001\u66f4\u306b\u4e0b\u306e\u30aa\u30ec\u30f3\u30b8\u306e\u67a0\u3067\u5206\u5c90\u304c\u8d77\u3053\u308a\u30014\u306e\u9053\u304c\u4f38\u3073\u3066\u3044\u304d\u307e\u3059\u3002\u3053\u3053\u3067\u65b0\u3057\u3044\u9053\u3092\u4f5c\u308b\u30b9\u30da\u30fc\u30b9\u304c\u306a\u304f\u306a\u308b\u306e\u3067\u8ff7\u8def\u304c\u5b8c\u6210\u3057\u307e\u3059\u3002<\/p>\n<p><a href=\"http:\/\/itoshi.main.jp\/tech\/wp-content\/uploads\/2021\/01\/05maze.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/itoshi.main.jp\/tech\/wp-content\/uploads\/2021\/01\/05maze.png\" alt=\"\" width=\"512\" height=\"547\" class=\"aligncenter size-full wp-image-3079\" srcset=\"http:\/\/itoshi.main.jp\/tech\/wp-content\/uploads\/2021\/01\/05maze.png 512w, http:\/\/itoshi.main.jp\/tech\/wp-content\/uploads\/2021\/01\/05maze-281x300.png 281w\" sizes=\"auto, (max-width: 512px) 100vw, 512px\" \/><\/a><\/p>\n<p>\u3042\u3068\u306f\u3001field \u306e\u8981\u7d20\u30671\u4ee5\u4e0a\u306e\u90e8\u5206\u3092\u5168\u30661\u306b\u76f4\u3057\u3066\u8ff7\u8def\u304c\u5b8c\u6210\u3067\u3059\u3002<\/p>\n<p>1\u3092\u8ff7\u8def\u306e\u9053\u30010\u3092\u58c1\u3068\u89e3\u91c8\u3057\u307e\u3059\u3002\u30b9\u30bf\u30fc\u30c8\u5730\u70b9\u3068\u30b4\u30fc\u30eb\u5730\u70b9\u306f\u3069\u3053\u306b\u304a\u3044\u3066\u3082\u6210\u308a\u7acb\u3061\u307e\u3059\u3002<\/p>\n<p><a href=\"http:\/\/itoshi.main.jp\/tech\/wp-content\/uploads\/2021\/01\/06maze.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/itoshi.main.jp\/tech\/wp-content\/uploads\/2021\/01\/06maze.png\" alt=\"\" width=\"512\" height=\"459\" class=\"aligncenter size-full wp-image-3080\" srcset=\"http:\/\/itoshi.main.jp\/tech\/wp-content\/uploads\/2021\/01\/06maze.png 512w, http:\/\/itoshi.main.jp\/tech\/wp-content\/uploads\/2021\/01\/06maze-300x269.png 300w\" sizes=\"auto, (max-width: 512px) 100vw, 512px\" \/><\/a><\/p>\n<p>\u5b9f\u306f\u3001<strong class=\"marker-yellow\">\u8ff7\u8def\u3092\u89e3\u304f\u3068\u304d\u306b\u3082fill_with_road()\u304c\u4f7f\u3048\u307e\u3059<\/strong>\u30021\u306e\u90e8\u5206\u3092brank\u3068\u89e3\u91c8\u3057\u3001\u305d\u3053\u306b\u9053\u3092\u5145\u586b\u3057\u3066\u3044\u3051\u3070\u3088\u3044\u306e\u3067\u3059\u3002<\/p>\n<h2>\u8ff7\u8def\u3092\u89e3\u304f\u65b9\u6cd5<\/h2>\n<p>\u8ff7\u8def\u3092\u89e3\u304f\u65b9\u6cd5\u3067\u3059\u3002\u5de6\u4e0a\u304c\u30b9\u30bf\u30fc\u30c8\u3001\u53f3\u4e0b\u304c\u30b4\u30fc\u30eb\u3060\u3068\u3057\u307e\u3059\u3002\u4eca\u5ea6\u306f\u30011\u3092\u30d6\u30e9\u30f3\u30af\u3068\u3057\u307e\u3059\u30021\u306e\u4e0a\u306bid=2, 3, 4, &#8230; \u306e\u9053\u3092\u4f5c\u3063\u3066\u3044\u304f\u3053\u3068\u3092\u8003\u3048\u307e\u3059\u3002<\/p>\n<p><a href=\"http:\/\/itoshi.main.jp\/tech\/wp-content\/uploads\/2021\/01\/07maze.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/itoshi.main.jp\/tech\/wp-content\/uploads\/2021\/01\/07maze.png\" alt=\"\" width=\"512\" height=\"402\" class=\"aligncenter size-full wp-image-3087\" srcset=\"http:\/\/itoshi.main.jp\/tech\/wp-content\/uploads\/2021\/01\/07maze.png 512w, http:\/\/itoshi.main.jp\/tech\/wp-content\/uploads\/2021\/01\/07maze-300x236.png 300w\" sizes=\"auto, (max-width: 512px) 100vw, 512px\" \/><\/a><\/p>\n<p>\u8ff7\u8def\u751f\u6210\u6642\u3067\u306f\u30d6\u30e9\u30f3\u30af\u306e\u7a7a\u9593\u306f\u5e83\u3044\u9577\u65b9\u5f62\u3067\u3057\u305f\u304c\u3001\u4eca\u56de\u306e\u30d6\u30e9\u30f3\u30af\u306f\u8ff7\u8def\u306e\u304f\u306d\u304f\u306d\u3057\u305f\u5eca\u4e0b\u306e\u5f62\u72b6\u3067\u3059\u3002\u3057\u304b\u3057\u3001fill_with_road\u306f\u3001\u5358\u306b\u9699\u9593\u304c\u3042\u3063\u305f\u3089\u305d\u3053\u306b\u9053\u3092\u4f38\u3070\u3057\u3066\u3044\u304f\u30a2\u30eb\u30b4\u30ea\u30ba\u30e0\u306a\u306e\u3067\u3001\u30d6\u30e9\u30f3\u30af\u306e\u5f62\u72b6\u306b\u306f\u95a2\u4fc2\u306a\u304f\u52d5\u4f5c\u3057\u307e\u3059\u3002<\/p>\n<p>\u3088\u3063\u3066\u3001\u3053\u3053\u3067\u3082\u3001\u8ff7\u8def\u751f\u6210\u6642\u3068\u307b\u3068\u3093\u3069\u540c\u3058\u30a2\u30eb\u30b4\u30ea\u30ba\u30e0\u3067\u9053\u3092\u4f38\u3070\u3057\u3066\u3044\u3051\u3070\u3001\u3044\u3064\u304b\u30b4\u30fc\u30eb\u306b\u307e\u3067\u9053\uff08\uff1f\uff09\u304c\u5230\u9054\u3057\u307e\u3059\u3002<\/p>\n<p>\u305f\u3060\u3057\u3001\u524d\u56de\u4f7f\u3063\u305ffill_with_road\u306e\u4ee5\u4e0b\u306e\u90e8\u5206\u3060\u3051\u3001\u5909\u66f4\u3057\u307e\u3059\u3002<\/p>\n<p><a href=\"http:\/\/itoshi.main.jp\/tech\/wp-content\/uploads\/2021\/01\/fill_with_road2.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/itoshi.main.jp\/tech\/wp-content\/uploads\/2021\/01\/fill_with_road2.png\" alt=\"\" width=\"538\" height=\"310\" class=\"aligncenter size-full wp-image-3086\" srcset=\"http:\/\/itoshi.main.jp\/tech\/wp-content\/uploads\/2021\/01\/fill_with_road2.png 538w, http:\/\/itoshi.main.jp\/tech\/wp-content\/uploads\/2021\/01\/fill_with_road2-300x173.png 300w\" sizes=\"auto, (max-width: 538px) 100vw, 538px\" \/><\/a><\/p>\n<p>\u96a3\u308a\u5408\u3063\u305f4\u65b9\u5411\u3067brank=1\u306e\u65b9\u5411\u306b\u9053\u3092\u9032\u3081\u307e\u3059\u3002\u884c\u3051\u308b\u65b9\u5411\u304c\u5206\u304b\u3063\u305f\u3089\u30012\u30de\u30b9\u9032\u3081\u307e\u3059\u3002\u3053\u306e\u8981\u9818\u3067\u9053\u3092\u9577\u304f\u3057\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n<p><a href=\"http:\/\/itoshi.main.jp\/tech\/wp-content\/uploads\/2021\/01\/08maze.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/itoshi.main.jp\/tech\/wp-content\/uploads\/2021\/01\/08maze.png\" alt=\"\" width=\"512\" height=\"402\" class=\"aligncenter size-full wp-image-3088\" srcset=\"http:\/\/itoshi.main.jp\/tech\/wp-content\/uploads\/2021\/01\/08maze.png 512w, http:\/\/itoshi.main.jp\/tech\/wp-content\/uploads\/2021\/01\/08maze-300x236.png 300w\" sizes=\"auto, (max-width: 512px) 100vw, 512px\" \/><\/a><\/p>\n<p>\u7d50\u679c\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u884c\u304d\u6b62\u307e\u308a\u306b\u305f\u3069\u308a\u7740\u304d\u307e\u3057\u305f\u3002\u3053\u3053\u304b\u3089\u306f\u3001\u65b9\u5411\u3092\u6c7a\u5b9a\u3057\u305f\u7b87\u6240\u5168\u3066\u306b\u304a\u3044\u3066\u5206\u5c90\u3092\u8a66\u3057\u307e\u3059\u3002<\/p>\n<p><a href=\"http:\/\/itoshi.main.jp\/tech\/wp-content\/uploads\/2021\/01\/09maze.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/itoshi.main.jp\/tech\/wp-content\/uploads\/2021\/01\/09maze.png\" alt=\"\" width=\"515\" height=\"471\" class=\"aligncenter size-full wp-image-3089\" srcset=\"http:\/\/itoshi.main.jp\/tech\/wp-content\/uploads\/2021\/01\/09maze.png 515w, http:\/\/itoshi.main.jp\/tech\/wp-content\/uploads\/2021\/01\/09maze-300x274.png 300w\" sizes=\"auto, (max-width: 515px) 100vw, 515px\" \/><\/a><\/p>\n<p>\u5206\u5c90\u3092\u3059\u308b\u3068\u304d\u306b\u306fid\u306b1\u3092\u52a0\u3048\u308b\u3068\u3059\u308c\u3070\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u9053\u304c\u751f\u6210\u3055\u308c\u3001\u30b4\u30fc\u30eb\u306b\u305f\u3069\u308a\u7740\u304f\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<p><a href=\"http:\/\/itoshi.main.jp\/tech\/wp-content\/uploads\/2021\/01\/10maze.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/itoshi.main.jp\/tech\/wp-content\/uploads\/2021\/01\/10maze.png\" alt=\"\" width=\"515\" height=\"404\" class=\"aligncenter size-full wp-image-3090\" srcset=\"http:\/\/itoshi.main.jp\/tech\/wp-content\/uploads\/2021\/01\/10maze.png 515w, http:\/\/itoshi.main.jp\/tech\/wp-content\/uploads\/2021\/01\/10maze-300x235.png 300w\" sizes=\"auto, (max-width: 515px) 100vw, 515px\" \/><\/a><\/p>\n<p>\u4ee5\u4e0a\u3067\u8ff7\u8def\u306e\u4f5c\u308a\u65b9\u30fb\u89e3\u304d\u65b9\u306e\u8aac\u660e\u306f\u7d42\u308f\u308a\u3067\u3059\u3002\u8aad\u3093\u3067\u3044\u305f\u3060\u304d\u3042\u308a\u304c\u3068\u3046\u3054\u3056\u3044\u307e\u3057\u305f\u3002<\/p>\n<p>\u30d7\u30ed\u30b0\u30e9\u30e0\u306f github \u306b\u3082upload \u3057\u3066\u3044\u307e\u3059\u3002<br \/>\n<a href=\"https:\/\/github.com\/itoshin-tech\/maze\">https:\/\/github.com\/itoshin-tech\/maze<\/a><\/p>\n<p>\u30d5\u30a1\u30a4\u30eb\u306f1\u3064\u306a\u306e\u3067\u4ee5\u4e0b\u306b\u3082\u51fa\u3057\u3066\u304a\u304d\u307e\u3059\u3002 <\/p>\n<pre class=\"lang:python decode:true \" title=\"maze.py\" >\r\n\"\"\"\r\n\u8ff7\u8def\u751f\u6210\u3001\u8ff7\u8def\u89e3\u304d\u30d7\u30ed\u30b0\u30e9\u30e0\r\n\"\"\"\r\nimport numpy as np\r\nimport random\r\nimport cv2\r\nimport matplotlib.pyplot as plt\r\nimport seaborn as sns\r\nimport sys\r\n\r\n\r\nclass MazeCreater():\r\n    \"\"\"\r\n    \u8ff7\u8def\u3092\u4f5c\u308b\u30af\u30e9\u30b9\r\n    \"\"\"\r\n    def __init__(self, size_w=10, size_h=5):\r\n        \"\"\"\r\n        Parameters\r\n        ----------\r\n        size_w: int\r\n            \u8ff7\u8def\u306e\u6a2a\u30b5\u30a4\u30ba\uff08\u5206\u5c90\u3067\u304d\u308b\u70b9\u306e\u6570\uff09\r\n        size_h: int\r\n            \u8ff7\u8def\u306e\u7e26\u30b5\u30a4\u30ba\r\n        \"\"\"\r\n\r\n        self.size_w = size_w\r\n        self.size_h = size_h\r\n\r\n        # \u9053\u751f\u6210\u30af\u30e9\u30b9\u306e\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u751f\u6210\r\n        # \u5f15\u6570 max_col \u306f\u753b\u50cf\u51fa\u529b\u6642\u306e\u8272\u306e\u6570\r\n        self.roadfiller =RoadFiller(\r\n            max_col=size_w,\r\n            )\r\n    \r\n    def generate_maze(self, is_show=True, unit=10, delay=100):\r\n        \"\"\"\r\n        \u8ff7\u8def\u3092\u751f\u6210\u3059\u308b\r\n\r\n        \u5185\u90e8\u3067\u4f7f\u7528\u3059\u308bRoadFiller\u30af\u30e9\u30b9\u304c\u3001\u5b9f\u969b\u306b\u8ff7\u8def\u3092\u751f\u6210\u3057\u3066\u3044\u308b\r\n\r\n        Parameters\r\n        ----------\r\n        unit: int\r\n            \u753b\u50cf\u751f\u6210\u6642\u306e\u30bb\u30eb\u30b5\u30a4\u30ba\r\n        delay: int\r\n            \u30a2\u30cb\u30e1\u30fc\u30b7\u30e7\u30f3\u6642\u306e\u9045\u5ef6(ms)\r\n\r\n        Returns\r\n        -------\r\n        field_out: 2d numpuy.array\r\n            \u751f\u6210\u3057\u305f\u8ff7\u8def\r\n            0\u304c\u58c1\r\n            1\u304c\u901a\u8def\r\n        \"\"\"\r\n\r\n        # field \u306e\u30b5\u30a4\u30ba\r\n        n_w = 2 * self.size_w + 1\r\n        n_h = 2 * self.size_h + 1\r\n\r\n        # field \u3092\u30d6\u30e9\u30f3\u30af0\u3067\u6e80\u305f\u3059\r\n        field = np.zeros((n_h, n_w), dtype=np.uint8)\r\n\r\n        # \u9053\u306e\u958b\u59cb\u6642\u306eid (\u753b\u9762\u8868\u793a\u306e\u90fd\u5408\u4e0a2\u304b\u3089\u958b\u59cb)\r\n        road_id = 2\r\n\r\n        # \u30b9\u30bf\u30fc\u30c8\u5730\u70b9\u3092\u30e9\u30f3\u30c0\u30e0\u3067\u6c7a\u3081\u308b\r\n        x = 2* np.random.randint(0, self.size_w) + 1\r\n        y = 2* np.random.randint(0, self.size_h) + 1\r\n\r\n        # \u9053\u306e\u751f\u6210\r\n        field = self.roadfiller.fill_with_road(\r\n            field, x, y, id=road_id, mode='create',\r\n            is_show=is_show,\r\n            delay=delay, unit=unit,\r\n            )\r\n        \r\n        # \u9053\u306eid \u3092\u5168\u30661\u306b\u5909\u63db\u3057\u3066\u51fa\u529b\r\n        field_out = field.copy()\r\n        field_out[field &gt; 0] = 1\r\n\r\n        return field_out\r\n\r\n\r\nclass MazeSolver:\r\n    \"\"\"\r\n    \u8ff7\u8def\u3092\u89e3\u304f\u30af\u30e9\u30b9\r\n    \"\"\"\r\n    def __init__(self, field, start, goal):\r\n        self.field = field.copy()\r\n        self.start_xy = start\r\n        self.goal_xy = goal\r\n        self.xy = self.start_xy\r\n        max_col = int(self.field.shape[1] \/ 2)\r\n        self.roadfiller =RoadFiller(\r\n            max_col=max_col,\r\n            goal_xy=goal,\r\n            start_xy=start,\r\n            )\r\n\r\n    def solve_maze(self, is_show=True, unit=10, delay=100):\r\n        \"\"\"\r\n        \u901a\u8def\u30920\u3001\u58c1\u30921\u3068\u3059\u308b\r\n        \u901a\u8def\u306b\u6cbf\u3063\u3066\u9032\u3080\u3001\u5206\u5c90\u70b9\u306b\u6765\u305f\u3089\u30b4\u30fc\u30eb\u304c\u8fd1\u304f\u306a\u308b\u65b9\u3092\u9078\u3076\r\n\r\n        \u8ff7\u8def\u751f\u6210\u30af\u30e9\u30b9\u3068\u540c\u3058\u3001RoadFiller\u30af\u30e9\u30b9\u3092\u5185\u90e8\u3067\u4f7f\u7528\r\n\r\n        Parameters\r\n        ----------\r\n        unit: int\r\n            \u753b\u50cf\u751f\u6210\u6642\u306e\u30bb\u30eb\u30b5\u30a4\u30ba\r\n        delay: int\r\n            \u30a2\u30cb\u30e1\u30fc\u30b7\u30e7\u30f3\u6642\u306e\u9045\u5ef6(ms)\r\n\r\n        Returns\r\n        -------\r\n        field_out: 2d numpuy.array\r\n            \u89e3\u3044\u305f\u8ff7\u8def\r\n            0\u304c\u58c1\r\n            1\u304c\u901a\u8def\r\n            2\u4ee5\u4e0a\u304c\u901a\u3063\u305f\u8ecc\u8de1\r\n        \"\"\"\r\n\r\n        field = self.field.copy()\r\n        x, y = self.start_xy\r\n\r\n        # \u9053\u306eid\u306f2\u304b\u3089\u958b\u59cb\r\n        road_id = 2\r\n        field[y, x] = road_id\r\n\r\n        # \u9053\u306e\u751f\u6210ds\r\n        field_out = self.roadfiller.fill_with_road(\r\n            field, x, y, id=road_id, mode='solve',\r\n            is_show=is_show,\r\n            delay=delay, unit=unit,\r\n            )\r\n        return field_out\r\n   \r\n        \r\nclass RoadFiller:\r\n    \"\"\"\r\n    \u6307\u5b9a\u3057\u305fid\u306e\u9818\u57df\u3092\u3001\u9053\u3092\u5206\u5c90\u3055\u305b\u306a\u304c\u3089\u9053\u3067\u6e80\u305f\u3059\u30af\u30e9\u30b9\r\n    \"\"\"\r\n    def __init__(self, max_col=10, mode='create', goal_xy=None, start_xy=None):\r\n        self.render = Render(\r\n            max_col=max_col, mode=mode, \r\n            goal_xy=goal_xy, start_xy=start_xy,\r\n            )\r\n        self.reach_goal = False\r\n        self.goal_xy = goal_xy\r\n        self.start_xy = start_xy\r\n\r\n    def fill_with_road(\r\n        self, field, x, y, id=1, mode='create',\r\n        is_show=True, delay=100, unit=10,\r\n        ):\r\n        \"\"\"\r\n        0\u306e\u9818\u57df\u3092\u9053\u3067\u6e80\u305f\u3059\r\n        \u8ff7\u8def\u3092\u751f\u6210\u3059\u308b\u672c\u4f53\r\n        \u8ff7\u8def\u3092\u89e3\u304f\u3068\u304d\u306b\u3082\u4f7f\u7528\r\n\r\n        Parameters\r\n        ----------\r\n        field: 2d numpy.array\r\n            \u8ff7\u8def\u306e\u30d5\u30a3\u30fc\u30eb\u30c9\r\n            0\u306e\u9818\u57df\u306b\u9053\u304c\u4f5c\u3089\u308c\u308b\r\n        x, y: int\r\n            \u30b9\u30bf\u30fc\u30c8\u5730\u70b9\r\n        id: int\r\n            \u4f5c\u308b\u9053\u306eid \r\n        mode: str\r\n            'create': \u8ff7\u8def\u3092\u4f5c\u308b\r\n            'solve': \u8ff7\u8def\u3092\u89e3\u304f\r\n        is_show: bool\r\n            True: \u30a2\u30cb\u30e1\u30fc\u30b7\u30e7\u30f3\u3092\u51fa\u3059\r\n        \r\n        Returens\r\n        --------\r\n        field: 2d numpy.array\r\n            \u9053\u304c\u751f\u6210\u3055\u308c\u305f\u30d5\u30a3\u30fc\u30eb\u30c9\r\n        \"\"\"\r\n\r\n        # \u30b4\u30fc\u30eb\u306b\u5230\u9054\u3057\u305f\u3089\u7d42\u4e86\r\n        if self.reach_goal is True:\r\n            return field\r\n\r\n        self.field = field.copy()\r\n        self.delay = delay\r\n        self.unit = unit\r\n        \r\n        # \u958b\u59cb\u5730\u70b9\u304c0\u306a\u3089 id \u3068\u3059\u308b\r\n        if self.field[y, x] == 0:\r\n            self.field[y, x] = id\r\n\r\n        # xy \u306e\u5c65\u6b74 (B)\u3067\u4f7f\u7528\r\n        xy_history = [(x, y)]\r\n\r\n        # (A)\r\n        while True:\r\n            # x, y \u306e\u5468\u56f2\u3092\u8abf\u3079\u3066\u3001\u9053\u304c\u4f38\u3070\u305b\u308b\u306a\u3089\u3070\u4f38\u3070\u3059\r\n            res, x, y, fields = self.extend_road(\r\n                self.field, x, y, id, mode=mode,\r\n                )\r\n            self.field = fields[-1]\r\n\r\n            if res == 'stretched':\r\n                # \u9053\u3092\u4f38\u3070\u3057\u305f\u5834\u5408\u306f\u3001xy \u3092\u8a18\u9332\u3057\u3066\u7e70\u308a\u8fd4\u3059\r\n                xy_history.append((x, y))\r\n\r\n                # \u63cf\u753b\r\n                if is_show is True:\r\n                    if self.delay &gt; 50:\r\n                        for ff in fields:\r\n                            self.render.draw(\r\n                                ff, delay=self.delay, unit=self.unit,\r\n                                )\r\n                    else:\r\n                        self.render.draw(\r\n                            fields[-1], delay=self.delay, unit=self.unit,\r\n                            )\r\n\r\n                # \u30b4\u30fc\u30eb\u5224\u5b9a\r\n                if mode == 'solve':\r\n                    if x == self.goal_xy[0] and y == self.goal_xy[1]:\r\n                        # \u30b4\u30fc\u30eb\u306b\u8fbf\u308a\u7740\u3044\u305f\u3089\u7d42\u4e86\r\n                        self.reach_goal = True\r\n                        return self.field\r\n\r\n                continue\r\n\r\n            # \u884c\u304d\u6b62\u307e\u308a\u306b\u6765\u305f\u3089\r\n            # \u30eb\u30fc\u30d7\u304b\u3089\u629c\u3051\u3066(B)\u3078\r\n            if res == 'deadend':\r\n                break\r\n        \r\n        # (B)\r\n        # \u5c65\u6b74\u3092\u4e00\u3064\u305a\u3064\u3082\u3069\u3063\u305f\u5730\u70b9\u304b\u3089\u3001\u884c\u304d\u6b62\u307e\u308a\u307e\u3067\u9053\u3092\u4f38\u3070\u3059\r\n        xy_history.pop(-1)\r\n        xy_history.reverse()\r\n        for xy in xy_history:\r\n            x = xy[0]\r\n            y = xy[1]\r\n            self.fill_with_road(\r\n                self.field, x, y, id=id + 1, mode=mode,\r\n                is_show=is_show,\r\n                delay=self.delay, unit=self.unit,\r\n                )\r\n        \r\n        return self.field\r\n\r\n    def extend_road(\r\n        self, field, x, y, id, mode='create',\r\n        ):\r\n        \"\"\"\r\n        field\u306e(x,y)\u3092\u4e2d\u5fc3\u3068\u3057\u3066\u3001\r\n        \u4e0a\u4e0b\u5de6\u53f3\u306e4\u65b9\u5411\u3092\u8abf\u3079\u3001\r\n        id_brank \u304c\u3042\u3063\u305f\u3089\u9053\u3092\u4f38\u3070\u3059\r\n        'create'\u306e\u3068\u304did_brank = 0\r\n        'solve'\u306e\u3068\u304did_brank = 1\r\n\r\n        Parameters\r\n        ----------\r\n        field: 2d numpy.array\r\n            \u30d5\u30a3\u30fc\u30eb\u30c9\r\n        x, y: int\r\n            \u958b\u59cb\u5730\u70b9\r\n        id: int\r\n            \u9053\u306eid\r\n        mode: str\r\n            'create': \u8ff7\u8def\u3092\u4f5c\u308b\r\n            'solve': \u8ff7\u8def\u3092\u89e3\u304f\r\n        \r\n        Returens\r\n        --------\r\n        res: str\r\n            'stretched': \u9053\u3092\u4f38\u3070\u3057\u305f\r\n            'deaded': \u884c\u304d\u6b62\u307e\u308a\u3060\u3063\u305f\r\n        next_x, next_y: int\r\n            'streatched' \u3067\u4f38\u3070\u3057\u305f\u5148\u306e\u5ea7\u6a19\r\n        fields: list of 2d numpy.array\r\n            \u6bb5\u968e\u7684\u306b\u9053\u3092\u4f38\u3070\u3057\u305f\u3068\u304d\u306efield\u306e\u30ea\u30b9\u30c8\r\n            \uff08\u30a2\u30cb\u30e1\u30fc\u30b7\u30e7\u30f3\u7528\uff09\r\n        \"\"\"\r\n        if mode == 'create':\r\n            id_brank = 0\r\n        elif mode == 'solve':\r\n            id_brank = 1\r\n        else:\r\n            raise ValueError('mode\u304c\u9055\u3044\u307e\u3059')\r\n\r\n        # 4\u65b9\u5411\u306ex, y \u306e\u5897\u52a0\u5206\r\n        dd = [\r\n            (1, 0),\r\n            (-1, 0),\r\n            (0, 1),\r\n            (0, -1),\r\n        ]\r\n\r\n        # \u5909\u6570\u6e96\u5099        \r\n        n_h, n_w = field.shape[:2]\r\n        next_field = field.copy()\r\n        pre_field = field.copy()\r\n\r\n        # 4\u65b9\u5411\u306e\u72b6\u614b\u3092\u8abf\u3079\u308b\r\n        dd_res = [''] * 4 # \u7d50\u679c\u306e\u683c\u7d0d\u5909\u6570\r\n        for id_dir in range(4):\r\n            x1 = x + dd[id_dir][0] * 2\r\n            y1 = y + dd[id_dir][1] * 2\r\n            x0 = x + dd[id_dir][0]\r\n            y0 = y + dd[id_dir][1]\r\n\r\n            if x1 &lt; 0 or n_w &lt;= x1:\r\n                # \u6a2a\u65b9\u5411\u306e\u306f\u307f\u51fa\u3057\r\n                dd_res[id_dir] = 'out'\r\n                continue\r\n\r\n            if y1 &lt; 0 or n_h &lt;= y1:\r\n                # \u7e26\u65b9\u5411\u306e\u306f\u307f\u51fa\u3057\r\n                dd_res[id_dir] = 'out'\r\n                continue\r\n\r\n           \r\n            if (mode == 'create' and field[y1, x1] == id_brank) or \\\r\n                (mode == 'solve' and field[y0, x0] == id_brank): \r\n                # \u30d6\u30e9\u30f3\u30af(\u9053\u3092\u4f38\u3070\u305b\u308b)\r\n                dd_res[id_dir] = 'brank'\r\n                continue\r\n                \r\n\r\n            # \u9053\u3092\u4f38\u3070\u305b\u306a\u3044\r\n            dd_res[id_dir] = 'no'\r\n\r\n        # \u30d6\u30e9\u30f3\u30af\u3042\u3063\u305f\u3089\u305d\u3053\u306b\u9053\u3092\u4f38\u3070\u3059\r\n        ids_dir = [i for i, x in enumerate(dd_res) if x == 'brank']\r\n        if len(ids_dir) &gt; 0:\r\n            res = 'stretched'\r\n            if mode == 'create':\r\n                # \u30e9\u30f3\u30c0\u30e0\u3067\u9078\u3076\r\n                id_dir = random.sample(ids_dir, 1)[0]\r\n            elif mode == 'solve':\r\n                # \u30b4\u30fc\u30eb\u306b\u8fd1\u304f\u306a\u308b\u65b9\u3092\u9078\u3076\r\n                dist = []\r\n                for i, id_dir in enumerate(ids_dir):\r\n                    x0 = x + dd[id_dir][0]\r\n                    y0 = y + dd[id_dir][1]\r\n                    dist.append((x0 - self.goal_xy[0])**2 + (y0 - self.goal_xy[1]) ** 2)\r\n                iid = dist.index(min(dist)) # \u6700\u5c0f\u306e\u8981\u7d20\u306eindex \u3092\u8fd4\u3059\r\n                id_dir = ids_dir[iid]\r\n            else:\r\n                raise ValueError('mode\u304c\u9055\u3044\u307e\u3059')\r\n\r\n            x1 = x + dd[id_dir][0] * 2\r\n            y1 = y + dd[id_dir][1] * 2\r\n            x0 = x + dd[id_dir][0]\r\n            y0 = y + dd[id_dir][1]\r\n            pre_field[y0, x0] = id  # \u30a2\u30cb\u30e1\u30fc\u30b7\u30e7\u30f3\u7528\u306e\u9014\u4e2d\u72b6\u614b\r\n            next_field[y1, x1] = id\r\n            next_field[y0, x0] = id # \u6700\u7d42\u7684\u306a\u72b6\u614b\r\n            next_x = x1\r\n            next_y = y1\r\n            fields = [pre_field, next_field]\r\n\r\n            return res, next_x, next_y, fields\r\n\r\n        # \u884c\u304d\u6b62\u307e\u308a\r\n        res = 'deadend'\r\n        next_x = None\r\n        next_y = None\r\n        fields = [pre_field, next_field]\r\n        return res, next_x, next_y, fields\r\n\r\n\r\nclass Render():\r\n    \"\"\"\r\n    \u753b\u50cf\u751f\u6210\u3001\u8868\u793a\r\n    \"\"\"\r\n    def __init__(\r\n        self, max_col=10, \r\n        goal_xy=None, start_xy=None, mode='create',\r\n        ):\r\n        self.max_col = max_col # \u8272\u306e\u7a2e\u985e\u306e\u4e0a\u9650\r\n        self.goal_xy=goal_xy\r\n        self.start_xy=start_xy\r\n        self.mode=mode\r\n\r\n        self.colorpalette = sns.color_palette(\r\n            \"hls\", n_colors = self.max_col,\r\n            )\r\n\r\n    def draw(\r\n        self,\r\n        field,\r\n        unit=10,\r\n        is_show=True, delay=0,\r\n        unicol=None,\r\n        start_xy=None,\r\n        goal_xy=None,\r\n        ):\r\n        \"\"\"\r\n        \u8ff7\u8def\u306e\u753b\u50cf\u751f\u6210\r\n        \"\"\"\r\n\r\n        if start_xy is not None:\r\n            self.start_xy = start_xy\r\n        if goal_xy is not None:\r\n            self.goal_xy = goal_xy\r\n    \r\n        # field \u3092unit\u5206\u62e1\u5927\r\n        val = field\r\n        max_val = np.max(val)\r\n        val = val.astype(dtype=np.uint8)\r\n        val = cv2.resize(\r\n            val,\r\n            dsize=(0, 0),\r\n            fx=unit, fy=unit,\r\n            interpolation=cv2.INTER_NEAREST,\r\n            )\r\n        \r\n        #--- for video fix size\r\n        \"\"\"\r\n        val_bak = np.ones((440, 840), dtype=np.uint8) * 80\r\n        h, w = val.shape[:2]\r\n        val_bak[:h, :w] = val\r\n        val = val_bak\r\n        \"\"\"\r\n        # ----\r\n\r\n        img_r = val.copy()\r\n        img_g = val.copy()\r\n        img_b = val.copy()\r\n\r\n        # \u9053\u3092id\u6bce\u306b\u8272\u3092\u4ed8\u3051\u3066\u63cf\u753b\r\n        for v in range(max_val + 1):\r\n            if self.mode == 'create':\r\n                if v == 0: # \u30d6\u30e9\u30f3\u30af\uff08\u9053\u3092\u4f38\u3070\u3059\uff09\r\n                    col = (80, 80, 80)\r\n                elif v == 1: # \u58c1\uff08\u9053\u3092\u4f38\u3070\u3059\uff09\r\n                    col = (255, 255, 255)\r\n                else:\r\n                    ic = v % self.max_col\r\n                    col = np.array(self.colorpalette[ic]) * 255\r\n            elif self.mode == 'solve':\r\n                if v == 0: # \u58c1\r\n                    col = (80, 80, 80)\r\n                elif v == 1: # \u30d6\u30e9\u30f3\u30af\r\n                    col = (255, 255, 255)\r\n                else:\r\n                    ic = v % self.max_col\r\n                    col = np.array(self.colorpalette[ic]) * 255\r\n            else:\r\n                raise ValueError('mode \u304c\u9055\u3044\u307e\u3059')\r\n\r\n            img_r[val == v] = col[0]\r\n            img_g[val == v] = col[1]\r\n            img_b[val == v] = col[2]\r\n\r\n        h, w = val.shape\r\n        img = np.zeros((h, w, 3), dtype=np.uint8)\r\n        img[:, :, 0] = img_b\r\n        img[:, :, 1] = img_g\r\n        img[:, :, 2] = img_r\r\n\r\n        # \u30b9\u30bf\u30fc\u30c8\u5730\u70b9\u306e\u76ee\u5370\r\n        if self.start_xy is not None:\r\n            x = int(self.start_xy[0] * unit + unit \/ 2)\r\n            y = int(self.start_xy[1] * unit + unit \/ 2)\r\n            r = int(0.45 * unit)\r\n            col = (100, 100, 200)\r\n            img = cv2.circle(img, (x, y), r, col, -1)\r\n\r\n        # \u30b4\u30fc\u30eb\u5730\u70b9\u306e\u76ee\u5370\r\n        if self.goal_xy is not None:\r\n            x = int(self.goal_xy[0] * unit + unit \/ 2)\r\n            y = int(self.goal_xy[1] * unit + unit \/ 2)\r\n            r = int(0.45 * unit)\r\n            col = (100, 200, 100)\r\n            img = cv2.circle(img, (x, y), r, col, -1)\r\n\r\n        # \u30a2\u30cb\u30e1\u30fc\u30b7\u30e7\u30f3\u8868\u793a\r\n        if is_show:\r\n            cv2.imshow('img', img)\r\n            INPUT = cv2.waitKey(delay) &amp; 0xFF\r\n            if INPUT == ord('q'):\r\n                sys.exit()\r\n\r\n        return img\r\n\r\n\r\nif __name__ == '__main__':\r\n\r\n        prms = {\r\n            0: (10, 5, 40, 100),\r\n            1: (20, 10, 20, 50),\r\n            2: (40, 20, 10, 1),\r\n        }\r\n\r\n        # for video\r\n        \"\"\"\r\n        cv2.imshow('img', np.ones((440, 840, 3), dtype=np.uint8) * 80)\r\n        cv2.waitKey(0)\r\n        \"\"\"\r\n\r\n        for i in range(100):\r\n            # \u30d1\u30e9\u30e1\u30fc\u30bf\u306e\u53d6\u5f97\r\n            w, h, u, d = prms[i % len(prms)]\r\n\r\n            # \u8ff7\u8def\u751f\u6210\u30af\u30e9\u30b9\u306e\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u751f\u6210\r\n            maze = MazeCreater(size_w=w, size_h=h)\r\n\r\n            # \u8ff7\u8def\u3092\u30a2\u30cb\u30e1\u30fc\u30b7\u30e7\u30f3\u3055\u305b\u306a\u304c\u3089\u751f\u6210\r\n            field = maze.generate_maze(is_show=True, unit=u, delay=d)\r\n\r\n            # \u30b9\u30bf\u30fc\u30c8\u3068\u30b4\u30fc\u30eb\u5730\u70b9\u3092\u4f5c\u6210\r\n            f_h, f_w = field.shape[:2]\r\n            start_xy = (1, 1)\r\n            goal_xy = (f_w - 2, f_h - 2)\r\n\r\n            # \u5b8c\u6210\u3057\u305f\u8ff7\u8def\u3092\u8868\u793a\r\n            img = maze.roadfiller.render.draw(\r\n                field, unit=u, delay=1000, unicol=(255, 255, 255),\r\n                start_xy=start_xy, goal_xy=goal_xy,\r\n                )\r\n\r\n            # \u8ff7\u8def\u89e3\u304d\u306e\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u751f\u6210\r\n            solver = MazeSolver(\r\n                field, start=start_xy, goal=goal_xy)\r\n            # \u8ff7\u8def\u3092\u30a2\u30cb\u30e1\u30fc\u30b7\u30e7\u30f3\u3055\u305b\u306a\u304c\u3089\u89e3\u304f\r\n            map = solver.solve_maze(is_show=True, unit=u, delay=d)\r\n            # \u89e3\u3044\u305f\u8ff7\u8def\u3092\u8868\u793a\r\n            solver.roadfiller.render.draw(map, unit=u, delay=1000)\r\n\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u8ff7\u8def\u3092\u81ea\u52d5\u3067\u4f5c\u3063\u3066\u3001\u81ea\u52d5\u3067\u89e3\u304f\u3001\u305d\u3093\u306a\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u4f5c\u308a\u305f\u3044\u3068\u524d\u3005\u304b\u3089\u601d\u3063\u3066\u3044\u307e\u3057\u305f\u3002 \u8a66\u884c\u932f\u8aa4\u3057\u306a\u304c\u3089\u4f5c\u3063\u3066\u307f\u308b\u3068\u3001\u306a\u3093\u3068\u3001\u4f5c\u308b\u306e\u3082\u89e3\u304f\u306e\u3082\u540c\u3058\u30a2\u30eb\u30b4\u30ea\u30ba\u30e0\u3067\u3067\u304d\u308b\u3053\u3068\u304c\u5206\u304b\u308a\u307e\u3057\u305f\u3002 youtube \u52d5\u753b\u306b\u3082up\u3057\u307e\u3057\u305f\u3002\u3053\u3061\u3089\u306f\u8ff7\u8def\u306e\u30b5\u30a4\u30ba\u3092\u5909\u3048\u306a\u304c\u3089\u3001\u8ff7\u8def\u3092\u4f5c\u3063\u3066\u3001\u305d\u308c\u3092\u89e3 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":3069,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[56,37,3,2,20,4,33],"tags":[],"class_list":{"0":"post-3068","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-00-","8":"category-ai","9":"category-opencv","10":"category-python","11":"category-20","12":"category-math","13":"category-33","14":"cat-56-id","15":"cat-37-id","16":"cat-3-id","17":"cat-2-id","18":"cat-20-id","19":"cat-4-id","20":"cat-33-id","21":"has_thumb"},"_links":{"self":[{"href":"http:\/\/itoshi.main.jp\/tech\/wp-json\/wp\/v2\/posts\/3068","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/itoshi.main.jp\/tech\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/itoshi.main.jp\/tech\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/itoshi.main.jp\/tech\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/itoshi.main.jp\/tech\/wp-json\/wp\/v2\/comments?post=3068"}],"version-history":[{"count":10,"href":"http:\/\/itoshi.main.jp\/tech\/wp-json\/wp\/v2\/posts\/3068\/revisions"}],"predecessor-version":[{"id":3072,"href":"http:\/\/itoshi.main.jp\/tech\/wp-json\/wp\/v2\/posts\/3068\/revisions\/3072"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/itoshi.main.jp\/tech\/wp-json\/wp\/v2\/media\/3069"}],"wp:attachment":[{"href":"http:\/\/itoshi.main.jp\/tech\/wp-json\/wp\/v2\/media?parent=3068"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/itoshi.main.jp\/tech\/wp-json\/wp\/v2\/categories?post=3068"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/itoshi.main.jp\/tech\/wp-json\/wp\/v2\/tags?post=3068"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}