Python Planets Example

说明

python planets示例是从最受好评的开源项目中提取的实现代码,你可以参考下面示例的使用方式。

编程语言: Python

命名空间/包名称: planetwarsplanet

示例#1
文件: universe_custom2.py项目: vk-eipi/PlanetWars

 def frontlines(self):
     if self._frontlines_cache:
         return self._frontlines_cache
     else:
         frontlines = Planets()
         for eplanet in self.enemy_planets:
             frontlines.add(min(self.my_planets, key=lambda p: (p.distance(eplanet), -p.ship_count)))
         self._frontlines_cache = frontlines
         return frontlines

示例#2
文件: universe_custom.py项目: vk-eipi/PlanetWars

 def frontlines(self):
     if self._frontlines_cache:
         return self._frontlines_cache
     else:
         frontlines = Planets()
         if len(self.my_planets) > 0:
             for eplanet in self.enemy_planets:
                 min_dist = 99999
                 for mplanet in self.my_planets:
                     if mplanet.distance(eplanet) < min_dist:
                         min_dist = mplanet.distance(eplanet)
                 for mplanet in self.my_planets:
                     if mplanet.distance(eplanet) == min_dist:
                         frontlines.add(mplanet)
                     elif mplanet.distance(eplanet) < min_dist:
                         log.warning("min_dist not working in MyUniverse")
                         frontlines.add(mplanet)
         self._frontlines_cache = frontlines
         return frontlines

展开阅读全文