æ¡æã¿ã¼ãã«ã®åºæ¬æ§è½èª¿æ»ï¼ï¼ï¼
ä»åã®è¨äºã¯ãã¯ã¦ãªè¨æ³ã§ã¯ãªããMarkdownã§æ¸ãã¦ã¿ãã
ï¼2014/02/20ã表å ã®ãã¼ã¿ã«ã¤ãã¦è»¢åãã¹ãçºè¦ããã®ã§ä¿®æ£ãçµè«ã¯å¤ããã¾ãããï¼
ã¿ã¼ãã«ã®æ¡æé度ã調æ»ãã¦ã¿ã
å°ãã§ãæ©ãæ¡æã§ããã¨ããããã®ã§ã¯ãªããã¨ã æ¡æé¢é£ã§ã¯ã©ã®ãããªé¢æ°ã使ãã¨ã©ã®ãããé ããªãã®ã確èªãã¦ã¿ã¾ããã
調ã¹ãé¢æ°ã¯ä»¥ä¸ã®ï¼ã¤ã
- turtle.detect()
- turtle.dig()
以ä¸ã®ã³ã¼ãã®ã©ã¡ããæ©ããã確èªããããã«è¡ãã¾ããã
-- ãããç®ã®åã«ãããã¯ããã£ããdig()ããããªãã£ããdig()ããªãã if turtle.detect() then turtle.dig() end turtle.forward()
-- ç®ã®åã«ãããã¯ããããããªãããããdig()ã
turtle.dig()
turtle.forward()
ã¤ã¾ããããã¯ããªãã¨ãã§ããturtle.detect()ã使ã£ã¦ã¾ã§turtle.dig()ã®å®è¡ãåé¿ãã¹ããã©ããã¨ããæ¤è¨¼ã§ãã
ãªãã¨ãªãã¤ã¡ã¼ã¸ã§ãããå®éã«è¡åãããã¨ããturtle.dig()
ãããã
ãã ç®ã®åã«ãããã¯ããããã©ãã調ã¹ãã ãã®turtle.detect()
ã®æ¹ãã
å§åçã«å¦çã軽ããï¼å¿
è¦æéãå°ãªããï¼ã§ã¯ããã¾ãããï¼
ãããããªãã°ãturtle.detect()
ãäºåã«ä½¿ããã¨ã§ã
ç®ã®åã«ãããã¯ããªãã¨ãã«ã¯turtle.dig()
ãå®è¡ããªãããã«ããæ¹ãè¯ããã¨ã«ãªãã¾ãã
以ä¸ãæ¤è¨¼ã«ãªãã¾ãã
ä¾ã«ãã£ã¦ãéä¸ã¯é·ãã®ã§ãçµè«ã ãç¥ããã人ã¯æå¾ã®ã¾ã¨ãã ãèªãã§ããããã°OKã§ãã
æ¤è¨¼æ¹æ³
æ¤è¨¼å ´æã®ç»å
-
æ¤è¨¼ç¨ããã°ã©ã
ãã³ãã¬ã¼ã
èªåå®è¡ã®ãããstartupãã¨ãããã¡ã¤ã«åã§ä¿åã
print(os.clock()) for i=1, 10 do --ï¼ããã«æ¡ä»¶ãã¨ã«ç°ãªãã³ã¼ããå ¥ããï¼ turtle.forward() end print(os.clock())
æ¤è¨¼æ¡ä»¶ã¨æ¿å ¥ããã³ã¼ã
以ä¸ãforæã§10åç¹°ãè¿ããçµéæéãæ°ããï¼os.clock()ãå©ç¨ï¼ã
- æ¡ä»¶ï¼ï¼ detect+dig(+forward)
- 使ç¨ããã³ã¼ãï¼ã
if turtle.detect() then turtle.dig() end
- 使ç¨ããã³ã¼ãï¼ã
- æ¡ä»¶ï¼ï¼ detect(+forward)
- 使ç¨ããã³ã¼ãï¼ã
if turtle.detect() then ãend
- 使ç¨ããã³ã¼ãï¼ã
- æ¡ä»¶ï¼ï¼ dig(+forward)
- 使ç¨ããã³ã¼ãï¼ã
turtle.dig()
- 使ç¨ããã³ã¼ãï¼ã
- æ¡ä»¶ï¼ï¼ ãªã(+forward)ãã¤ã¾ãforwardã®ã¿ã
- 使ç¨ããã³ã¼ãï¼ããªã
試è¡çµæ
çµæ表1ï¼åä½ã¯ç§ï¼ãforæã«ãã10åç¹°ãè¿ãã®çµéæé
- ï¼2014/02/20ãæ¸ãçãããã¼ã¿ãã転åãã¹ããã¦ããã®ã§ãä¿®æ£ï¼
- *注1ï¼ãããã¯ãªãã®ã¨ãã¯IFæã§dig()åé¿ãããã®ã§ããããã¯ãªãæ¡ä»¶2ã¨ã»ã¼åç
æ¡ä»¶1ï¼detect+digï¼ | æ¡ä»¶2ï¼detectï¼ | æ¡ä»¶3ï¼digï¼ | æ¡ä»¶4ï¼fowardã®ã¿ï¼ | |
---|---|---|---|---|
ãããã¯ãªã | 4.15(*注1) | 4.15 | 4.15 | 3.65 |
ãããã¯ãã | 8.15 | - | 7.65 | - |
表ããããããããã¨ã¯ã10æ©åé²ã§3.65ç§ã¨ãããã¨ã§ããã åç´è¨ç®ããã¨1æ©åé²ã§0.365ç§ã§ãã
ãã以ä¸ã«ã¤ãã¦ã¯ãã®ã¾ã¾ã ã¨è¦ã¥ããã®ã§ããããã¯ãªãã®æ¡ä»¶ï¼ï¼forwardã®ã¿ï¼ã®å¤ã§ãã3.65(ç§)ã¨ã®å·®ãæ±ãããã¨ã§æ£è¦åãã¾ããã å ãã¦ããããã®å¤ã¯foræã«ãã10試è¡ã®çµæãªã®ã§ããããã10ã§å²ããã¨ã§1試è¡ãããã®çµéæéãæ±ãã¾ãããçµæã以ä¸ã®è¡¨ã§ãã
çµæ表2ï¼åä½ã¯ç§ï¼ã1試è¡ãããã®çµéæé
- ï¼2014/02/20ãæ¸ãçãããã¼ã¿ãã転åãã¹ããã¦ããã®ã§ãä¿®æ£ï¼
- *注1ï¼ãããã¯ãªãã®ã¨ãã¯IFæã§dig()åé¿ãããã®ã§ããããã¯ãªãæ¡ä»¶2ã¨ã»ã¼åç
æ¡ä»¶1ï¼detect+digï¼ | æ¡ä»¶2ï¼detectï¼ | æ¡ä»¶3ï¼digï¼ | æ¡ä»¶4ï¼ãªãï¼ | |
---|---|---|---|---|
ãããã¯ãªã | 0.05(*注1) | 0.05 | 0.05 | 0 |
ãããã¯ãã | 0.45 | - | 0.4 | - |
ãã¨ãã°ãæ¡ä»¶ï¼ã®ãããã¯ãªãæ¡ä»¶ã®çµéæé0.05(ç§)ã¯ãç´ç²ã«detect()ã1åå®è¡ããã¨ãã®çµéæéãæå³ãã¦ãã¾ãï¼å³å¯ã«ã¯IFæã®å¦çæéãªã©èããªãã¦ã¯ãªãã¾ããããããã§ã¯çç¥ï¼ã
çµæèå¯
表ï¼ããããããã¨
1æ©ç§»åï¼turtle.forward()ï¼ããã®ã«0.365ç§ããã
ãªããå¾é²ï¼turtle.back()ï¼ãä¸æï¼turtle.up()ï¼ãä¸éï¼turtle.down()ï¼ãå ¨ã¦åãã¿ã¤ã ã§ããã ããããããã¨æããåé²ããå¾é²ãä¸æããä¸éãªã©ãéä¸ã§åãåããåãæ¿ãã¾ããããåãæ¿ãã®ã¿ã¤ã ã©ã°ã¯ããã¾ããï¼ã¤ã¾ãç¾å®ä¸çã®ããã«åé²ããå¾é²ã«æ¥ã«åãæ¿ãã¦ãæ £æ§ã¯ã¯ããããªãï¼ã
ããä¸ã¤ãã¾ãã«ãå³å転ï¼turtle.turnRight()ï¼ãå·¦å転ï¼turtle.turnLeft()ï¼ã試ãã¾ãããã1åãããåã0.365ç§ã«ãªãã¾ãã å³å転ããå·¦å転ãªã©éä¸ã§å転æ¹åãåãæ¿ãã¦ãï¼ç¾å®ä¸çã®ããã«æ £æ§ã«ããï¼ã¿ã¤ã ã©ã°ã¯ããã¾ããã
表ï¼ããããããã¨
dig()ã§1åã®ãããã¯ãç ´å£ããã®ã«0.35ç§ããã
æ¡ä»¶3ã«æ³¨ç®ãããããã¯ãã/ãªãã®å·®ãåãã¨0.45-0.1 = 0.35ç§ã§ãã
ãã®ãã¨ãããdig()ã使ã£ã¦ãããã¯ãå£ãã®ã«0.35ç§å¿ è¦ã§ãããã¨ããããã¾ãã
turtle.detect()ã«ããdig()å®è¡åé¿ã¯ç¡é§ãã
æ¡ä»¶ï¼ã¨æ¡ä»¶ï¼ãæ¯è¼ããã¨ããããã¯ããªãã¨ãã¯åãæéããããã¯ãããã¨ãã«ã¯æ¡ä»¶ï¼ã®æ¹ãæéãããã£ã¦ãã¾ããã¤ã¾ãããã¯æåã®ç®çã§ãã£ãã
-- ãããç®ã®åã«ãããã¯ããã£ããdig()ããããªãã£ããdig()ããªãã if turtle.detect() then turtle.dig() end turtle.forward()
ã¨ããã³ã¼ããæéã®ç¡é§ã§ãããã¨ããããã¾ããã·ã³ãã«ã¤ãºãã¹ãï¼
Turtle APIé¢æ°1åããã0.05ç§å¿ è¦ï¼
ã¾ããããã¯ãªãæ¡ä»¶ã«ããã¦ãæ¡ä»¶ï¼/æ¡ä»¶ï¼ãæ¯è¼ãããã¨ã§ã ãããããã¦ãTurtle APIç³»ã®é¢æ°ã1åå®è¡ããã®ã«ä¸å¾0.05ç§å¿ è¦ãªã®ã§ã¯ï¼ãã¨ããäºæ³ãã¤ãã¾ãã
ãã¦ããã§ããTutleAPIãã0.05ç§ãã¨ãããã¼ã¯ã¼ãã§æãã¤ããã¨ã¯ããã¾ãããï¼
- ãã³ã1
- os.sleep(æé)é¢æ°ã§ãæå®ã§ããæéã®æå°åä½ã¯0.05ç§ã§ãã
- ã¾ããos.sleep(æé)é¢æ°ã¯ã"timer"ã¤ãã³ããå©ç¨ãã¦å®è£ ããã¦ãã¾ãã
- ãã³ã2
- Turtle APIä¸ã®ã»ã¨ãã©ã®é¢æ°ã¯ãå é¨ã§"turtle_response"ã¤ãã³ãã使ããã¨ã§å®è¡ã®æå¦ã確èªãã¦ãã¾ãã
ããããã§ããï¼å人çã«ã¯ã»ã¼ç¢ºä¿¡ãã¦ãã¾ããï¼ã
Turtle APIãªã©ãCCã®ã¤ãã³ã(Event)ãå
é¨ã§ç¨ãã¦ããé¢æ°ã¯æä½ã§ã0.05ç§ã®æéãå¿
è¦ãªã®ã§ããããããã¯ãã¤ãã³ãå¦çã«ã¤ãã¦ã®ã·ã¹ãã çãªå¶éã ã¨æããã¾ãã
ã¤ãã³ãå¦çã¨ã¯ããªãã¡ã³ã«ã¼ãã³ï¼coroutine.yeildï¼ã®ãã¨ã§ãã£ã¦ãã³ã«ã¼ãã³ã«ãã£ã¦ãLuaâJavaâLuaã¨å¦çã移ã£ã¦ãããã¨ã以åã«èª¬æãã¾ããã
ãã®å¦çã®ç§»ãå¤ããã«ãå¿
ã0.05ç§ï¼ä»¥ä¸ï¼ã®æéãå¿
è¦ãªã®ã§ãããã
ã¨ãããã¨ã§ãã¿ã¼ãã«ããã°ã©ãã³ã°ã§å¦çé度ãã·ãã¢ã«èãããªãã°ãã¤ãã³ããç¨ãã¦ããé¢æ°ã¯ã§ããã ã使ãã®ãé¿ããã»ããè¯ããã¨ããããã¾ããã¨ã¯ãããå ¨ã使ããªãã¨ãªãã¨ä»åº¦ã¯ãToo long without yieldingãã¨ã©ã¼ã¨ãªã£ã¦ãã¾ãã¾ãã®ã§ãå¹çãèãããªãã°æ¬¡ã®ããã«è¦ãã¦ããã°è¯ãã§ãããã
- å¦çæéãèãããªãã°ãã¤ãã³ãå¦çãå å ããTurtleAPIã®ãããªé¢æ°ç¾¤ã®å©ç¨ã¯å¿ è¦æå°éã«ãã¹ãããã ãå ¨ã使ããªãã®ããã¡ã
ãã£ã¨ãã0.05ç§ãã±ãããªãã¦ã¯ãããªããããªã·ãã¢ãªããã°ã©ã ãçµããã¨ãããããã¨ã¯æãã¾ãããï¼P
æ¤è¨¼ã®ã¾ã¨ã
ã¿ã¼ãã«ã®è¡åã«ã¤ãã¦
- åé²ã»å¾é²ã»ä¸æã»ä¸éã»å転ãªã©ãä¸ã¤ã®è¡åãããã®ã«0.365ç§ããã
- turtle.dig()ã§1åã®ãããã¯ãç ´å£ããã®ã«0.35ç§ããã
ãã®ä»ã®TurtleAPIã«ã¤ãã¦
- turtle.detect()ãªã©ãTurtle APIã®ã¤ãã³ãå¦çãå
å
ããé¢æ°ã¯ä¸å¾0.05ç§ã®æéããããã
- ãã®ããå¦çæéã ãã§èãããªãã°
if turtle.detect() then turtle.dig() end
ã¯ç¡é§ãã·ã³ãã«ã«turtle.dig()
ã ãã§ããã
- ãã®ããå¦çæéã ãã§èãããªãã°