Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Maintain fee #38

Merged
merged 5 commits into from

1 participant

@crhan
Collaborator

维护费用功能增加完成

  1. 通过在地图 yml 文件中增加一行 maintain_fee: True 激活此功能
  2. 维护费用自动计算, 通过地图的全部星球 max 属性相加折半后再除以现在在线的玩家数量
crhan added some commits
@crhan crhan 消除可能的代码歧义 56d612f
@crhan crhan 玩家增加方法, 返回兵力增长系数 10a83de
@crhan crhan count_growth 增加维护费用接口 1c75b8d
@crhan crhan 增加维修费用的地图接口
1. 维修费用动态调整, base_line 设定为地图上星球最大兵力的总和(m.map_max)的一半再除以玩家数量
2. 地图上通过增加一行 `maintain_fee: True` 打开维修费用限制
3f48931
@crhan crhan 用户加入和丢失后都要调整费用 7faef8a
@crhan crhan merged commit 6613544 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Aug 25, 2012
  1. @crhan

    消除可能的代码歧义

    crhan authored
  2. @crhan
  3. @crhan
  4. @crhan

    增加维修费用的地图接口

    crhan authored
    1. 维修费用动态调整, base_line 设定为地图上星球最大兵力的总和(m.map_max)的一半再除以玩家数量
    2. 地图上通过增加一行 `maintain_fee: True` 打开维修费用限制
  5. @crhan
This page is out of date. Refresh to see the latest.
Showing with 40 additions and 5 deletions.
  1. +2 −2 running.py
  2. +33 −3 srcs/game.py
  3. +5 −0 srcs/map/map.py
View
4 running.py
@@ -31,7 +31,7 @@ def start_game(q):
msg_queue=q)
def start_http():
- from srcs.web_server import main
+ from srcs import web_server
sys.stdout = Logger('http.log')
#application.settings['debug'] = False
#application.listen(9999)
@@ -40,7 +40,7 @@ def start_http():
#except KeyboardInterrupt:
#print "bye!"
- main()
+ web_server.main()
def start_ai(name, roomid):
ai = __import__('examples.%s' % name, globals(), locals(), ['main'])
View
36 srcs/game.py
@@ -11,6 +11,8 @@
WAITFORPLAYER='waitforplayer'
RUNNING='running'
FINISHED='finished'
+MAINTAIN_LEVEL_1 = 1.5
+MAINTAIN_LEVEL_2 = 2
DEFAULT_MAP = 'srcs/map/fight_here.yml'
# DEFAULT_MAP = 'srcs/map/test.yml'
@@ -51,6 +53,8 @@ def __init__(self,
self.set_map(m)
+ self.map_max_units = m.max_sum
+ self.maintain_fee = m.meta.get('maintain_fee', False)
self.start()
def log(self, msg):
@@ -105,9 +109,16 @@ def add_player(self, name="unknown", side='python'):
player_id = len(self.players)-1
planet_id = self.map.starts[player_id]
self.holds[planet_id] = [player_id, self.map.meta['start_unit']]
+ # 用户加入时调整维护费用
+ self.adjust_mt_fee()
# 返回玩家的顺序, 以及玩家的id(用来验证控制权限)
return dict(seq=len(self.players) - 1, id=player.id)
+ def adjust_mt_fee(self):
+ """动态调整维修费用"""
+ active_playes = len([i if i.alive for i in self.players])
+ self.mt_base_line = int(self.map_max_units / float(2) / active_players
+
def get_seq(self, id):
"""根据玩家的id获取seq"""
for i, s in enumerate(self.players):
@@ -264,12 +275,26 @@ def battle_stage(self, arrives):
for move in arrives:
self.battle(move)
+ def mt_level(self, _side, base_line=2000):
+ """
+ 根据 玩家 units & base_line 返回增长系数, 最高为 1
+ """
+ _units = self.get_info()['players'][_side]['units']
+ if _units <= base_line:
+ return float(1)
+ elif _units <= base_line * MAINTAIN_LEVEL_1:
+ return float(0.5)
+ elif _units <= base_line * MAINTAIN_LEVEL_2:
+ return float(0.25)
+ else:
+ return float(0)
+
def next_round(self):
# 生产回合
for i, data in enumerate(self.holds):
side, count = data
if side == None: continue
- next = self.count_growth(count, self.planets[i])
+ next = self.count_growth(count, self.planets[i], self.mt_level(side, self.mt_base_line))
if next <= 0:
side = None
next = 0
@@ -374,11 +399,14 @@ def battle(self, move):
winner=planet_side))
self.holds[to] = [planet_side, planet_count]
- def count_growth(self, planet_count, planet):
+ def count_growth(self, planet_count, planet, mt_proc = 1):
max = planet['max']
res = planet['res']
cos = planet['cos']
- new_count = int(planet_count * res + cos)
+ # 兵力增量乘以维护费用水平(增长系数)
+ new_armies = (planet_count * (res - 1) + cos)
+ if self.maintain_fee: new_armies *= mt_proc
+ new_count = int(planet_count + new_armies)
if planet_count < max:
planet_count = min(new_count, max)
elif new_count < planet_count:
@@ -413,6 +441,8 @@ def no_response_player_die(self, player, round):
# 判断是否没有响应时间过长
if player.no_resp_time >= MAX_LOST_TURN:
player.alive = False
+ # 用户丢失后调整维护费用
+ self.adjust_mt_fee()
logging.debug('kill no response player: %d' % \
self.players.index(player))
self.log('kill player for no response %s: , round is %s, time is %s' % (player.name, round, player.no_resp_time))
View
5 srcs/map/map.py
@@ -72,6 +72,11 @@ def load(self, data):
for name in self.meta['starts']]
random.shuffle(self.starts)
+ self.max_sum = 0
+ # 计算 map 上所有星球的最大产兵量总和
+ for i in self.planets:
+ self.max_sum += int(i['max'])
+
def test():
"""
>>> map = Map.loadfile("srcs/map/test.yml")
Something went wrong with that request. Please try again.