Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function wander(who) {
let result = Promise.resolve();
if (ROT.RNG.getUniform() < rules.AI_IDLE) { return result; }
let level = who.getLevel();
let xy = who.getXY();
let dirs = DIRS.filter(dxy => {
let entity = level.getEntity(xy.plus(dxy));
return entity.blocks < BLOCKS_MOVEMENT;
});
if (!dirs.length) { return result; }
let dir = dirs.random();
who.moveTo(xy.plus(dir));
return result;
}