ãMore Turtlesããã©ã¼ãã¥ã³ä»ããããã¯ãã¬ã¤ã«ã¼ãä¿®æ£ãã
ã¡ãã£ã¨ã ãå æ°ã«ãªã£ãã®ã§æ´æ°ã
ã¯ããã«
ååã¯ãFortune Mining Turtleã使ã£ããã©ã¼ãã¥ã³ä»ããããã¯ãã¬ã¤ã«ã¼ããã°ã©ã ãç´¹ä»ãã¾ããã
ãã¤ã¤é±ç³ãªã©ãä¸ã®ãã§ã¹ãã«å ¥ãã¦ããã¨ããã©ã¼ãã¥ã³æ¡æã§ç ´å£ãã¦å ¥æç´ æãå¢ããã¦ããã¾ãã
ä»åã¯ãååã®ããã°ã©ã ã§åé¡ã¨ãªã£ãçæé¢ä¿ãä¸å¿ã«ããã°ã©ã ãä¿®æ£ãã¾ãããã
ããã°ã©ã ä¿®æ£ã®æ¹é
ï¼ï¼çæè£çµ¦ã®ã¿ã¤ãã³ã°
ä¸ã®ãã§ã¹ããããããã¯ã1ã¹ã¿ãã¯ã¨ã£ã¦ããã®åæ°ã ããã©ã¼ãã¥ã³æ¡æãè¡ãã®ã§ããã®åæ°åã®çæãæä½éå¿ è¦ãªçæã¨ãã¾ãããã
å ·ä½çã«ã¯ããã§ã¹ããããããã¯å ¥æãããã³ã«çæã確èªãã¾ãã çæã足ããªãã£ããä¸æçã«åæ¢ãã¦çæã¢ã¤ãã ã®è£çµ¦ãå¾ ã¤ã¨ãã以ä¸ã®é¢æ°ãä½ãå©ç¨ãã¾ãããã
- waitForEnoughFuel()é¢æ°ã®ä½æ
ï¼ï¼ã¢ã¤ãã ããããã«ã¤ãã¦å¹çå
ååã®ããã°ã©ã ã§ã¯ãã¹ããã1ãã16ã¾ã§å ¨ã¦ã®ã¢ã¤ãã ãä¸ã®ãã§ã¹ãã«ãããããã¦ãã¾ããããããããèããã¨ãããã ã1ã¹ã¿ãã¯64åã®ãããã¯ãç ´å£ããã¨ãã¦ãã¹ããã16ã¾ã§ãããããããã¨ããã®ã¯ç¡é§ã§ãã
ãã®ããã°ã©ã ã§ã¯ãé¸æã¹ãããã1ã«ããã¾ã¾ãããã¯ãç ´å£ãã¦ããã®ã§ãå ¥æããã¢ã¤ãã ã¯ã¹ããã1以éãé ã«åã®ã¹ãããããè©°ã¾ã£ã¦ããã¾ãã
ã¨ãããã¨ã¯ãã¹ããã1,2,3,4â¦â¦ã¨åã®ã¹ãããããé ã«ã¢ã¤ãã ããããããã¦ããã空ã®ã¹ãããã«çªãå½ãã£ã¦ããããã§ããªããã¨ãããã£ããããã§ããããä½æ¥ãåãä¸ãã¦ãã¾ãã°ããããã§ãã
ä»åã¯ãåã®ã¹ãããããé ã«è½ã¨ãã¦ãã以ä¸ã®é¢æ°ãä½æãã¾ãã
- dropSeq()é¢æ°ã®ä½æ
ï¼ï¼è¨å®ï¼configï¼ã§ããé ç®ãå¢ãã
ååã®ããã°ã©ã ã§ã¯ãçæãå ¥ããã¹ãããï¼FUEL_SLOTï¼ã¨å ¥æãããã¯ã®ã¹ãããï¼BLOCK_SLOTï¼ãè¨å®ã§ããããã«ãã¦ãã¾ããããä»åã¯ããã«å ãã¦ãé±ç³ãããã¯ç¨ãã§ã¹ãã®ä½ç½®ã¨ã¢ã¤ãã ããããç¨ãã§ã¹ãã®ä½ç½®ãå¤ããããããã«ãã¾ãã
å ·ä½çã«ã¯ãã¢ã¤ãã å ¥æç¨é¢æ°ï¼SUCK_FUNCï¼ã¨ã¢ã¤ãã ããããç¨é¢æ°ï¼DROP_FUNCï¼ãç´æ¥æå®ã§ããããã«ãã¾ãã
ããã°ã©ã
ã¤ã³ã¹ãã¼ã«
ããã°ã©ã åãbbãã¨ãã¦ã¤ã³ã¹ãã¼ã«ããã
> pastebin get pCY3K7vs bb
ã½ã¼ã¹ã³ã¼ã
ãããã°ã©ã ã®è§£èª¬
è¨å®é ç®ï¼configï¼
ã¢ã¤ãã å
¥æç¨é¢æ°ï¼SUCK_FUNCï¼ã¨ã¢ã¤ãã ããããç¨é¢æ°ï¼DROP_FUNCï¼ç´æ¥æå®ãã¾ãã
ããã©ã«ãã¯ã以ä¸ã®ã¨ãããã¤ã¾ããé±ç³ãããã¯ç¨ãã§ã¹ãã¯ä¸ãããããç¨ãã§ã¹ã¨ã¯ä¸ã§ãã
é¢æ°ãç´æ¥æå®ããã®ã§ããããturtle.suckUp()
ã®ããã«æ«å°¾ã«ã()ããã¤ãã¦ã¯ãã¡ã§ããã¤ãã¦ãã¾ãã¨ããã®é¢æ°ãå®è¡ãã¦ãã¾ãã¾ããããã()ããã¯ããã¦é¢æ°åãæå®ãã¦ãã ããï¼è©³ç´°ã¯ãã¡ããåç
§ã®ãã¨ï¼ã
SUCK_FUNC = turtle.suckUp DROP_FUNC = turtle.dropDown
ã¡ã¤ã³(main)é¨å
print("Start: fortune BB") while suckBlock() do placeDig(turtle.getItemCount(BLOCK_SLOT)) dropSeq() end print("Finished: fuel ",turtle.getFuelLevel())
- æåã«ããã°ã©ã ã¹ã¿ã¼ããããï¼ã¨å®£è¨
- ã¾ãä¸ã®ãã§ã¹ãããé±ç³ãããã¯ãå
¥æï¼suckBlock()ï¼
- æã«å ¥ããé±ç³ãããã¯ã®æ°ã ãããããã¯è¨ç½®ï¼ãã©ã¼ãã¥ã³ç ´å£
- å ¥æããç´ æãã¢ã¤ãã ç¨ãã§ã¹ãã«ãããã
- ä¸ã®ãã§ã¹ãããé±ç³ãããã¯ãå ¥æã§ããªãã£ãããwhileã«ã¼ããæãã¦ãçµäºã
- æå¾ã«ããã°ã©ã çµäºå®£è¨ã念ã®ããçæã®æ®éã表示ã
èªåã§å®ç¾©ããé¢æ°
suckBlock()
ãã§ã¹ããã1ã¹ã¿ãã¯ã®ã¢ã¤ãã ãå ¥æããé¢æ°ã§ãå ¥æã«æåãããtrueã失æãããfalseãè¿ãã¾ãããã®true/falseã§ãã¡ã¤ã³é¨åã®whileã«ã¼ããå¶å¾¡ãã¾ãã
ãªãååã®ããã°ã©ã ã¨ã®ç¸éã¯ããã§ã«ã¤ã³ãã³ããªå ã®BLOCK_SLOTã«ã¢ã¤ãã ãããã¨ãã«ã¯ããã§ã«å ¥ææ¸ã¿ã¨ãããã¨ã§å¼·å¶çã«trueãè¿ãããã«ãã¦ãã¾ãã
waitForEnoughFuel(minLevel, slot)
å¼æ°slotã®çæã¢ã¤ãã ãè£çµ¦ããä¸ã§ãæå°çæå¤minLevelã«æºããªãã®ãªãããããªãçæã¢ã¤ãã ã®æ¿å ¥ãå¾ ã¤é¢æ°ã§ãããã®é¢æ°ã®ãã¤ã³ãã¯ä»¥ä¸ã®ã¨ããã
- ç¾å¨çæå¤ãä¸æçã«ä¿åãã¦ããå¤æ°qty
- é¢æ°å
ã§ãã¼ã«ã«é¢æ°refuel()ãå®ç¾©ãã¦è¦ããããéè¦ã
- æå®ã¹ãããã®çæè£çµ¦ï¼å¤æ°qtyã«ç¾å¨ã®çæå¤ãä¿å
- è¿å¤ã¨ãã¦qtyã®å¤ãè¿ãããã«ãããã¨ã§ãwhileã«ã¼ãã®æ¡ä»¶å¼ã¨ãã¦ä½¿ããããã«
- ç¾å¨ã®çæå¤ãæä½å¤ããå¤ããªãã¾ã§whileã«ã¼ããç¹°ãè¿ã
- ã¤ã³ãã³ããªå
容ãå¤åããã¾ã§å¾
ã¤
os.pullEvent("turtle_inventory")
ã使ç¨ã - sleep(1)ã¯ãos.pullEvent()ãéæã«åå¿ãããé²ãããã®ã¦ã§ã¤ãã
- ã¤ã³ãã³ããªå
容ãå¤åããã¾ã§å¾
ã¤
placeDig(count)
é¢æ°å ã®æåã§waitForEnoughFuel()ã使ããã¨ã«ããããããã¯è¨ç½®ï¼ç ´å£ãéå§ããåã«å¿ è¦çæã確ä¿ã§ããããã«ãªã£ãã
ãã®ãããååã®ããã«assert()é¢æ°ã使ã£ã¦ããã°ã©ã ãå¼·å¶åæ¢ããå¿ è¦ããªããªã£ãã ã·ã³ãã«ï¼
dropSeq()
åºæ¬çã«ã¯ãã¹ããã1ãã16ã¾ã§é ã«ã¢ã¤ãã ããããããã¦ããã®ã ãã©ã éä¸ã§ããããé¢æ°ã®å®è¡ã«å¤±æï¼ãã¨ãã°ãã®ã¹ãããã«ã¯ã¢ã¤ãã ããªãã®ã§ããããã§ããªããªã©ï¼ããããforã«ã¼ããæãã¦ããã®é¢æ°ãçµäºããã
ããã§ãåã®ã»ãã®ã¹ãããããã¢ã¤ãã ãé ã«è½ã¨ãã¦ããã空ã¹ãããã«ããããããã以ä¸ã¯è½ã¨ããªãã¨ããå¦çãå®æã
ãªã注æããªãã¨ãããªãã®ã¯ããã®é¢æ°ã¯ææã¢ã¤ãã ã¯åã®ã»ãã®ã¹ãããããé ã«è©°ã¾ã£ã¦ããã¨ããåæãå ã«ãã¦ãããã¨ã ãã¨ãã°ãé¸æã¹ãããã1ï¼turtle.select(1)ï¼ã«ããã¾ã¾ãã²ãããã¢ã¤ãã ãå ¥æããã¨ããããã«ãããã
ä»®ã«ãé¸æã¹ãããã次ã ã¨åãæ¿ãã¦ã¢ã¤ãã ãå ¥æãããã¨ã§ãã¢ã¤ãã ãå ¥ã£ã¦ããã¹ããããé£ã³é£ã³ã«ãªã£ã¦ãããããã®é¢æ°ã¯ç ´ç¶»ãããè¦æ³¨æã
ãããã«
ãã©ã¼ãã¥ã³ä»ããããã¯ãã¬ã¤ã«ã¼ã¯ãããã§ã²ã¨ã¾ãå®æã¨ãã¾ãã
ã¶ã£ã¡ãããã¡ã®ç°å¢ã ã¨ããã¾ã«ãã使ããªããã§ãããããããã¯ãã¬ã¤ã«ã¼ã
次åã¯ããããã¯ãã¬ã¤ã«ã¼ã¤ãªããã§ãé»æç³çæããã°ã©ã ã¨ã丸ç³çæããã°ã©ã ããããèãã¦ãã¾ããã楽ãã¿ã«ã