[Solved] Explosive works! 😄


#1

i don’t know what is wrong pls help

# Place explosives to clear a passage to the dungeon.

# The mines should form a rectangle with this perimeter.
perimeter = 160
# The bottom left corner of the rectangle.
bottomLeft = {"x": hero.pos.x, "y": hero.pos.y}

# One mine is placed already.
topLeft = hero.findHazards()[0].pos
# So we can find the height of the rectangle.
height = hero.distanceTo(topLeft)
# Find the width. Use the perimeter and height to calculate it.
w = (perimeter - 2 * height) / 2

# First, we need to place a mine in the bottom left corner.
hero.buildXY("fire-trap", bottomLeft.x, bottomLeft.y)
# Put a mine in the bottom right corner.
hero.buildXY("fire-trap", bottomLeft.x + 48, bottomLeft.y)
# Put a mine in the top right corner.
hero.buildXY("fire-trap", bottomLeft.x + 48, topLeft.y )

# Now go to the demolitionist.
hero.moveXY(74, 32)
# Calculate the area of the rectangle to know the charge.
a = height * w
# Say the area of the rectangle to start the explosion.
hero.say(a)


#2

Should be bottomLeft.x + 44 if you want to do it the hard way. You should be calculating the length based on the perimeter though.

Edit: Nevermind. the +44 or +48 can vary. So you have to calculate based on perimeter.


#3

How do i do that @SuperSmacker?


#4

length = (Perimeter - hero.distanceTo(topLeft))/2


#5

still not working @SuperSmacker


#6

You did it wrong. You are supposed to add the length TO the bottomLeft.pos.x, not just dump it there.


#7

Ohhhh (20 chars) Deadpool pls kill 20 chars


#8

this is what happens @SuperSmacker


#9

In your code you defined height as hero.distanceTo(topLeft), and then you defined length as (perimeter - 2 * height)/2, which doesn’t make sense. The height is the width. so delete you width variable and replace the area as height * length. Gosh seriously proofread your code yourself.

The mistakes you make are primitive. Try to find them yourself before blaming me for everything.


#10

But are the placing of the mines are correct?


#11

Yeah. (die 20 chars die)


#12

it’s still not working. Sorry i am getting confused

# Place explosives to clear a passage to the dungeon.

# The mines should form a rectangle with this perimeter.
perimeter = 160
# The bottom left corner of the rectangle.
bottomLeft = {"x": hero.pos.x, "y": hero.pos.y}

# One mine is placed already.
topLeft = hero.findHazards()[0].pos
# So we can find the height of the rectangle.
height = hero.distanceTo(topLeft)
# Find the width. Use the perimeter and height to calculate it.
length = (perimeter - hero.distanceTo(topLeft))/2

# First, we need to place a mine in the bottom left corner.
hero.buildXY("fire-trap", bottomLeft.x, bottomLeft.y)
# Put a mine in the bottom right corner.
hero.buildXY("fire-trap", bottomLeft.x + length, bottomLeft.y)
# Put a mine in the top right corner.
hero.buildXY("fire-trap", bottomLeft.x + length, topLeft.y)

# Now go to the demolitionist.
hero.moveXY(74, 32)
# Calculate the area of the rectangle to know the charge.
a = height * length
# Say the area of the rectangle to start the explosion.
hero.say(a)


#13

Found the problem.
Change length = (perimeter - hero.distanceTo(topLeft))/2 to length = (perimeter - 2 * hero.distanceTo(topLeft))/2.

After that you are all set.


#14

THANK YOU @SuperSmacker it worked!


#15

It also took me a while to figure that out. Never thought of going to the forum at the time.