清风

导航

2017-11-04 Sa OCT codecombat

def hasEnemy():
    e = hero.findNearestEnemy()
    if e:
        return True
    else:
        return False

def enemyTooClose():
    e = hero.findNearestEnemy()
    if e:
        return hero.distanceTo(e) < 30
    else:
        return False

def healthTooLow():
    return hero.health < 200

def nearestEnemyHook(hook):
    if not hook:
        return False

    e = hero.findNearestEnemy()
    if e:
        hook(e)
        return True
    return False

def attackNearestEnemy():
    nearestEnemyHook(hero.attack)
        
def bashNearestEnemy():
    nearestEnemyHook(hero.bash)

def attackByType(eType):
    t = hero.findNearest([x for x in hero.findEnemies() if x.type == eType])
    if t:
        hero.attack(t)
        return True
    else:
        return False

def bashByType(eType):
    t = hero.findNearest([x for x in hero.findEnemies() if x.type == eType])
    if t:
        hero.bash(t)
        return True
    else:
        return False

def moveTo(i):
    if i:
        hero.moveXY(i.pos.x, i.pos.y)
        return True
    return False

def collectNearestItem():
    i = hero.findNearestItem()
    if i:
        moveTo(i)
        return True
    return False

def moveToFlag(color):
    f = hero.findFlag(color)
    if f:
        hero.pickUpFlag(f)
        return True
    return False

def desert_SarvenSiege():
    # Defend your towers in this replayable challenge level!
    # Step on an X if you have 20 gold to build a soldier.

    def attack():
        attackNearestEnemy()

    def passiveAttack():
        f = hero.findFlag("black")
        if f:
            hero.pickUpFlag(f)
            attackNearestEnemy()
            return True
        return False

    def buildSoldier():
        pass

    while True:
        if not move():
            attack()
        if hero.gold >= 20:
            buildSoldier()

def forest_backwoodsBrawl_lv0():
    # Stay alive for one minute.
    # If you win, it gets harder (and more rewarding).
    # If you lose, you must wait a day before you can resubmit.
    # Remember, each submission gets a new random seed.

    while True:
        attackNearestEnemy()

def forest_backwoodsBrawl_lv1():
    # Stay alive for one minute.
    # If you win, it gets harder (and more rewarding).
    # If you lose, you must wait a day before you can resubmit.
    # Remember, each submission gets a new random seed.

    while True:
        if not attackByType('thrower'):
            attackNearestEnemy()

def forest_backwoodsBrawl_lv2():
    # Stay alive for one minute.
    # If you win, it gets harder (and more rewarding).
    # If you lose, you must wait a day before you can resubmit.
    # Remember, each submission gets a new random seed.

    while True:
        if not attackByType('thrower'):
            attackNearestEnemy()

def forest_backwoodsBrawl_lv3():
    # Stay alive for one minute.
    # If you win, it gets harder (and more rewarding).
    # If you lose, you must wait a day before you can resubmit.
    # Remember, each submission gets a new random seed.

    while True:
        attackByType('thrower') or attackByType('orge') or attackNearestEnemy()

# Backwoods Treasure
# Gather gleaming gold from ogre-guarded groves in this player-created replayable level by Kevin Holland.
# It gets harder (and more lucrative) each time you win! But if you lose, you must wait a day to resubmit
#
# Goals
# Collect 100 gold
#
# Collect 100 gold from two or three groves.
# If you win, it gets harder (and more rewarding).
# If you lose, you must wait a day before you can resubmit.
# Remember, each submission gets a new random seed.

def forest_backwoodsTreasure_lv0():
    while True:
        attackNearestEnemy() or collectNearestItem()

def forest_backwoodsTreasure_lv1():
    while True:
        if hasEnemy():
            if enemyTooClose() and healthTooLow():
                attackNearestEnemy()
                continue
        collectNearestItem()

# Thoktar's clone army guards the gate to the Cloudrip Mountains.

# equip the 'simple sword' (6 damage) (have to equip one sword), only use bash. so that the cloned one use 'simple sword' too
# painted steel shield, 740 gold, 73.4 damage

def desert_clashofClones_v1():
    # You'll need good strategy to win this one!
    # Your clone will have the same equipment you have!
    # But, they're not very skilled at using special powers.

    def ass(e, t):
        for i in e:
            if i and i.type == t:
                if t == 'scout' and hero.distanceTo(i) >= 10:
                    continue
                hero.attack(i)
                return True
        return False
        
    def has(e, t):
        for i in e:
            if i.type == t:
                return True
        return False


    def fn(e, t): # find nearest
        n = None
        nd = 999999999
        
        for i in e:
            d = hero.distanceTo(i)
            if i.type == t and d < nd:
                n = i
                nd = d
        return (n, nd)

    def a():
        while True:
            e = hero.findEnemies()
            
            # scout first
            if has(e, 'scout'):
                (sc, scd) = fn(e, 'scout')
                if has(e, 'archer'):
                    (ar, ard) = fn(e, 'archer')
                    if ard < scd:
                        hero.attack(ar)
                hero.attack(sc)
            
        #    if ass(e, 'scout') or ass(e, 'archer'):
        #        pass

    while True:
        g = hero.findFlag("green")
        if g:
            hero.pickUpFlag(g)
            continue
        
        v = hero.findFlag("violet")
        if v:
            hero.pickUpFlag(v)
            hero.shield()
            
        
        b = hero.findFlag("black")
        if b:
            hero.pickUpFlag(b)
            es = hero.findEnemies()
            if False:#has(es, 'alejandro'):
                (a, ad) = fn(es, 'alejandro')
                hero.attack(a)
            else:
                e = hero.findNearestEnemy()
                if e:
                    if hero.isReady("cleave"):
                        hero.cleave()
                    hero.attack(e)

def desert_clashofClones_v2():
    while True:
        moveToFlag('green') or bashByType('alejandro')

def desert_clashofClones_v3():
    while True:
        moveToFlag('green') or bashNearestEnemy()

def desert_clashofClones():
    desert_clashofClones_v3()

# Sarven Treasure
# Gather 150 gold while evading ogres and running through teleporters. It gets harder (and more lucrative) each time you win! But if you lose, you must wait a day to resubmit.
# #Basic Syntax #Reading the Docs
#
# Goals
# Collect 150 gold
# Survive
#
# Collect 150 gold while evading ogres with teleporters.
# If you win, it gets harder (and more rewarding).
# If you lose, you must wait a day before you can resubmit.
# Remember, each submission gets a new random seed.
def desert_sarvenTreasure_lv0():
    while True:
        attackNearestEnemy() or collectNearestItem()

def desert_sarvenTreasure_lv1():
    while True:
        attackNearestEnemy() or collectNearestItem()

desert_clashofClones()

posted on 2017-11-04 10:12  清风2009  阅读(272)  评论(0编辑  收藏  举报