-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathMove.h
More file actions
executable file
·178 lines (160 loc) · 5.14 KB
/
Move.h
File metadata and controls
executable file
·178 lines (160 loc) · 5.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
/*
* Copyright 2023 University of Michigan EECS183
*
* Move.h
* Project UID 28eb18c2c1ce490aada441e65559efdd
*
* Final Project - Elevators
*/
#ifndef _MOVE_H_
#define _MOVE_H_
#include <string>
#include "Utility.h"
#include "Floor.h"
#include "Elevator.h"
//////////////////////////////////////////////////
/////// DO NOT MODIFY ANY CODE IN THIS FILE //////
/////////// ANY CONSTANTS/ETC SHOULD /////////////
////////////// BE ADDED IN THE .CPP //////////////
//////////////////////////////////////////////////
class Move {
private:
int elevatorId;
int targetFloor;
int peopleToPickup[MAX_PEOPLE_PER_FLOOR] = {};
int numPeopleToPickup;
int totalSatisfaction;
bool isPass; //just hitting enter is a move
bool isPickup;
bool isSave;
bool isQuit;
public:
/**
* 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);
/**
* 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;
/**
* 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);
/**
* Requires: nothing
* Modifies: Move object
* Effects: initializes a Move object
*
*/
Move();
/**
* Requires: nothing
* Modifies: nothings
* Effects: returns the value of isPass
*
*/
bool isPassMove() const;
/**
* Requires: nothing
* Modifies: nothings
* Effects: returns the value of isSave
*
*/
bool isSaveMove() const;
/**
* Requires: nothing
* Modifies: nothings
* Effects: returns the value of isQuit
*
*/
bool isQuitMove() const;
/**
* Requires: nothing
* Modifies: nothing
* Effects: returns the value of isPickup
*
*/
bool isPickupMove() const;
/**
* Requires: nothing
* Modifies: nothing
* Effects: returns the elevatorId
*
*/
int getElevatorId() const;
/**
* Requires: nothing
* Modifies: nothing
* Effects: returns the targetFloor
*
*/
int getTargetFloor() const;
/**
* Requires: nothing
* Modifies: nothing
* Effects: returns the number of people being picked up by
* this move (-1 if not pickup move)
*
*/
int getNumPeopleToPickup() const;
/**
* Requires: nothing
* Modifies: nothing
* Effects: returns totalSatisfaction
*
*/
int getTotalSatisfaction() const;
/**
* Requires: inTargetFloor is a valid floor
* Modifies: targetFloor
* Effects: sets the targetFloor to inTargetFloor
*
*/
void setTargetFloor(int inTargetFloor);
/**
* Requires: newList is a valid array
* Modifies: newList
* Effects: copies peopleToPickup into newList
*/
void copyListOfPeopleToPickup(int newList[MAX_PEOPLE_PER_FLOOR]) const;
};
#endif