Level: Boulder Woods


#1

It seems like this level doesn’t have enough explanation or ???

I do what it says I am to do (add an “if”, a “move”, and a “else:”) and my hero runs NE until she gets stuck trying to walk through the forest to the north. (She white-dots along the north edge in the upper alcove.) It looks like once she puts the “go here marker” in the woods she never recovers (never places another).


#2

Looks like isPathClear(self, targetPos) wasn’t working. I had tried to set it up for isPathClear(self.pos, targetPos), but it wasn’t also accepting self in place of self.pos. It should be good to go now.


#3

It’s working perfectly now.


#4

Sweet, thanks!! :smiley:


#5

I don’t think it’s a very good example of the move vs moveXY.
If I well understand the code (not sure), we should be able to do the same with moveXY, as we’re sure the path is clear.
I tried.
Problem : the hero can’t reach the target position in some cases. I suppose the isPathClear check the intermediate position are clear, but it seems that it does not ensure that the destination is clear also. The last step is missing.

Appart this trouble, I’m afraid it could mislead people to the real use of move (if I well understand it myself, I just suppose it’s the equivalent of the move in the ancien levels). And also the math stuff could be a fog on the use of the move. Even if it’s a really good example of angle management.

Edit : in the code given at startup, there is some “self” in javascript, instead of “this”.


#6

Hmm, it does check both intermediate paths and destination to see if they are clear, but it only has a resolution of 1m. Maybe you’re colliding with an obstacle that doesn’t overlap the target by 1m. This happens with the normal solution?

I fixed the self.


#7

I don’t know what’s the behavior of move with a collision. With moveXY, it says it can’t get there, but not with move.
With this code with move, you never really reach the target, so I don’t really know.


#8

in level Slalom the isPathClear methods does not identify bear trap and always be the “true”.


#9

Ah, right; I haven’t hooked it up to know about hazards as trap yet (and findHazards doesn’t work yet, either). I’ll get it hooked up for next week’s levels.


#10

Hmmm…

Also unclear on how to use the tools to achieve the objective.

I’m not clear how to “sweet the angle” in Cartesian coordinates.


#11

I would agree with there not being enough explanation (or I’m more dense then most).
As you can see I have tried different combinations of code that have resulted in either no movement or an error. I guess what the different code really shows is that I have no idea what I’m doing or supposed to be doing. Any help is appreciated and some explanation/clarification would be even more helpful. Thanks

# Use isPathClear to move around the randomly positioned boulders.
# Automatic pathfinding doesn't work in Boulder Woods.

# Runs out of time, hero never moves
target = ({'x': 76, 'y': 34})

# target not defined, line 7 highlighted red
# target.pos = ({'x': 76, 'y': 34})

# line 15 "Math.sin(angle)" highlighted in Green, line 18 'target' highlighted red - target not defined
# targetPos = ({'x': 76, 'y': 34})

loop:
    angle = Math.PI / 2 - Math.PI / 16
    while angle >= -Math.PI / 2:
        targetX = self.pos.x + 5 * Math.cos(angle)
        targetY = self.pos.y + 5 * Math.sin(angle)
        # Use isPathClear between your current pos and the target.
        # If the path is clear, move to the target.
  
        # nothing happens, hero never moves
        if self.isPathClear(self, target):
        
        # isPathClear target not defined - target.pos highlighted green when using line 5
        # line 8 error: target not defined
        # if self.isPathClear(self.pos, target.pos):
        
        # hard excecution limit exceeded
	# if self.isPathClear(self.pos, target.pos):
		
	# hard excecution limit exceeded - line 15 'Math.PI' highlighted green
	# if self.isPathClear(selfPos, targetPos):
            self.move(target)
	    # self.move(target.pos)
	    # self.move(targetPos)
        # Otherwise, sweep the angle clockwise a bit.
        angle -= Math.PI / 16

#12

I sent you an email, too, but for any others reading:

The syntax is a bit tricky; there’s more practice with it in the mountain. Here’s one way to do it:

targetX = self.pos.x + 5 * Math.cos(angle)
targetY = self.pos.y + 5 * Math.sin(angle)
target = {"x": targetX, "y": targetY}

Then you can use:

if self.isPathClear(self, target):
    self.moveXY(targetX, targetY)

#13

Or you can just do it the cheap way
hero.moveXY(23, 44)
hero.moveXY(49, 40)
hero.moveXY(71, 47)
hero.moveXY(76, 46)
hero.moveXY(76, 34)