Play Home Contribute GitHub Join Us Discourse Staff Members GitHub Contribution Guides Team

Mine coding problem on Thunderhooves


Hello I am new to Code Combat, so using python I have some problem with my code it seems it is succeeding but I know its not right.

my code is this

    yak = self.findNearestEnemy()
    x = self.pos.x        
    y = self.pos.y
    if yak:
        yakPos = yak.pos
        yx = yakPos.x
        yy = yakPos.y                        
        if yy > y:
            y = y + 2          
            self.buildXY("fence", x, y)
            y = y - 2
            self.buildXY("fence", x, y)
        x = self.pos.x + 10   
        self.moveXY(x, y)


i dont actually see a problem with this.
if you are cunfused with all of these x and yx and so on, you can directly use “self.pos.x” and “yak.pos.y”


The comments clearly state to build 10 meters above/below you. Did you try this?

Despite from that it looks good. You maybe should use more speaking variable-names. You named yakPos in a way I can immediately see what it contains. Why not also yakX and yakY?


you know its really fast for typing and I tried that too also it doesn’t work at 10 or 5


Then it would slowly help to see some screenshots of the situation.


I think the problem is that you have the fence being built where you’re standing. I think you need to move it to where you were just standing, so instead of “self.buildXY(“fence”, x, y)”, try "self.buildXY(“fence”, x + 2, y + 2) and "self.buildXY(“fence”, x - 2, y - 2)