「網易官方」極客戰記(codecombat)攻略-山峰-聯合做戰-mixed-unit-tactics


(點擊圖片進入關卡)

找出最佳的兵種組合, 擊退食人大隊

簡介

開放式防御水平!

依靠你的技能生存 30 秒並收集 300 金幣。

你能把它變成 60 秒嗎?

默認代碼

# 練習用取模從數組中循環取值
# 在數組array中編排好兵種組合
summonTypes = []
def summonTroops():
    # 用%取模來循環預設的征兵方案 len(self.built)
    #type = summonTypes[???]
    hero.say("I should summon troops!")

概覽

首先,按照您要召喚的單位類型填寫 “summonTypes” 數組。

然后,使用 summonTroops 函數完成

len(hero.built) % len(summonTypes)

遍歷 summonTypes 數組。

您還需要創建一個 collectCoins 函數和一個 commandTroops 函數。

提示:在 commandTroops 中,您會想要跳過任何擁有 type =="palisade" 的朋友!

聯合做戰解法

# 練習用取模從數組中循環取值
# 在數組array中編排好兵種組合
summonTypes = []
def summonTroops():
    # 用%取模來循環預設的征兵方案 len(self.built)
    type = summonTypes[len(hero.built) % len(summonTypes)]
    if(hero.costOf(type) <= hero.gold):
        hero.summon(type)

 

def gatherCoins():
    items = hero.findItems()
    item = hero.findNearest(items)
    if item:
        hero.move(item.pos)
def commandTroops():
    friends = hero.findFriends()
    for i in range(len(friends)):
        friend = friends[i]
        enemy = friend.findNearestEnemy()
        if enemy:
            hero.command(friend, "attack", enemy)
while True:
    summonTroops()
    gatherCoins()
    commandTroops()
 

本攻略發於極客戰記官方教學欄目,原文地址為:

https://codecombat.163.com/news/jikezhanji-lianhezuozhan

極客戰記——學編程,用玩的


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM