æ¡æã¿ã¼ãã«ã§æ´å°ããï¼ãï¼8ï¼å±±ãååãã¦ç©ºæ´ããã£ãã¨ãã®å¯¾ç
- チュートリアル「採掘タートルで整地する」
- (7) ï¼ï¼ (8)ãã®è¨äº ï¼ï¼ (9) ã¾ã
é ããè¨ã訳
å é±æ«ã«é£è¼ã®ç¶ããæ¸ãã¨è¨ãã¾ããããé ããªã£ã¦ãã¿ã¾ããã
è¨äºã¯ã§ãã¦ããã®ã§ããã説æç¨ã®SSç»åæ®ãã®ãé¢åã§æ¾ç½®ãã¦ã¾ããã
ããã»ã©æ®ã£ã¦ããã®ã§ãå ¬éã§ãã
ååã¾ã§ã®ã話
ååã§ãé«ããèªåèªèãã¤ã¤èªåååããããã°ã©ã ãç´¹ä»ãã¾ããã
ãã¨ãã°å¹å¸ã®ããå°ä¸ã§ä»¥ä¸ã®ã³ãã³ããæã¡è¾¼ãã ãã§ãããã°ã©ã éå§å°ç¹ã®ä½ç½®ã¨é«ããåºæºã¨ãã¦ã1ãã£ã³ã¯ï¼16x16ï¼ç¯å²ã®ä¸ãåããå¹³ãã«æ´å°ãã¦ããã¾ã
> cutland 16 16
çæãè£çµ¦ãããã¸ãã¯ã¯å ¥ãã¦ããªãã®ã§ãããã°ã©ã éå§åã«ãããããä½è£ãæã£ã¦è£çµ¦ãã¦ããã¦ãã ããã
ã¤ã³ãã³ããªã«æ¾æã¨ãã§ã¹ããå ¥ãã¦ããã¨æ¾æèªåè¨ç½®ï¼ãã§ã¹ãã«ã¢ã¤ãã åç´ãã¦ãããã¨ãã便å©ãªæ©è½ãã¤ãã¦ãã¾ãã
ãããåé¡ç¹ã
ãã®ããã«ä¾¿å©ãªããã°ã©ã ãªã®ã§ãããå®éã«ä½¿ã£ã¦ã¿ãã¨ä»¥ä¸ã®ãããªåé¡ç¹ãã§ã¦ãã¾ãã
- æ°´ãããã¯ã®å¯¾çã¯ç¡ã
- 大ããªå±±ãåã£ã¦ããã¨ãã«ãä¸ã«ç©ºæ´ãããã¨æåããããã
ã¾ããã¿ã¼ãã«ã¯æ°´ãããã¯ãèªèã§ããªãããã«ãååç¯å²ã«æ± ãªã©ã®æ°´æºããããã¨ãã®ã¾ã¾æ°´ãä¸ã¾ã§ããã¼ãã¦ãã¾ãããã£ããè¨ç½®ããæ¾æãæµãã¦ãã¾ãã¾ãã
ãã®å¯¾çã¯é常ã«é¢åãªã®ã§ãæ¬ããã°ã©ã ã§ã¯èããªããã¨ã«ãã¾ãããããããæ°´æºãã¯åãç«ã¦ããªã©ãã¦å¯¾çãã¦ãã ããã
ããã¦å¾è ã®ç©ºæ´åé¡ãä»åã®èª²é¡ã¨ãªãã¾ããããå°ã詳ãã説æãã¾ãããã
空æ´ã®ä¸ã«ããã¨ãããæé«å°ç¹ãªã®ãå¤æã§ããªãåé¡
ååã®ããã°ã©ã ã¯ãé«ããèªåèªèããããã«ãã¿ã¼ãã«ãèªåã®æ£é¢ã¾ãã¯çä¸ã«ãããã¯ããããã©ãããå¤å¥ãã¦ããããªãã°1mä¸æããªããªãã°ãããæé«å°ç¹ã¨ããã¢ã«ã´ãªãºã ã使ãã¾ããã
ãã®ã¢ã«ã´ãªãºã ã¯å°ããªä¸ãåã£ã¦ãããã¡ã¯åé¡ãªãã®ã§ãããåã対象ã大è¦æ¨¡ã«ãªãã¨åé¡ãçºçããå¯è½æ§ãããã¾ãã
ãã¨ãã°å±±ãåã£ã¦ããéä¸ã§ãé«ãã2以ä¸ããæ·±ã空æ´ã«åºä¼ã£ãã¨ãã¾ãããã
以ä¸ã¯ãã®ç©ºæ´ã®æé¢å³ã ã¨æã£ã¦ãã ããã説æã®ããã®ã¢ãã«å³ã§ãã
ãã®ä½ç½®ã«ããã¿ã¼ãã«ã®æ£é¢ããã³çä¸ã«ã¯ãããã¯ãåå¨ãã¾ããã
ãã®ããå ã®ã¢ã«ã´ãªãºã ã§ã¯ããã®ä½ç½®ãæé«å°ç¹ã¨å¤æãã¦ãã¾ãã¾ãã
ãã®çµæã1æ©åé²ãã¾ããã¾ããããã§ãæ£é¢ã¨çä¸ã«ãããã¯ãåå¨ããªãã®ã§ãããã«1æ©åé²ãã¾ãã
2æ©åé²ãã¦åãã¦æ£é¢ã«å£ãçºè¦ããå£ä¼ãã«æé«å°ç¹ãæ¢ãã¦ä¸ã£ã¦ãããã¨ã«ãªãã¾ãã
æçµçã«ãæé«å°ç¹ã¨èª¤ã£ã¦èªèããæåã®2æ©åã¯çä¸ã«ãããã¯ãæ®ã£ãã¾ã¾ã¨ãªãã¾ãã
ãã¨ããã®2ãããã¯ã®ä¸ã«ã©ãã ãåãç³ãéãªã£ã¦ãããã¨ãã§ãã
ãã®åé¡ã¯ãã¿ã¼ãã«ã¯èªåã®é£æ¥ä½ç½®ãããããã¯ã®æç¡ãå¤å¥ã§ããªããã¨ãåå ã§ãããã®å¶ç´ããããããããã®åé¡ãæ ¹æ¬çã«è§£æ±ºãããã¨ã¯é£ããã®ã§ãã
ããã§ãè¡ãå½ããã°ã£ãããªããã次ã®ãããªæ¹æ³ã§å¯¾çãã¾ããã
対çæ¡
ä¸å³ãè¦ã¦ãããããã«ãåé¡ã¯ãã¿ã¼ãã«ã®çä¸ã®ä½ããªã空éã§ãã
ãã¨ãã°ä¸å³ã®ã¨ãã«ãã¿ã¼ãã«ãçä¸ã«1æ©ä¸æãã¦ãããªãã°ãçä¸ã«ãããã¯ããããã¨ãæ¤ç¥ãã¦ãæé«å°ç¹ã®æ¢ç´¢ãéå§ã§ãã¾ãã
ããã§ããåå¨ããã§ããã空æ´ã®é«ãï¼CAVE_HEIGHTï¼ã¨ãããã©ã¡ã¼ã¿ãç¨æããã¿ã¼ãã«ãæé«å°ç¹ã¨å¤æãããã¨ã«ãã®é«ãåã ãä¸æããã¦æ¬å½ã«æé«å°ç¹ãã©ãããåå¤æããããã¨ãã対çãæ¡ãã¾ãã
ãã®CAVE_HEIGHT
ã¨ãããã©ã¡ã¼ã¿ã¯ãããã°ã©ã å®è¡æã«ãªãã·ã§ã³ã¨ãã¦å
¥åãå¯è½ã§ãã大ããªå±±ãåãã¨ãã«ãé«ã3ã®ç©ºæ´ãããããããããã¨æã£ããã追å ã§3ãå¼æ°ã¨ãã¦æ¸¡ããã¨ã«ãã¾ãã
# 16x16ç¯å²ã®ä¸ãå±±ãååãå¹³ãã«ãããå±±ã®ä¸ã«é«ã3ã®ç©ºæ´ããã£ã¦ã対å¦å¯è½ã¨ãã > cutland 16 16 3
ãã®å¯¾çæ¡ã¯å®è£ ãç°¡åãªã®ã§ãããå®éã®ã¿ã¼ãã«ã®åãã¯ç¡é§ãªåããå¢ããã®ã§æ³¨æãå¿ è¦ã§ãã
ãªã«ãããã¨ãæããã«ä½ãç¡ãã¨ããã§ããç¡é§ã«3mä¸æããããã§ãããã
ãã¨ã話ããããªãã°ã強度ã®è¿ç¼ã®äººãããããç¡ãããç¶æ ã§å£ä¼ã移åããã®ã«çããããã§ãç¡é§ãªåãããã¦ãã¾ãã®ã¯ä»æ¹ããã¾ããã妥åãã¾ãããã
ã½ã¼ã¹ã³ã¼ã
ååã¨ã»ã¨ãã©åããªã®ã§çç¥ãç¡é§ã«ã³ã¼ãé·ãã§ããã»ã»ã»ã
ã½ã¼ã¹ã³ã¼ã解説
å®ã¯ãååããä¿®æ£ããç®æã¯ã»ã¼2ç®æã ãã§ãã
æ°ãã©ã¡ã¼ã¿CAVE_HEIGHT
ã®å
¥åå¦çé¨åã¨ãæé«å°ç¹ãæ¢ç´¢ããgoTop()
é¢æ°ã®ä¿®æ£ã ãã§ãã
é çªã«è§£èª¬ãã¾ãããã
ãã©ã¡ã¼ã¿å ¥åå¦çé¨å
local args = { ... } if #args == 3 or #args == 2 or #args==0 then DEPTH = tonumber(args[1]) or DEPTH WIDTH = tonumber(args[2]) or WIDTH CAVE_HEIGHT = tonumber(args[3]) or CAVE_HEIGHT -- expect the hight of cave else error('seichi <DEPTH> <WIDTH> (CAVE_HEIGHT)') end
ãã®ããã°ã©ã ã®å®è¡æ¹éã¯ã
- ããã°ã©ã å®è¡æã«å¥¥è¡ãã»å¹ ã®ãã©ã¡ã¼ã¿ãä¸ç·ã«å ¥åããï¼ç©ºæ´ã®é«ãã¯ãªãã·ã§ã³ï¼ã
- æ¯ååãå¤ãå ¥åããã®ãé¢åãªãã°ã½ã¼ã¹ã³ã¼ãã®å é ï¼CONFIGé¨åï¼ã«ããDEPTHãWIDTHãCAVE_HEIGHTã®ããã©ã«ãå¤ãæ¸ãæããã¨ãã©ã¡ã¼ã¿å ¥åãªãã§åãå®è¡ãã§ããã
ã¨ãªãã¾ãããããè¸ã¾ãã¦ä»¥ä¸ãã確èªãã ããã
- ããã°ã©ã å®è¡æã«ä¸ç·ã«å
¥åããããã©ã¡ã¼ã¿ãé
åargsã«ä»£å
¥ãã¦ãã¾ã
cutland 16 8 3
ã¨ããã°ã©ã å®è¡ãããã®ãªãã°ãargs=["16", "8", "3"]
ã¨ãªã£ã¦ãã¾ãã- ãã¤ã³ãã¯ãCCã§ã¯å ¥åãã©ã¡ã¼ã¿ã¯å ¨ã¦æååã¨ãã¦æ¸¡ãããç¹ã§ãã
- ifæã§é
åãããªãã¡ãã©ã¡ã¼ã¿ã®æ°ã2ã3ã0ã¨ãã ãå¦çãå®è¡ãããã以å¤ã®ã¨ãã«ã¯ã¨ã©ã¼ãè¿ãããã«ãã¦ãã¾ãã
- ãã©ã¡ã¼ã¿ãå ¨ãå ¥åããã¦ããªãã¨ãã«ã¯ããã®ã½ã¼ã¹ã³ã¼ãã®æåã®ã»ãã§è¨å®ãã¦ããããã©ã«ãå¤ã使ãã¾ãã
DEPTH = tonumber(args[1]) or DEPTH
- tonumber()é¢æ°ã§æååãæ°å¤ã«å¤æãã¦ãã¾ãã
- ã¾ããorã使ã£ããã®è¨æ³ã¯ãå ¥åå¤ããªãã£ãï¼tonumber(args[1])ãnilï¼ã¨ãã«ããã©ã«ãå¤ã使ã£ã¦å¤æ°ãåæåããLuaã®å ¸åçãªè¨æ³ã§ãã
æé«å°ç¹ãæ¢ç´¢ããé¢æ°
ããããããããããã«ãååã®ããã°ã©ã ã®ã³ã¼ãã¨æ¯è¼ãã¾ãããã
-- ååï¼ãæ£é¢ã¨ä¸ã«ãããã¯ããã£ãã1mä¸æããªããã°çµäºã function goTop() while turtle.detectUp() or turtle.detect() do surelyUp() --ä¸ã«ãããã¯ããã£ã¦ãç ´å£ãã¦å¿ ã1mä¸æããé¢æ° end end
ååã®ããã°ã©ã ã«ãããgoTop()é¢æ°ã¯ãéè¦ãªé¢æ°ãªããã¨ã¦ãã·ã³ãã«ã§ããã
ãããã ãwhileæã®ä½¿ãæ¹ãç¹æ®ãªã®ã§è£è¶³ããã¨ã
turtle.detectUp() or turtle.detect()
ã¨ããæ¡ä»¶å¼ã¯ãã¾ãä¸ã«ãããã¯ããã£ããTrueããªããã°æ£é¢ã®ãããã¯ã®æç¡ã§True/Falseãè¿ãã¾ãã
ãã®æ¡ä»¶å¼ã®å®è¡çµæã«ãã£ã¦ãwhileã®ä¸ãå®è¡ãããã©ããã決å®ãã¾ãã
以ä¸ã¯ä»åã®ä¿®æ£çã§ãã
-- ä»åã®ä¿®æ£ç function goTop() repeat for i=1,(CAVE_HEIGHT-1) do surelyUp() end local flag_rose = true while turtle.detectUp() or turtle.detect() do surelyUp() flag_rose = false -- execute from beginning, if detects a block end until flag_rose end
ä»åã®ä¿®æ£çãèªã¿è§£ãã«ã¯2ã¤ãã¤ã³ããããã¾ãã
ã¾ã1ã¤ç®ã®ãã¤ã³ãã¯ãé¢æ°å®è¡éå§ããã¨ããã«(CAVE_HEIGHT-1)ã ãä¸æãã¦ãããã¨ã§ãã
ãã¨ãç¡é§ãªåãã¨è¨ããããã¨æç¡ãè¨ããã¾ãããã¿ã¼ãã«ã¯å¼·åº¦ã®è¿ç¼ãªã®ã§ãããä»æ¹ãªãã
ãªããCAVE_HEIGHTãã1ãå¼ãã¦ããã®ã¯ãé«ãNã®ç©ºæ´ãªãã°(N-1)ä¸æããã°å¤©äºãããã¯ã«æ¥ããæ¤ç¥ã§ããããã§ãã
ä¸æå¾ãwhileã®æ¡ä»¶å¼ã§çä¸ã¨æ£é¢ã«ãããã¯ãããã確èªããæé«å°ç¹ãæ¢ç´¢ã»ä¸æããã¨ããã¾ã§ã1ã¤ã®ã»ããã¨ãªãã¾ãã
ããã¦2ã¤ç®ã®ãã¤ã³ãã¯ãrepeatæã使ããã¨ã§ãã®å¦çã»ãããä½åº¦ãç¹°ãè¿ãã¦ãããã¨ã§ãã
ãªãç¹°ãè¿ãå¿ è¦ãããã®ã§ããããï¼ã解説ãã¾ãããã以ä¸ã®ã¢ãã«å³ãã¿ã¦ãã ããã
ã¢ã«ãã¡ãããã®Fï¼ãããéãã¾ãã
空æ´ã®ä¸ã«ãããã«åãè¦æ¨¡ã®ç©ºæ´ããããã¨ã示ãã¦ãã¾ãã
ãã®å³ã§ã¯2ã¤ã§ãããå ´åã«ãã£ã¦ã¯åãè¦æ¨¡ã®ç©ºæ´ããã以ä¸ã®æ°ãä¸ã«ç©ã¿éãªã£ã¦ããå¯è½æ§ãããã¾ãã
ã¹ã¿ã¼ããããã¾ãä¸æãä¸ã«ãããã¯ãæ¤ç¥ããã®ã§æé«å°ç¹æ¢ç´¢ã®ããã«ããã«ä¸æã
ã¨ãããããä¸å³ã®ä½ç½®ã¾ã§ãã¾ããããããæé«å°ç¹ã§ããããï¼
ãããéãã¾ãããã
ä»åã®ä¿®æ£ã¢ã«ã´ãªãºã ã®èã¯ãä¸æ¦æé«å°ç¹ã¨å¤æãããã¨ã«ããã«æå®ããé«ãã ãä¸æããã®ã§ããã
ããããããã«ä¸æãã¦ãçä¸ã«ãããã¯æ¤ç¥ãâãæé«å°ç¹æ¢ç´¢ã®ããä¸æãâããããããã¯ããªãã®ã§ãããæé«å°ç¹ã§ããï¼ãããã¾ã ãã¡ã§ãã
ããã«ããä¸åº¦ä¸æãã¦ãçä¸ã»æ£é¢ã«ãããã¯ããªããâãä»åº¦ããæé«å°ç¹ã ï¼æ£ç¢ºã«ã¯æé«å°ç¹ããå°ãã ãä¸ï¼ï¼
ã¨åããã¨ã«ãªãã¾ãã
ä»åã¯ã空æ´ãä¸ã«2段ã§ããããæ¬çªã§ã¯3ã¤ããããã¾ããã4ã¤ããããã¾ãããããã¦ãã¿ã¼ãã«ã«ã¨ã£ã¦ããã®æã«ãªããªãã¨ããã¤ç©ã¿éãªã£ã¦ããã®ãããããªãã®ã§ãã
ãã®ãããç¹°ãè¿ãåæ°ãæ示çã«æå®ããforæã§ã¯ãªãrepeatï½untilæã使ã£ã¦ãã¾ãã
ç¹°ãè¿ãã¯ãflag_rose
*1ã®å¤ãtrueã®ã¨ãã«çµäºãã¾ãã
ã¾ãæåã«CAVE_HEIGHT-1ã ãä¸æãããã¨ã§flagãtrueã«ããç¹°ãè¿ãçµäºæ¡ä»¶ãæ´ãã¾ãã
ãã ãããã§ãä¸ãæ£é¢ã«ãããã¯ãè¦ã¤ãã¦ãã¾ãã¨æé«å°ç¹ã®æ¢ç´¢ãå§ã¾ã£ã¦ãã¾ãã®ã§flagãfalseã«ãã¦å度æåããç¹°ãè¿ãã¾ãã
ãã®ä¸é£ã®å¦çã«ãã£ã¦ã空æ´ãèæ ®ããæ¬å½ã®æé«å°ç¹ï¼ãã ããããããå°ãä¸ã®ä½ç½®ï¼ã¸ã¨ç§»åãããã¨ãã§ãã¾ãã
ãããã«
ããã¾ã§ã®é£è¼ã§ã奥è¡ãã»å¹ ã»é«ããæå®ãã¦ç´æ¹ä½ç©ºéãæãã¬ãããã°ã©ã ã¨ãä»åã®å¥¥è¡ãã»å¹ ã ããæå®ãã¦é«ããèªåèªèãã¦ååããããã°ã©ã ãç´¹ä»ãã¾ããã
æ¬å½ã®æ´å°ããã°ã©ã ãä½ãããã«ã¯ãåå°ãåãã ãã§ã¯ãªããå°ããªç©´ãåããæ©è½ãç¡ãã¦ã¯ãªãã¾ããã
ãã®æ©è½ã«ã¤ãã¦ã¯ãã¾ã次åã話ãããäºå®ã§ãã
ãªãã次åã®è¨äºæ²è¼äºå®ã¯æªå®ã§ãã
ï¼ãªã¯ã¨ã¹ããå¤ããã°åªå 度ãä¸ãã¦æ©ãã«è¨äºãæ¸ãããï¼ï¼
*1:roseã¯riseã®éå»å½¢