zoukankan      html  css  js  c++  java
  • 【网易官方】极客战记(codecombat)攻略-森林-逻辑之路logical-path

    使用逻辑跟着巫师来到他的宝藏

    简介

    在森林深处,一个巫师给了你一次挑战:如果你能解出他的逻辑谜题,他会和你分享他的宝物!

    使用 与 (AND), 或 (OR), 非 (NOT) 这种 布尔操作符 (boolean operators) 觉得在每个分叉路口走哪条路。查看提示学会怎么写出你要的代码。

    默认代码

    # 从巫师那得到两个秘密的真假值
    # 查看提示,学会写逻辑表达式。
    hero.moveXY(14, 24)
    secretA = hero.findNearestFriend().getSecretA()
    secretB = hero.findNearestFriend().getSecretB()
    # 如果 secretA 和 secretB 都为真,走上面的路;否则,走下面。
    secretC = secretA and secretB
    if secretC:
        hero.moveXY(20, 33)
    else:
        hero.moveXY(20, 15)
    hero.moveXY(26, 24)
    # 如果 secretA 和 secretB 中有一个为真,走上面。
    hero.moveXY(38, 24)
    # 如果 secretB 不是真的,走上面。
    hero.moveXY(50, 24)

    概览

    在这关,你需要按照 布尔值 (真或假) 选择前方的道路。在每个分叉路口,值为真时走上方的路,值为假时走下方的路。巫师会给你前两个值,而后面的则需要你用 布尔运算 得出。

    布尔操作符 处理真 (TRUE) 和假 (FALSE) 这两个值,并返回真或假。

    与 (AND) 操作符在两个输入都为真时返回真:

    # Python 里 'and' 是小写。'True' 和 'False' 首字母大写。
    a = True and True # a = True
    b = True and False # b = False
    c = False and True # c = False
    d = False and False # d = False

    或 (OR) 操作符在两个输入的任意一个为真时返回真:

    a = True or True # a = True
    b = True or False # b = True
    c = False or True # c = True
    d = False or False # d = False

    非 (NOT) 操作符有点不同,它只处理一个输入,返回相反值:

    a = not True # a = False
    b = not False # b = True

    当然啦,你还可以用布尔运算将变量和布尔值结合:

    a = not False # a = True
    b = a or False # b = True
    c = a and b # c = True

    使用这些工具帮你找到最终到达宝藏的路!

    逻辑之路 解法

    # 从巫师那得到两个秘密的真假值
    # 查看提示,学会写逻辑表达式。
    hero.moveXY(14, 24)
    secretA = hero.findNearestFriend().getSecretA()
    secretB = hero.findNearestFriend().getSecretB()
    # 如果 secretA 和 secretB 都为真,走上面的路;否则,走下面。
    secretC = secretA and secretB
    if secretC:
        hero.moveXY(20, 33)
    else:
        hero.moveXY(20, 15)
    hero.moveXY(26, 24)
    # 如果 secretA 和 secretB 中有一个为真,走上面。
    secretD = secretA or secretB
    if secretD:
        hero.moveXY(32, 33)
    else:
        hero.moveXY(32, 15)
    hero.moveXY(38, 24)
    # 如果 secretB 不是真的,走上面。
    secretE = not secretB
    if secretE:
        hero.moveXY(44, 33)
    else:
        hero.moveXY(44, 15)
    hero.moveXY(50, 24)
     
    本攻略发于极客战记官方教学栏目,原文地址为:
  • 相关阅读:
    Python实现MapReduce,wordcount实例,MapReduce实现两表的Join
    structure needs cleaning
    Lifecycle of an ASP.NET MVC 5 Application
    ASP.NET Integration with IIS 7
    Execution order of modules in IIS7
    Assembly Binding redirect: How and Why?
    Cannot See Worker Processes Icon in IIS
    What is the main difference between a key, an IV and a nonce?
    核心玩法的三要素
    ruby各种循环输出数组元素
  • 原文地址:https://www.cnblogs.com/codecombat/p/12411308.html
Copyright © 2011-2022 走看看