Ejemplo n.º 1
0
	def calculate_player_balance(self, player, trimming_factor=10.0, linear_boundary=10.0):
		"""
		Calculate power balance between self.owner and other player.

		trimming_factor: Since any balance returns values of (0, inf) we agree to assume if x < 0.1 -> x = 0.1 and if x > 10.0 -> x=10.0
		linear_boundary: boundary of [-10.0, 10.0] for new balance scale

		@param player: player to calculate balance against
		@type player: Player
		@param trimming_factor: trim actual balance values to range [1./trimming_factor, trimming_factor] e.g. [0.1, 10.0]
		@type trimming_factor: float
		@param linear_boundary: boundaries of new balance scale [-linear_boundary, linear_boundary], e.g. [-10.0, 10.0]
		@type linear_boundary: float
		@return: unified balance for various variables
		@rtype: collections.namedtuple
		"""
		wealth_balance = self.owner.strategy_manager.calculate_player_wealth_balance(player)
		power_balance = self.owner.strategy_manager.calculate_player_power_balance(player)
		terrain_balance = self.owner.strategy_manager.calculate_player_terrain_balance(player)
		balance = {
			'wealth':wealth_balance,
			'power':power_balance,
			'terrain':terrain_balance,
		}
		balance = dict(( (key, trim_value(value, 1./trimming_factor, trimming_factor)) for key, value in balance.iteritems()))
		balance = dict(( (key, map_balance(value, trimming_factor, linear_boundary)) for key, value in balance.iteritems()))

		return collections.namedtuple('Balance', 'wealth, power, terrain')(**balance)
Ejemplo n.º 2
0
	def calculate_player_balance(self, player, trimming_factor=10.0, linear_boundary=10.0):
		"""
		Calculate power balance between self.owner and other player.

		trimming_factor: Since any balance returns values of (0, inf) we agree to assume if x < 0.1 -> x = 0.1 and if x > 10.0 -> x=10.0
		linear_boundary: boundary of [-10.0, 10.0] for new balance scale

		@param player: player to calculate balance against
		@type player: Player
		@param trimming_factor: trim actual balance values to range [1./trimming_factor, trimming_factor] e.g. [0.1, 10.0]
		@type trimming_factor: float
		@param linear_boundary: boundaries of new balance scale [-linear_boundary, linear_boundary], e.g. [-10.0, 10.0]
		@type linear_boundary: float
		@return: unified balance for various variables
		@rtype: collections.namedtuple
		"""
		wealth_balance = self.owner.strategy_manager.calculate_player_wealth_balance(player)
		power_balance = self.owner.strategy_manager.calculate_player_power_balance(player)
		terrain_balance = self.owner.strategy_manager.calculate_player_terrain_balance(player)
		balance = {
			'wealth':wealth_balance,
			'power':power_balance,
			'terrain':terrain_balance,
		}
		balance = dict(( (key, trim_value(value, 1./trimming_factor, trimming_factor)) for key, value in balance.iteritems()))
		balance = dict(( (key, map_balance(value, trimming_factor, linear_boundary)) for key, value in balance.iteritems()))

		return collections.namedtuple('Balance', 'wealth, power, terrain')(**balance)