-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBoat.cpp
52 lines (49 loc) · 1.24 KB
/
Boat.cpp
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
#include "Boat.h"
#include "tool.h"
using namespace std;
void Boat::act(std::vector<Berth *> &BerthList)
{
if (this->state == 1)
{
if (this->target == -1)
{
// 1. 在虚拟点,已经完成送货
this->loaded_cargo_num = 0;
Allocator alloc;
Berth *target_berth = alloc.alloc_boat_berth(this, BerthList);
cout << "ship " << this->id << " " << target_berth->id << endl;
}
else
{
// 2. 在泊位装货
Berth *berth = BerthList[this->target];
int boat_left_space = Boat::capacity - this->loaded_cargo_num;
// 能装就装
if (boat_left_space && berth->cargo_values.size())
{
berth->give_boat(this);
}
// 不能装就走
else
{
cout << "go " << this->id << " " << endl;
}
}
}
else if (this->state == 0)
{
// 移动中, 以下情况由判题器自动维护
if (this->target == -1)
{
// 3. 送货到虚拟点
}
else
{
// 4. 送货到泊位
}
}
else
{
// 5. 泊位外等待
}
}