Skip to content

Latest commit

 

History

History
36 lines (31 loc) · 806 Bytes

12_robotNav.md

File metadata and controls

36 lines (31 loc) · 806 Bytes

Autonomous Robot

donmccurdy

    map.defineObject('robot', {
        // ...
        'behavior': function (me) {
          	me.path = me.path || [];
            if (me.path.length) {
            	me.move(me.path.pop());
	        } else if (me.canMove('down')) {
                me.move('down');
            } else if (me.canMove('right')) {
                me.move('right');
            } else {
            	me.path = [
     	  			'right', 'right', 'right',
                    'up', 'up', 'up', 'up', 'up',
                    'left', 'left', 'left', 'left'    
                ];
            }
        }
    });

Jhack (giacgbj)

me.move( 
	me.getX() < 25 || me.getX() > 47 ?
		me.canMove('down') ? 'down' : 'right' :
		me.canMove('up') ? 'up' : 'right'
);