In this game, the aim is to get to the other side of the crevice by means of a turbo elevator. This consists of a number of horizontal platforms that were placed one after the other. The platforms vertically move up and down, and operate independently. You can only jump to the next platform, if it is situated on the same height as the platform you are on at the moment.

turbo elevator

Assignment

An initial level and an initial direction (going up, going down or standing still) is set for every platform at the beginning of the game. Furthermore, a lowest and highest level is set for every platform, these can not be changed afterwards. With every next time step, the platform moves one level up or down, or it stands still and stays in the same position. If the platform has reached the lowest (resp. highest) level, it will move back up (resp. down) from the next time step. A platform for which the lowest level is equal to the highest level, or for which was indicated that it is immobile, stays in the same position with every time step. Write a class Platform that can be used to model such platforms. For this, an object of the class Platform must contain the following methods:

>>> platform = Platform(0, Platform.OP, -1, 1)
>>> platform.position
0
>>> for steps in range(5):
...     platform.next()
...     print(platform.position)
1
0
-1
0
1
>>> platform = Platform(1, Platform.DOWN, 1, 1)
>>> for steps in range(3):
...     print(platform.position)
...     platform.next()
1
1
1
>>> platform = Platform(3, Platform.STILL)
>>> for steps in range(3):
...     print(platform.position)
...     platform.next()
3
3
3
>>> platform = Platform(-3, Platform.UP, -1, 1)
Traceback (most recent call last):
AssertionError: invalid configuration

Now, also write a class TurboElevator, of which every object represents a turbo elevator that is built from a number of platforms. The first and last platform represent the starting point and the other side of the crevice, but do not have to be on the same level, and also do not have to stand still. To make an object of the class TurboElevator, no arguments must be given. In the beginning the turbo elevator does not have any platforms yet, but an extra platform can be added at any time. Decide for yourself if it is necessary to provide an __init__ method for the class TurboElevator, and how it should be implemented. Objects of the class TurboElevator must however contain the following methods:

>>> turboElevator = TurboElevator()
>>> turboElevator.add(Platform(0, Platform.STILL)) 
>>> turboElevator.add(Platform(2, Platform.DOWN, -2, 2)) 
>>> turboElevator.add(Platform(0, Platform.UP, 0, 4)) 
>>> turboElevator.add(Platform(0, Platform.DOWN, -4, 0)) 
>>> turboElevator.add(Platform(0, Platform.DOWN, -2, 4)) 
>>> turboElevator.add(Platform(0, Platform.STILL)) 
>>> turboElevator.timesteps()
16
>>> turbo elevator.add(Platform(4, Platform.OP, 2, 8)) 
>>> print(turboElevator.timesteps())
None