So I just wanted to ask, what does the simple cpu identify as? I tried enemy and target, but neither were defined. I tried using it with the distanceTo and cleave/attack.
Hi @Kyle_Byrd and welcome to the forum This is a friendly place where you can ask help on levels, report bugs, or just chat with coders. Hope you enjoy your time here!
The simple CPU is an AI that is quite simple and easy to beat. Also, enemy/target should be variables. For example:
enemy = hero.findNearestEnemy()
First, use enemy =hero.findNearestEnemy
You can also use target=hero.findNearestEnemy.
BUT you MUST include one of them.
And then, based on that variable, you can use:
if enemy: hero.attack(enemy)
or the duck will yell at you.
Welcome to the forum! This is a family-friendly place where coders can share bugs, ask for help on any CodeCombat level (don’t forget to post your code correctly), or just hang out with other coders. But before you proceed, please check out our guidelines: this topic.
Have a great time!
Lol, you really like that duck, don’t you?
I hate that duck, it’s got something wrong with it’s AI. Once I didn’t have an error and the duck kept popping out saying “t.code is not allowed”.
the cpu doesn’t identify as an enemy for some reason, here is my code, i tried setting up the flags first.
while True: # Find coins and/or attack the enemy. # Use flags and your special moves to win! green = hero.findFlag("green") black = hero.findFlag('black') enemy = hero.findNearestEnemy() distance = hero.distanceTo(enemy) item = hero.findNearestItem() if green: hero.moveXY(flag.pos.x, flag.pos.y) elif black and hero.isReady("cleave"): hero.cleave(enemy) elif enemy and distance < 8: hero.attack(enemy) pass ```
You have to define enemy first using
enemy = hero.findNearestEnemy().
It is already wirtten
Ah, they don’t have twilight glasses, if they don’t, they can’t see the opponent until they go into the other room.
The problem is that you are not you’re picking up your flags, which means they’ll just stay there. What you need to use is hero.pickUp(flag) Another more important issue is that you are using two different variables here:
green and flag, and you haven’t defined flag, so just use green (with hero.pickUpfFlag() as I mentioned above).
You need to do the same for black, just make sure you place the flag on the hero so he doesn’t run for miles collecting it when you just want to cleave.
Finally, you may not be attacking the enemy just because you’re more than 8m away, so make sure you use the green flag to take you very close to the enemy.