Move is a class declared in Move.h and is responsible for representing what a Player (either a Human or AI) wants to do on a particular turn of the Game. The Game will take this move, validate it, and apply it to the Building, which will change its state accordingly.

When a player types in a specially formatted string into the game display, the code will parse it and convert it into a Move object.

There are four types of Moves that the player can input:

For details as to how the user can format these inputs, see this section.

Member Data

Note that a Service Move is represented by isPass, isPickup, isSave, and isQuit all being false.

Member Functions

Many member functions have been written for you. Please refer to their RME’s for reference on how to use them.

You will be writing the implementation for the following function:


 * Requires: commandString is a valid string
 * Modifies: elevatorId, targetFloor, isPass, isPickup, isSave, isQuit
 * Effects:  creates a Move object based on
 *           the characters in commandString
 *           Examples:
 *           commandString = "e1f4"; - elevatorID of 1 has a targetFloor of 4
 *           commandString = "e1p"; - elevatorID of 1 will pickup people on
 *                                    its current floor
 *           when commandString is "", or "S", or "Q", etc.:
 *                sets the corresponding private data member to true
Move(string commandString);

Move has a single non-default constructor which parses a special string to initialize a Move’s data members. Refer here for details on how the input string will be formatted. This input commandStringwill be what the user types in when asked to enter a Move, and this constructor will be used to turn their input into a Move object that our code can use.

If you’re using a stringstream for this, keep in mind that we shouldn’t be reading any characters from our stringstream if commandString is empty (i.e. a Pass move).

Walkthrough video

You can find this and other walkthroughs in the Google drive folder for the project here.


 * Requires: elevators represents the elevator servicing states
 * Modifies: nothing
 * Effects:  returns true if this Move instance is valid, false otherwise
 *           The following are the criterion for validity:
 *           If a move is a Pass Move, a Quit Move, or a Save Move it is valid
 *           For both Pickup Moves and Servicing Moves:
 *               0 <= elevatorId < NUM_ELEVATORS
 *               The corresponding Elevator is currently not
 *                  servicing a request.
 *           For Servicing Moves only:
 *               0 <= targetFloor < NUM_FLOORS
 *               targetFloor is different from the corresponding
 *                  Elevator's currentFloor
bool isValidMove(Elevator elevators[NUM_ELEVATORS]) const;

This function is responsible for ensuring the move is valid. Below are the criterion to determine validity:

The function argument elevators represents the current state of all the elevators in the building, so be sure to use that to verify some of these conditions.


* Requires: pickupList is a valid list of indices
*           currentFloor is the floor number where the pickup
*             is taking place
*           pickupFloor is the Floor instance where the pickup
*            is taking place
* Modifies: numPeopleToPickup, peopleToPickup, totalSatisfaction, targetFloor
* Effects:  sets numPeopleToPickup and totalSatisfaction to 0
*           adds the indices specified in pickupList to peopleToPickup
*           increments numPeopleToPickup by 1 for each person being picked up
*           adds satisfaction gained from each person picked up to totalSatisfaction
*           sets targetFloor to be the most extreme floor of those being picked up (furthest up or down)
void setPeopleToPickup(const string& pickupList, const int currentFloor, const Floor& pickupFloor);

This function takes in a validated string of indices, converts them into integers, and stores them inside peopleToPickup. For example, if pickupList contains "0347", then peopleToPickup would need to contain the indices 0, 3, 4, and 7.

While it does this, it also tracks a few other things:

Walkthrough video

Function Table

The table below provides an outline of which other functions each function should call, if any. The functions listed here do not include any library functions you may wish to use. Please look at the starter code section of the spec to see which libraries you are allowed to use.

Function Other functions it should call
Move() This function does not call any other functions
isValidMove() Elevator::isServicing(), Elevator::getCurrentFloor()
setPeopleToPickup() Floor::getPersonByIndex(), Person::getAngerLevel(), Person::getTargetFloor()