3

In Untrusted, how can I pass the many attack and defense droids?

I've tried going down, but they get stuck; I tried sending them right, but they cover the exit.

enter image description here

1
  • Alternative approach: override onCollision so you can just walk right through the enemies. Apr 10, 2014 at 5:14

5 Answers 5

1

For the red drones, give the following:

if(me.getY()>11)
    me.move('up');
else if(me.getX()>0)
    me.move('left');

The yellow drones can be given this:

me.moveToward('block');

Give the green drones this code:

if(me.getY()>11)
    me.move('up');
else if(me.getX()<map.getWidth()-1)
    me.move('right');

Just move right and the red and green drones will line up and move towards the top corners.

Line 'em up

3

Something easy and simple.

Red Drones

  me.move('left');
  map.placeObject(12, 12, 'block');

Yellow and Green Drones

  me.move('left');

My solution

2

I solved this by simply giving every single drone a random chance to go either 'up' or 'right'.

var z = Math.floor(Math.random() * 2) + 1
switch(z){
case(1):
  me.move('up');
  break;
case(2):
  me.move('right');
  break;
}

Copy and paste to all three drones.

2

I found a cooler way, take a look: red:

moveToward(me, 'dummy1');

nothing at all in yellow

green:

        moveToward(me, 'dummy2');
    }
});
map.defineObject('dummy1', {
    'type': 'dynamic',
    'symbol': 'R',
    'color': 'white',
    'behavior': function (me) {
            }
});

map.defineObject('dummy2', {
    'type': 'dynamic',
    'symbol': '+',
    'color': 'white',
    'behavior': function (me) {
            }
});

map.placeObject(2, 13, 'dummy1');
map.placeObject(42, 11, 'dummy2');

map.defineObject('dummy3', {
    'type': 'dynamic',
    'symbol': '=',
    'color': 'white',
    'behavior': function (me) {`

I love my answer.

1

Red Drones - keep moving the drones left and move your guy up one to avoid them as they approach.

if (me.getY()>11) {
  me.move('left');
} 

Yellow Drones

Nothing, leave the yellow drones right where they are

Green Drones - keep moving the middle drone (y==12) to the right until it reaches (12,29) at which time you move it up one to get it out of way of the exit block

if (me.getY()==12) {
    if (me.getX()==29) {
         me.move('up');
     } else {
         me.move('right');
     }
} 

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .