-
Notifications
You must be signed in to change notification settings - Fork 341
Open
Description
Steps
- elevator is on the way to
0, - elevator has detected that there's someone waiting on
1 - downIndicator is
ONsince that's the direction the elevator is going - elevator stops
Observation
- user doesn't climb aboard.
Expectation
- since the elevator is going in the right direction the expectation is that the user climb aboard
Code
Click to view code!
{
init: function(elevators, floors) {
// hasWaitingPeople :: Int -> "up" | "down" | undefined -> Boolean
const hasWaitingPeople = (floorNum, direction) => {
const source = floors.find(fl => fl.floorNum() === floorNum)
if(source === undefined)
throw new Error(`Could not find floor ${floorNum}`)
const {up, down} = source.buttonStates
return direction === undefined
? up === "activated" || down === "activated" : direction === "down"
? down === "activated" : up === "activated"
}
// setIndicator :: El -> Int -> void
const setIndicator = (el, destination) => {
const currentFloor = el.currentFloor()
if(destination > currentFloor) {
el.goingUpIndicator(true)
el.goingDownIndicator(false)
}
else {
el.goingUpIndicator(false)
el.goingDownIndicator(true)
}
}
// Elevator Listeners
for(el of elevators) {
el.on("floor_button_pressed", function(destination) {
console.log("Go To: ", destination)
setIndicator(el, destination)
// insert based on direction
el.goToFloor(destination, true)
});
el.on("passing_floor", function(floorNum, direction) {
if(el.loadFactor() < 1 && hasWaitingPeople(floorNum, direction)) {
console.log('Stopped:', floorNum, direction)
el.stop()
console.log("indicators:", el.goingUpIndicator(), el.goingDownIndicator())
}
});
el.on("stopped_at_floor", function(floorNum) {
console.log("STOPPED at: ", floorNum)
if(el.destinationQueue.length === 0) {
el.goingUpIndicator(true)
el.goingDownIndicator(true)
}
})
el.on("idle", function() {
const allStates = floors.filter(fl => hasWaitingPeople(fl.floorNum())).map(fl => fl.floorNum())
console.log('Idle: ', allStates)
const target = Math.max(...allStates)
setIndicator(el, target)
el.goToFloor(target)
});
}
},
update: function(dt, elevators, floors) {
}
}
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels
