|
|
@@ -31,6 +31,7 @@ eval({
|
|
31
|
31
|
// returns the closest floor from that list in the given
|
|
32
|
32
|
// direction that is not part of the ignored floors list. Ties
|
|
33
|
33
|
// are broken by even/oddness of the current floor.
|
|
|
34
|
+ // TODO: fix direction shadowing/usage
|
|
34
|
35
|
function getClosestFloor(currentFloor, floorList, ignoredFloors = new Set(), direction = IDLE) {
|
|
35
|
36
|
const isEven = (currentFloor % 2 == 0);
|
|
36
|
37
|
|
|
|
@@ -46,11 +47,11 @@ eval({
|
|
46
|
47
|
closestFloor = floorNum;
|
|
47
|
48
|
distance = newDistance;
|
|
48
|
49
|
} else if (newDistance == distance && !(ignoredFloors.has(floorNum))) {
|
|
49
|
|
- if (isEven && direction == UP) {
|
|
|
50
|
+ if ((isEven && direction == UP) ||
|
|
|
51
|
+ (!isEven && direction == DOWN) ||
|
|
|
52
|
+ (direction == IDLE && Math.random() < 0.5)) {
|
|
50
|
53
|
closestFloor = floorNum;
|
|
51
|
|
- } else if (!isEven && direction == DOWN) {
|
|
52
|
|
- closestFloor = floorNum;
|
|
53
|
|
- }
|
|
|
54
|
+ }
|
|
54
|
55
|
}
|
|
55
|
56
|
});
|
|
56
|
57
|
|