{"id":342,"date":"2017-06-14T14:46:06","date_gmt":"2017-06-14T05:46:06","guid":{"rendered":"https:\/\/do-gugan.com\/swift\/?p=342"},"modified":"2019-01-17T03:26:28","modified_gmt":"2019-01-16T18:26:28","slug":"%e3%83%91%e3%83%a9%e3%83%a1%e3%83%bc%e3%82%bf-8-2%e3%81%a4%e3%81%ae%e5%b1%b1","status":"publish","type":"post","link":"https:\/\/do-gugan.com\/swift\/?p=342","title":{"rendered":"\u30d1\u30e9\u30e1\u30fc\u30bf 8. 2\u3064\u306e\u5c71"},"content":{"rendered":"<p>\u5927\u304d\u304f3\u7a2e\u985e\u306e\u9053\u304b\u3089\u6210\u3063\u3066\u3044\u308b\u30b9\u30c6\u30fc\u30b8\u3067\u3059\u3002\u4e21\u5074\u306e\u7802\u306e\u9053\u3001\u8349\u306e\u9053\u3001\u305d\u3057\u3066\u771f\u3093\u4e2d\u306e\u30d5\u30ed\u30fc\u30c8\u677f7\u679a\u3067\u69cb\u6210\u3055\u308c\u305f\u9053\u3067\u3059\u3002\u771f\u3093\u4e2d\u306e\u30d5\u30ed\u30fc\u30c8\u677f\u306e\u9053\u30921\u6bb5\u968e\u4e0a\u3052\u3066\u3084\u308b\u3068\u3001\u4e21\u5074\u306e\u9053\u306e\u7247\u65b9\u306e\u7aef\u3068\u9ad8\u3055\u304c\u63c3\u3063\u3066\u3001\u6b69\u3044\u3066\u884c\u304d\u6765\u3067\u304d\u308b\u4e00\u672c\u9053\u306b\u306a\u308a\u307e\u3059\u3002\u306e\u3067\u3001N\u5b57\u306e\u3088\u3046\u306b\u5f80\u5fa9\u3057\u306a\u304c\u3089\u5b9d\u77f3\u3092\u898f\u5b9a\u6570\uff08totalGem\uff09\u96c6\u3081\u3066\u3044\u304d\u307e\u3059\u3002<br \/>\n\u307e\u305a\u30d5\u30ed\u30fc\u30c8\u677f\u306e\u4e0a\u3052\u4e0b\u3052\u4fc2\u306eex\u304f\u3093\uff08Expert\u578b\uff09\u3092\u4f5c\u308a\u3001\u30b9\u30a4\u30c3\u30c1\u524d\u306b\u79fb\u52d5\u3055\u305b\u307e\u3059\u3002\u5f7c\u306e\u4ed5\u4e8b\u306f\u30d5\u30ed\u30fc\u30c8\u677f\u30921\u6bb5\u7d42\u308f\u308a\u3060\u3051\u3067\u7d42\u308f\u308a\u3067\u3059\u3002<br \/>\n\u6b21\u306bch\u304f\u3093\uff08Character\u578b\uff09\u3092\u4f5c\u308a\u30b9\u30bf\u30fc\u30c8\u5730\u70b9\u306b\u79fb\u52d5\u3002\u4eca\u56de\u306f3\u3064\u306e\u9053\u306e\u305d\u308c\u305e\u308c\u3067\u3001\u7aef\u304b\u3089\u7aef\u307e\u3067\u79fb\u52d5\u3057\u3064\u3064\u5b9d\u77f3\u3092\u53d6\u308b\u52d5\u4f5c\u3092\u3072\u3068\u307e\u3068\u307e\u308a\u3068\u3057\u3001\u95a2\u6570jumpToEdge()\u3092\u4f5c\u308a\u307e\u3057\u305f\u3002\u7802\u306e\u9053\u3068\u8349\u306e\u9053\u306f\u6bb5\u5dee\u304c\u3042\u308b\u306e\u3067moveForward()\u3060\u3051\u3067\u306a\u304fjump()\u3082\u4f7f\u3044\u5206\u3051\u306a\u3051\u308c\u3070\u306a\u308a\u307e\u305b\u3093\uff08\u3076\u3063\u3061\u3083\u3051\u5168\u90e8jump()\u3067\u9032\u3081\u308b\u306e\u3067\u3059\u304c\u3001\u307e\u3041\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u306e\u7df4\u7fd2\u306a\u306e\u3067\u4e00\u5fdcif\u6587\u3067\u884c\u304d\u6b62\u307e\u308a\u304b\u3069\u3046\u304b\u3067\u5206\u5c90\u3055\u305b\u3066\u307e\u3059\uff09\u3002\u3068\u3063\u305f\u5b9d\u77f3\u306e\u6570\u306fgems\u3068\u3044\u3046\u5909\u6570\u3067\u8a18\u9332\u3057\u3066\u3044\u304d\u307e\u3059\u3002collectGem()\u3057\u305f\u3089\u5fc5\u305a+=1\u3057\u3066\u304a\u304d\u307e\u3057\u3087\u3046\u3002<\/p>\n<p>\u672c\u7de8\u3067\u306f\u300c\u898f\u5b9a\u6570\u306e\u5b9d\u77f3\u3092\u96c6\u3081\u308b\u300d\u306e\u304c\u30b4\u30fc\u30eb\u306a\u306e\u3067\u3001\u300c\u3068\u3063\u305f\u5b9d\u77f3\u6570gems\u304c\u898f\u5b9a\u6570totalGem\u306b\u6e80\u305f\u306a\u3044\u5834\u5408\u306f\u7e70\u308a\u8fd4\u3059\u300dwhile\u30eb\u30fc\u30d7\u3092\u30e1\u30a4\u30f3\u30eb\u30fc\u30d7\u3068\u3057\u3066\u3044\u307e\u3059\u3002\u305d\u306e\u4e2d\u3067jumpToEdge()\u3092\u547c\u3093\u3067\u4eca\u3044\u308b\u9053\u306e\u53cd\u5bfe\u5074\u306e\u7aef\u307e\u3067\u884c\u304d\u3001\u7aef\u306e\u884c\u304d\u6b62\u307e\u308a\u72b6\u6cc1\u306b\u5fdc\u3058\u3066\u5de6\u53f3\u306b\u5411\u304d\u3092\u304b\u3048\u308b\u5206\u5c90\u3092\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<p><strong>2019.1.17\u7de8\u96c6<\/strong><\/p>\n<p>Swift 4.2\u7248\u3067\u306f\u6607\u964d\u30b9\u30a4\u30c3\u30c1\u306e\u4f4d\u7f6e\u304c\u5909\u308f\u3063\u305f\u3088\u3046\u3067\u3001\u305d\u308c\u3092\u64cd\u4f5c\u3059\u308bex\u304f\u3093\u306e\u914d\u7f6e\u5ea7\u6a19\u3092atColumn:1 row:4\u304b\u3089AtColumn:0 row:4\u306b\u5909\u66f4\u3057\u307e\u3057\u305f\u3002<\/p>\n<pre class=\"lang:swift decode:true  crayon-selected\">let totalGem = randomNumberOfGems \/\/totalGem\u306b\u53d6\u308b\u3079\u304d\u5b9d\u77f3\u306e\u6570\u304c\u30bb\u30c3\u30c8\u3055\u308c\u308b\uff08\u6bce\u56de\u9055\u3046\uff09\n\n\/\/\u6607\u964d\u30b9\u30a4\u30c3\u30c1\u3092\u64cd\u4f5c\u3059\u308bex\u304f\u3093\u3092\u4f5c\u6210\u3057\u3066\u914d\u7f6e\nlet ex = Expert()\n\/\/world.place(ex, facing: north, atColumn: 1, row: 4) \/\/\u65e7\u30d0\u30fc\u30b8\u30e7\u30f3\u3067\u306fatColumn:1\u3067\u3057\u305f\nworld.place(ex, facing: north, atColumn: 0, row: 4) \n\/\/\u5b9d\u77f3\u3092\u53d6\u308bch\u304f\u3093\u3092\u4f5c\u6210\u3057\u3066\u914d\u7f6e\nlet ch = Character()\nworld.place(ch, facing: north, atColumn: 3, row: 0)\n\nvar gems = 0  \/\/\u53d6\u3063\u305f\u5b9d\u77f3\u306e\u6570\u3092\u8a18\u9332\u3059\u308b\u5909\u6570\n\n\/\/\u4eca\u3044\u308b\u9053\u3092\u7a81\u304d\u5f53\u305f\u308a\u307e\u3067\u9032\u307f\u3064\u3064\u3001\u5b9d\u77f3\u304c\u3042\u308c\u3070\u53d6\u308b\u95a2\u6570\nfunc jumpToEdge() {\n    for i in 1 ... 6 {\n        \/\/\u5b9d\u77f3\u304c\u3042\u308a\u3001\u304b\u3064\u307e\u3060\u53d6\u308a\u8db3\u308a\u306a\u3051\u308c\u3070\n        if ch.isOnGem &amp;&amp; gems &lt; totalGems{\n            ch.collectGem()\n            gems += 1 \/\/\u53d6\u3063\u305f\u3089\u30ab\u30a6\u30f3\u30bf\u30821\u5897\u3084\u3057\u3066\u3044\u304f\n        }\n        \/\/\u884c\u304d\u6b62\u307e\u308a\u306a\u3089\u30b8\u30e3\u30f3\u30d7\u3001\u3067\u306a\u3051\u308c\u3070\u524d\u9032\n        if ch.isBlocked {\n            ch.jump()\n        } else {\n            ch.moveForward()\n        }\n    }\n}\n\nex.turnLock(up: true, numberOfTimes: 1) \/\/ex\u304f\u3093\u306b\u30d5\u30ed\u30fc\u30c8\u677f\u3092\u64cd\u4f5c\u3055\u305b\u308b\n\n\/\/\u3053\u3053\u304b\u3089\u672c\u7de8\n\/\/\u898f\u5b9a\u6570\u306e\u5b9d\u77f3\u3092\u96c6\u3081\u3066\u306a\u3044\u3046\u3061\u306f\u30eb\u30fc\u30d7\nwhile gems != totalGems {\n    jumpToEdge() \/\/\u4f5c\u6210\u3057\u305f\u95a2\u6570\u3092\u547c\u3073\u51fa\u3059\n    \/\/\u4e0a\u306e\u95a2\u6570\u3067\u7aef\u307e\u3066\u6765\u305f\u3089\u96a3\u306e\u9053\u306b\u79fb\u52d5\u3059\u308b\u3002\n    \/\/\u5de6\u53f3\u3068\u3082\u884c\u304d\u6b62\u307e\u308a\u306a\u3089\u632f\u308a\u8fd4\u308b\n    if ch.isBlockedLeft &amp;&amp; ch.isBlockedRight {\n        ch.turnRight()\n        ch.turnRight()\n    \/\/\u53f3\u304c\u884c\u304d\u6b62\u307e\u308a\u306a\u3089\u5de6\u306e\u9053\u3078\n    } else if ch.isBlockedRight {\n        ch.turnLeft()\n        ch.moveForward()\n        ch.turnLeft()\n    \/\/\u5de6\u304c\u884c\u304d\u6b62\u307e\u308a\u306a\u3089\u53f3\u306e\u9053\u3078\n    } else if ch.isBlockedLeft {\n        ch.turnRight()\n        ch.moveForward()\n        ch.turnRight()\n    }\n}\n<\/pre>\n<script type=\"text\/javascript\">amzn_assoc_ad_type =\"responsive_search_widget\"; amzn_assoc_tracking_id =\"doguganprojec-22\"; amzn_assoc_marketplace =\"amazon\"; amzn_assoc_region =\"JP\"; amzn_assoc_placement =\"\"; amzn_assoc_search_type = \"search_widget\";amzn_assoc_width =\"500\"; amzn_assoc_height =\"400\"; amzn_assoc_default_search_category =\"\"; amzn_assoc_default_search_key =\"iPad\";amzn_assoc_theme =\"light\"; amzn_assoc_bg_color =\"FFFFFF\"; <\/script><script src=\"\/\/z-fe.amazon-adsystem.com\/widgets\/q?ServiceVersion=20070822&Operation=GetScript&ID=OneJS&WS=1&Marketplace=JP\"><\/script>","protected":false},"excerpt":{"rendered":"<p>\u5927\u304d\u304f3\u7a2e\u985e\u306e\u9053\u304b\u3089\u6210\u3063\u3066\u3044\u308b\u30b9\u30c6\u30fc\u30b8\u3067\u3059\u3002\u4e21\u5074\u306e\u7802\u306e\u9053\u3001\u8349\u306e\u9053\u3001\u305d\u3057\u3066\u771f\u3093\u4e2d\u306e\u30d5\u30ed\u30fc\u30c8\u677f7\u679a\u3067\u69cb\u6210\u3055\u308c\u305f\u9053\u3067\u3059\u3002\u771f\u3093\u4e2d\u306e\u30d5\u30ed\u30fc\u30c8\u677f\u306e\u9053\u30921\u6bb5\u968e\u4e0a\u3052\u3066\u3084\u308b\u3068\u3001\u4e21\u5074\u306e\u9053\u306e\u7247\u65b9\u306e\u7aef\u3068\u9ad8\u3055\u304c\u63c3\u3063\u3066\u3001\u6b69\u3044\u3066\u884c\u304d\u6765\u3067\u304d\u308b\u4e00\u672c\u9053\u306b\u306a &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/do-gugan.com\/swift\/?p=342\" class=\"more-link\"><span class=\"screen-reader-text\">&#8220;\u30d1\u30e9\u30e1\u30fc\u30bf 8. 2\u3064\u306e\u5c71&#8221; \u306e<\/span>\u7d9a\u304d\u3092\u8aad\u3080<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,12],"tags":[],"class_list":["post-342","post","type-post","status-publish","format-standard","hentry","category-learncode2","category-parameter"],"_links":{"self":[{"href":"https:\/\/do-gugan.com\/swift\/index.php?rest_route=\/wp\/v2\/posts\/342","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/do-gugan.com\/swift\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/do-gugan.com\/swift\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/do-gugan.com\/swift\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/do-gugan.com\/swift\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=342"}],"version-history":[{"count":3,"href":"https:\/\/do-gugan.com\/swift\/index.php?rest_route=\/wp\/v2\/posts\/342\/revisions"}],"predecessor-version":[{"id":501,"href":"https:\/\/do-gugan.com\/swift\/index.php?rest_route=\/wp\/v2\/posts\/342\/revisions\/501"}],"wp:attachment":[{"href":"https:\/\/do-gugan.com\/swift\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=342"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/do-gugan.com\/swift\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=342"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/do-gugan.com\/swift\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=342"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}