-
Notifications
You must be signed in to change notification settings - Fork 0
/
purchase1.py
161 lines (135 loc) · 6.03 KB
/
purchase1.py
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
# -*- coding: utf-8 -*-
"""
Created on Fri May 25 22:22:03 2018
@author: bangwei
"""
# -*- coding: utf-8 -*-
"""
Created on Thu May 24 21:53:07 2018
@author: bangwei
"""
import sys
#######购买飞机 策略 分类 按比例购买
def purchasefly(pstMapInfo, pstMatchStatus):
purchase_plane=[]
pstUAV_price=pstMapInfo["UAV_price"]
pstUAV_we=pstMatchStatus["UAV_we"]
pstgoods=pstMatchStatus["goods"]
we_value=pstMatchStatus["we_value"]
pstUAV_enemy=pstMatchStatus["UAV_enemy"]
pstfly_load_xiao=[]
pstfly_load_da=[]
goods_keguihua=[]
for i in range(len(pstgoods)):
if pstgoods[i]["status"]==0:
goods_keguihua.append(pstgoods[i])
pstUAV_price.sort(key=lambda x: x['load_weight'])
pstfly_load_xiao=pstUAV_price # 按载重从小到大 排序
##########################################################
def qu_bianhao(zidian): #取编号
result=[]
for i in range(len(zidian)):
result.append(zidian[i]["type"])
return result
#######################################################
pstUAV_price.sort(key=lambda x: x['value'])
pstfly_value_xiao=pstUAV_price
ab=0
for i in range(len(pstUAV_enemy)):
if pstUAV_enemy[i]["status"]!=1:
ab=ab+1 # 敌军在役 飞机总数
cd=0
for i in range(len(pstUAV_we)):
if pstUAV_we[i]["type"]==pstfly_value_xiao[0]["type"] and pstUAV_we[i]["status"]!=1:
cd=cd+1 # 我军在役 最烂无人机数
while ab > cd:
if we_value <pstfly_value_xiao[0]["value"]: # 购买最烂无人机 攻击敌军 保卫我军
break
if we_value >= pstfly_value_xiao[0]["value"]:
aa={"purchase": pstfly_value_xiao[0]["type"]}
purchase_plane.append(aa)
we_value=we_value-pstfly_value_xiao[0]["value"]
cd=cd+1
#########################################################
pstUAV_price.sort(key=lambda x: -x['load_weight']) # 按载重从da到小 排序
pstfly_load_da=pstUAV_price
#最重飞机 购买
cc=0
bb=0
for i in range(len(pstgoods)):
if pstfly_load_da[1]["load_weight"]< pstgoods[i]["weight"] <=pstfly_load_da[0]["load_weight"]:
cc=cc+1
if 3<=cc:
for m in range(len(pstUAV_we)):
if pstUAV_we[m]["type"]==pstfly_load_da[0]["type"]:
bb=bb+1
if cc/3 > bb:
if we_value >=pstfly_load_da[0]["value"]:
aa={"purchase":pstfly_load_da[0]["type"]}
purchase_plane.append(aa)
we_value=we_value-pstfly_load_da[0]["value"]
#第二重飞机 购买
cc=0
bb=0
for i in range(len(pstgoods)):
if pstfly_load_da[2]["load_weight"]< pstgoods[i]["weight"] <=pstfly_load_da[1]["load_weight"]:
cc=cc+1
if 4<=cc:
for m in range(len(pstUAV_we)):
if pstUAV_we[m]["type"]==pstfly_load_da[1]["type"]:
bb=bb+1
if cc/4 > bb:
if we_value >=pstfly_load_da[1]["value"]:
aa={"purchase":pstfly_load_da[1]["type"]}
purchase_plane.append(aa)
we_value=we_value-pstfly_load_da[1]["value"]
#第3重飞机 购买
if len(pstfly_load_da)>=4:
cc=0
bb=0
for i in range(len(pstgoods)):
if pstfly_load_da[3]["load_weight"]< pstgoods[i]["weight"] <=pstfly_load_da[2]["load_weight"]:
cc=cc+1
if 4<=cc:
for m in range(len(pstUAV_we)):
if pstUAV_we[m]["type"]==pstfly_load_da[2]["type"]:
bb=bb+1
if cc/4 > bb:
if we_value >=pstfly_load_da[2]["value"]:
aa={"purchase":pstfly_load_da[2]["type"]}
purchase_plane.append(aa)
we_value=we_value-pstfly_load_da[2]["value"]
#第4重飞机 购买
if len(pstfly_load_da)>=5:
cc=0
bb=0
for i in range(len(pstgoods)):
if pstfly_load_da[4]["load_weight"]< pstgoods[i]["weight"] <=pstfly_load_da[3]["load_weight"]:
cc=cc+1
if 5<=cc:
for m in range(len(pstUAV_we)):
if pstUAV_we[m]["type"]==pstfly_load_da[3]["type"]:
bb=bb+1
if cc/5 > bb:
if we_value >=pstfly_load_da[3]["value"]:
aa={"purchase":pstfly_load_da[3]["type"]}
purchase_plane.append(aa)
we_value=we_value-pstfly_load_da[3]["value"]
#第5重飞机 购买
if len(pstfly_load_da)>=6:
cc=0
bb=0
for i in range(len(pstgoods)):
if pstfly_load_da[5]["load_weight"]< pstgoods[i]["weight"] <=pstfly_load_da[4]["load_weight"]:
cc=cc+1
if 5<=cc:
for m in range(len(pstUAV_we)):
if pstUAV_we[m]["type"]==pstfly_load_da[4]["type"]:
bb=bb+1
if cc/5 > bb:
if we_value >=pstfly_load_da[4]["value"]:
aa={"purchase":pstfly_load_da[4]["type"]}
purchase_plane.append(aa)
we_value=we_value-pstfly_load_da[4]["value"]
########################################################################
return purchase_plane