山峰_分诊_triage
发布于 2020年2月11日

(点击图片进入关卡)
受伤的士兵需要治疗,但我们需要首先帮助受伤最重的人。
简介
把伤兵分成三组(三个数组)。
一组给 mage ,他会帮那些速度降低的士兵解除咒语。
一组给 doctor ,他会治疗受伤严重的士兵(生命值小于一半)。
第三组给 helper ,他会找一个让轻伤士兵休息的地方。
请记住,可以使用以下方式为数组添加元素:
doctorPatients.append(soldier)
默认代码
# 对伤员进行分类。
doctor = hero.findByType("paladin")[0]
mage = hero.findByType("pixie")[0]
helper = hero.findByType("peasant")[0]
soldiers = hero.findByType("soldier")
# 初始化患者数组。
doctorPatients = []
magePatients = []
helperPatients = []
# 迭代所有士兵:
for soldier in soldiers:
# 如果士兵减速:
if soldier.maxSpeed < 6:
# 将它们添加到'mage'的病人数组中。
magePatients.append(soldier)
# 如果士兵的健康不到最大的一半。
# 把它们添加到'doctor'病人行列中。
# 其他:
# 将士兵添加到'helper'的病人行列中。
# 现在将病人名单分配给合适的人。
mage["patients"] = magePatients
doctor["patients"] = doctorPatients
helper["patients"] = helperPatients
概览
示例代码显示了如何将速度减慢的士兵添加到 magePatients 数组中,以提示您如何完成。
首先,你需要把 soldier.health 小于 soldier.maxHealth / 2 的士兵添加到 doctorPatients 数组中。
然后,既没有速度减慢、生命值也未小于1/2的士兵,应该被添加到 helperPatients 数组中。
这就行了!之后示例代码就会将伤员的数组给到合适的人,来完成对应的治疗。
分诊解法
# 对伤员进行分类。
doctor = hero.findByType("paladin")[0]
mage = hero.findByType("pixie")[0]
helper = hero.findByType("peasant")[0]
soldiers = hero.findByType("soldier")
# 初始化患者数组。
doctorPatients = []
magePatients = []
helperPatients = []
# 迭代所有士兵:
for soldier in soldiers:
# 如果士兵减速:
if soldier.maxSpeed < 6:
# 将它们添加到'mage'的病人数组中。
magePatients.append(soldier)
# 如果士兵的健康不到最大的一半。
elif soldier.health < soldier.maxHealth / 2:
# 把它们添加到'doctor'病人行列中。
doctorPatients.append(soldier)
# 其他:
else:
# 将士兵添加到'helper'的病人行列中。
helperPatients.append(soldier)
# 现在将病人名单分配给合适的人。
mage["patients"] = magePatients
doctor["patients"] = doctorPatients
helper["patients"] = helperPatients