zoukankan      html  css  js  c++  java
  • 「网易官方」极客战记(codecombat)攻略-山峰-钢爪间隙-steelclaw-gap

    (点击图片进入关卡)

    在爪子的缝隙中被敌人包围,其余的部队保卫着一个临时的栅栏。

    简介

    使用模运算符( % )向每个保护点发送两个单位。

    你需要召唤 8 个单位并移动到 4 点,所以 unitIndex%4 需要 defendIndex 。

    默认代码

    # 这个关卡介绍了%操作符,也称为模操作符。
    # a % b返回除以b的余数
    # 当索引可能大于长度时,这可以用于环绕数组的开头。
    defendPoints = [{"x": 35, "y": 63},{"x": 61, "y": 63},{"x": 32, "y": 26},{"x":64, "y": 26}]
    summonTypes =["soldier","soldier","soldier","soldier","archer","archer","archer","archer"]
    # 你用360金开始建造一个士兵和弓箭手的混合体。
    # Self.Bug是你曾经建造的一个部队数组。
    # 在这里,我们使用"len(self.built) % len(summonTypes)"来环绕召唤类型数组。
    def summonTroops():
        type = summonTypes[len(hero.built) % len(summonTypes)]
        if hero.gold >= hero.costOf(type):
            hero.summon(type)
    def commandTroops():
        friends = hero.findFriends()
        for i in range(len(friends)):
            friend = friends[i]
            # 根据friendIndex使用%来环绕防卫点

     

            # 命令你的手下捍卫防卫点

     

    while True:
        summonTroops()
        commandTroops()

    概览

    %运算符被称为模运算符。

    a%b 给你 a / b 的余数(作为一个整数)。 所以 12%5 == 2 。

    这可以用来环绕数组,例如:

    使用数组: summonTypes = ["soldier","archer","peasant","paladin"]

    用: type = summonTypes [i%summonTypes.length] 0 % 4 == 0 因此 type == "soldier"

    1 % 4 == 1` 因此 `type == "archer"
    2 % 4 == 2` 因此 `type == "peasant"
    3 % 4 == 3` 因此 `type == "paladin"
    4 % 4 == 0` 因此 `type == "soldier"
    5 % 4 == 1` 因此 `type == "archer"

    等等...

    钢爪间隙解法

    # 这个关卡介绍了%操作符,也称为模操作符。
    # a % b返回除以b的余数
    # 当索引可能大于长度时,这可以用于环绕数组的开头。
    defendPoints = [{"x": 35, "y": 63},{"x": 61, "y": 63},{"x": 32, "y": 26},{"x":64, "y": 26}]
    summonTypes =["soldier","soldier","soldier","soldier","archer","archer","archer","archer"]
    # 你用360金开始建造一个士兵和弓箭手的混合体。
    # Self.Bug是你曾经建造的一个部队数组。
    # 在这里,我们使用"len(self.built) % len(summonTypes)"来环绕召唤类型数组。
    def summonTroops():
        type = summonTypes[len(hero.built) % len(summonTypes)]
        if hero.gold >= hero.costOf(type):
            hero.summon(type)
    def commandTroops():
        friends = hero.findFriends()
        for i in range(len(friends)):
            friend = friends[i]
            # 根据friendIndex使用%来环绕防卫点
            point = defendPoints[i % len(defendPoints)]
            # 命令你的手下捍卫防卫点
            hero.command(friend, "defend", point)
    while True:
        summonTroops()
        commandTroops()
     
    本攻略发于极客战记官方教学栏目,原文地址为:
  • 相关阅读:
    Codeforces Beta Round #92 (Div. 2 Only) B. Permutations 模拟
    POJ 3281 Dining 最大流 Dinic算法
    POJ 2441 Arrange the BUlls 状压DP
    URAL 1152 Faise Mirrors 状压DP 简单题
    URAL 1039 Anniversary Party 树形DP 水题
    URAL 1018 Binary Apple Tree 树形DP 好题 经典
    pytorch中的forward前向传播机制
    .data()与.detach()的区别
    Argparse模块
    pytorch代码调试工具
  • 原文地址:https://www.cnblogs.com/codecombat/p/13588186.html
Copyright © 2011-2022 走看看