AlexeySapsay / Python_solution_CodeCombat_2018

In that repository I will post my sollution for codecombat.com games for study Python
1 stars 0 forks source link

Multiplayer Treasure Grove (Coin colection) #75

Open AlexeySapsay opened 6 years ago

AlexeySapsay commented 6 years ago
# Be the first to 100 gold!
# If you are defeated, you will respawn at 67% gold.
#  Find coins and/or attack the enemy.
# Use flags and your special moves to win!

#1. Try use pet to collect coins and attack
#2. Try use different type of traps
#3. Use the best protection
#4. Use arrays and try find max coin points
#5. Use to attack only abbillity, and rare stupide attack
#6. Your priority must be to collection coin 
#7 Find tactics vs lot of meat

#Find me on youtube  channel Phy tu
#https://www.youtube.com/channel/UCP5ycahCEZ24qmRRgNnko5Q

# Coins here disappear after a few seconds!
# Get all the gold coins before they vanish.

while True:
    closestGold = None
    minGoldDist = 9001
    coinIndex = 0
    coins = hero.findItems()
    # Find the closest coin that is gold.
    # Remember that gold coins have a value of 3.
    for coin in coins:
        distance=hero.distanceTo(coin)
        if (distance<minGoldDist and coin.value==3)or     (distance<minGoldDist and coin.value==2)or      (distance<minGoldDist and coin.value==1):
            closestGold=coin
            minGoldDist=distance

        coinIndex+=1

    if closestGold:
        #Now go to the closest gold coin and get it!
        hero.moveXY(closestGold.pos.x,closestGold.pos.y)
        pass

    enemy=hero.findNearestEnemy()

    if enemy:
        distanceE=hero.distanceTo(enemy)
        if distanceE<10:
            if hero.isReady("cleave"):
                hero.cleave(enemy)
            elif hero.isReady("bash"):
                hero.bash(enemy)
            else:
                hero.attack(enemy)
    #hero.moveXY(item.pos.x,item.pos.y)

    if hero.gold >= 100:
        hero.say("Hahah ! I'm the Millionaire!")
AlexeySapsay commented 6 years ago
# Be the first to 100 gold!
# If you are defeated, you will respawn at 67% gold.
#  Find coins and/or attack the enemy.
# Use flags and your special moves to win!

#1. Try use pet to collect coins
#2. Try use different type of traps

while True:

    enemy=hero.findNearestEnemy()
    item=hero.findNearestItem()

    #Reavan will delivery coin for me
    #if item.type=="coin":
    #    pet.moveXY(item.pos.x,item.pos.y)

    if enemy:
        distanceE=hero.distanceTo(enemy)
        if distanceE<10:
            if hero.isReady("cleave"):
                hero.cleave(enemy)
            elif hero.isReady("bash"):
                hero.bash(enemy)
            else:
                hero.attack(enemy)
    hero.moveXY(item.pos.x,item.pos.y)

    if hero.gold >= 100:
        hero.say("I'm very rich!")
AlexeySapsay commented 6 years ago
# Be the first to 100 gold!
# If you are defeated, you will respawn at 67% gold.
#  Find coins and/or attack the enemy.
# Use flags and your special moves to win!

#1. Try use pet to collect coins
#2. Try use different type of traps
#3. Use the best protection
#4. Use arrays and try find max coin points
#5. 

while True:

    enemy=hero.findNearestEnemy()
    item=hero.findNearestItem()

    #Reavan will delivery coin for me
    #if item.type=="coin":
    #    pet.moveXY(item.pos.x,item.pos.y)

    if enemy:
        distanceE=hero.distanceTo(enemy)
        if distanceE<10:
            if hero.isReady("cleave"):
                hero.cleave(enemy)
            elif hero.isReady("bash"):
                hero.bash(enemy)
            else:
                hero.attack(enemy)
    hero.moveXY(item.pos.x,item.pos.y)

    if hero.gold >= 100:
        hero.say("I'm very rich!")
AlexeySapsay commented 6 years ago
# Be the first to 100 gold!
# If you are defeated, you will respawn at 67% gold.
#  Find coins and/or attack the enemy.
# Use flags and your special moves to win!

#1. Try use pet to collect coins and attack
#2. Try use different type of traps
#3. Use the best protection
#4. Use arrays and try find max coin points
#5. Use to attack only abbillity, and rare stupide attack
#6. Your priority must be to collection coin 
#7 Find tactics vs lot of meat

#Find me on youtube  channel Phy Tu
#https://www.youtube.com/channel/UCP5ycahCEZ24qmRRgNnko5Q

while True:

    enemy=hero.findNearestEnemy()
    item=hero.findNearestItem()

    #Reavan will delivery coin for me
    #if item.type=="coin":
    #    pet.moveXY(item.pos.x,item.pos.y)

    if enemy:
        distanceE=hero.distanceTo(enemy)
        if distanceE<10:
            if hero.isReady("cleave"):
                hero.cleave(enemy)
            elif hero.isReady("bash"):
                hero.bash(enemy)
            else:
                hero.attack(enemy)
    hero.moveXY(item.pos.x,item.pos.y)

    if hero.gold >= 100:
        hero.say("Hahah ! I'm the Millionaire!")
AlexeySapsay commented 6 years ago
#other solution but I don't like it

def FightEnemy(enemy):
    while True:
        enemy = hero.findNearestEnemy()
        if enemy:
            distance = hero.distanceTo(enemy)
            if distance<5:
                if hero.isReady("bash"):
                    hero.bash(enemy)
                elif hero.isReady("cleave"):
                    hero.cleave(enemy)
                #else:
                    hero.attack(enemy)
        CollectCoin()

def CollectCoin(item):
    while True:
        item= hero.findNearestItem()
        if item:
            pos = item.pos
            x= pos.x
            y = pos.y
            hero.moveXY(x,y)
        FightEnemy()
while True:
    CollectCoin()
AlexeySapsay commented 6 years ago
# Be the first to 100 gold!
# If you are defeated, you will respawn at 67% gold.
#  Find coins and/or attack the enemy.
# Use flags and your special moves to win!

#1. Try use pet to collect coins and attack
#2. Try use different type of traps
#3. Use the best protection
#4. Use arrays and try find max coin points
#5. Use to attack only abbillity, and rare stupide attack
#6. Your priority must be to collection coin 
#7 Find tactics vs lot of meat

#Find me on youtube  channel Phy tu
#https://www.youtube.com/channel/UCP5ycahCEZ24qmRRgNnko5Q

# Coins here disappear after a few seconds!
# Get all the gold coins before they vanish.

while True:
    closestGold = None
    minGoldDist = 9001
    coinIndex = 0
    coins = hero.findItems()
    # Find the closest coin that is gold.
    # Remember that gold coins have a value of 3.
    for coin in coins:
        distance=hero.distanceTo(coin)
        if (distance<minGoldDist and coin.value==3)or     (distance<minGoldDist and coin.value==2)or      (distance<minGoldDist and coin.value==1):
            closestGold=coin
            minGoldDist=distance

        coinIndex+=1

    if closestGold:
        #Now go to the closest gold coin and get it!
        hero.move(closestGold.pos)
        pass

    enemy=hero.findNearestEnemy()

    if enemy:
        distanceE=hero.distanceTo(enemy)
        if distanceE<10:
            if hero.isReady("cleave"):
                hero.cleave(enemy)
            elif hero.isReady("bash"):
                hero.bash(enemy)
            else:
                hero.attack(enemy)
    hero.move(closestGold.pos)

    if hero.gold >= 100:
        hero.say("Hahah ! I'm the Millionaire!")