Subversion Repositories programming

Rev

Rev 335 | Rev 338 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 335 Rev 336
Line 35... Line 35...
35
    // to this floor. If there is already one, ignore this
35
    // to this floor. If there is already one, ignore this
36
    // request.
36
    // request.
37
    if (floor_already_requested (on_floor))
37
    if (floor_already_requested (on_floor))
38
        return;
38
        return;
39
 
39
 
40
    //puts("2");
-
 
41
 
-
 
42
    // find elevator that is closest, AND NOT moving away
40
    // find elevator that is closest, AND NOT moving away
43
    // "push" it's button
41
    // "push" it's button
44
    elevator_number = find_closest_elevator (on_floor, direction);
42
    elevator_number = find_closest_elevator (on_floor, direction);
45
    elevator.at(elevator_number) -> push_button (on_floor);
43
    elevator.at(elevator_number) -> push_button (on_floor);
46
 
44
 
Line 51... Line 49...
51
 * Check if there is an elevator already in the queue to stop
49
 * Check if there is an elevator already in the queue to stop
52
 * at the floor given as a parameter.
50
 * at the floor given as a parameter.
53
 */
51
 */
54
bool Controller::floor_already_requested (int on_floor)
52
bool Controller::floor_already_requested (int on_floor)
55
{
53
{
-
 
54
    assert (on_floor >= 0);
-
 
55
    assert (on_floor < num_floors);
-
 
56
 
56
    int i;
57
    int i;
57
 
58
 
58
    for (i=0; i<num_elevators; i++)
59
    for (i=0; i<num_elevators; i++)
59
        if (elevator.at(i) -> button_is_pushed (on_floor))
60
        if (elevator.at(i) -> button_is_pushed (on_floor))
60
            return true;
61
            return true;
Line 70... Line 71...
70
 * heading in the right direction, or the closest elevator
71
 * heading in the right direction, or the closest elevator
71
 * if it is sitting idle.
72
 * if it is sitting idle.
72
 */
73
 */
73
int Controller::find_closest_elevator (int to_floor, int in_direction)
74
int Controller::find_closest_elevator (int to_floor, int in_direction)
74
{
75
{
-
 
76
    assert (to_floor >= 0);
-
 
77
    assert (to_floor < num_floors);
-
 
78
    assert (in_direction == MOVE_UP || in_direction == MOVE_DOWN);
-
 
79
 
75
    int i;
80
    int i;
76
    float distance = INT_MAX;
81
    float distance = INT_MAX;
77
    float temp_distance;
82
    float temp_distance;
78
    int answer = -1;
83
    int answer = -1;
79
 
84