Reading and Writing
User Input: Moves
Move class represents an action the user wishes to take while they are playing the game. There are 4 types of Moves:
- Pass Move: Do nothing this turn.
- Service Move: Send an elevator to a particular floor
- Pickup Move: Tell an elevator to pick up people from the floor that it is on.
- Game Move: Save or quit the game.
A user enters a pass move using the empty string
A service move directs an empty elevator to go to a floor. They are input by the user in the following format:
For example, this is a service move requesting elevator 1 to move to floor 4:
string serviceMove = "e1f4";
A pickup move directs an empty elevator to pick up people on the floor it is currently on then initiate travel to the farthest floor that those people wish to go. Not all the people waiting on the current floor need to be picked up, so the user will be given the chance to select which people will be picked up after they enter a pickup move.
pickup moves can be expressed with the following
For example, this will direct elevator 1 to pick up some people on its current floor then begin to move to the farthest floor those people wish to go:
string pickupMove = "e1p";
Moves that affect the status of the game are Game moves. The two Game moves are save and quit, which are represented by either an uppercase or lowercase
File Input/Output: Saved Games
The game has a save game format which is used when starting new games or resuming saved games. The file format has 4 sections:
- The current score of the player
- The last tick completed by the game
- The current state of the elevators
- The ticks and locations where people will spawn
Here is an example of a saved game file (the comments are not part of the file):
0 // 1. The current score of the player (5 lines) 0 0 0 0 0 // 2. The last tick completed by the game 0w // 3. The current state of the elevators 0w 0w 0f1t9a1 // 4. The ticks and locations where people will spawn 1f0t8a0 2f0t9a0
1. Current score
The current score is stored in an instance of
SatisfactionIndex, which has overloaded
operator<< to read and write to streams. The provided
Game::initGame() function can help with reading the score.
2. Last tick completed
For new games, this will be 0. For saved games, this is an integer representing the last completed tick number.
3. Elevator state
The next lines describe what the elevators are currently doing. We have provided all the code for reading and writing Elevator states.
Game::initGame() will handle reading elevator state from a stream.
Elevator::print() can be used to write to a file.
waiting elevators can be expressed with the following
string waitingElevator = "0w";
This elevator is waiting on floor 0.
When we save elevators to a file, we save them in index-order:
elevator elevator ... elevator[NUM_ELEVATORS - 1]
Because of this, we do not need to save the
elevatorId. We assume that the first
elevator state read in belongs to an elevator at
index 0, the second
elevator state read in at
index 1, and so on.
servicing elevators can be expressed with the following
string servicingElevator = "1s4";
This elevator is currently on floor 1, servicing to floor 4.
4. The ticks and locations where people will spawn
The game will spawn people at the times listed. You will implement the
Person::Person(string) constructor which parses input strings into
Person objects, and the
Person::print(ostream &) member function for output.
string personInfo = "7f4t8a3";
On tick 7, a person will appear on floor 4 wanting to go to floor 8. They have an anger level of 3.
When saving games, all Person objects that have already spawned must have the
tick field set to 0, even if the game is currently at a later tick.