icp/oer/courses/c-newcomers/sections/03-lift/06-more-requests/content.md

1.4 KiB

The lift controller is almost complete. It needs to be able to have more than just one pending floor and it needs a way to get new requests. Let's concentrate on the first thing first.

Knowledge

We already know how to speak in terms of multiple variables. We just use an array. There are at least two reasonable solutions, on how to implement this array to encode the pending floors. We could have an array, where each index stands for a floor and the value for whether or not the floor is pending. The other way would be just a list of all the pending floors, but then we need a way of marking indices the lift already finished. For example we could use the Value -1, this only works of course, if we don't have underground floors.

Model

We think the first solution is a bit cleaner. So in our model we have the array, where every index is a floor. That way we also don't have to worry about duplicates. The array in question is called PendingFloors.

Because we have more pending floors, we now also have to check if we reached all, if not we have to keep going. And on every level we have to check if the floor we are on is a pending floor.

Task

Change the program to support multiple pending floors. When choosing the next target floor, use the first not finished floor from the pending floor array. The lift will not reach every floor, because we don't simulate enough time-steps.