Sunday, May 29, 2022
HomeGame Developmentarithmetic - Assault/Defence components: guarantee defender wins a sure share of the...

arithmetic – Assault/Defence components: guarantee defender wins a sure share of the time


I’ve two easy stats for my assault components, assault and defence.

I used to be studying by way of this reply which made it look like utilizing percentages for components results in a scaling nightmare, so I fairly like utilizing the harm = att * att / (att + def) components.

Nonetheless, I would like there to be a bonus to defenders, however not for defenders to win each time. So I may have one thing like +5 bonus factors to defenders like so

Attacker assault = 50
Defender defence = 55

which can put the combat in favour of the defender however they are going to win each time. How can I write a components that can swing issues in the best way of the defender? Base stats I am is for defenders to win 55% of the time. Ought to there be a “crit probability” for defenders?

How does this then scale? If I needed there to be a 2% elevated win probability when equipping a stage 1 weapon, how would I am going about plotting this?

Beneath I’ve tried to make use of random numbers and have managed to get the win price to 55% at base values. However as I am not a mathematician I am unable to determine find out how to get this to scale after I introduce gadgets that would improve assault or defence. Is there a graph that I can plot slightly than having to guess values (as I trial and error’d till I bought -/+0.7)?

import random

# Similar as above, however use a coefficient to change assault values
class BattleSimulationCoeff:
  def __init__(self, attack_attacker, attack_defender, defence_attacker, defence_defender, attacker_attack_coeff_max, defender_attack_coeff_max, num_battles=200_000):
    self.attack_attacker = attack_attacker
    self.attack_defender = attack_defender
    self.defence_attacker = defence_attacker
    self.defence_defender = defence_defender
    self.attacker_hp = 100
    self.defender_hp = 100
    self.attacker_attack_coeff_max = attacker_attack_coeff_max
    self.defender_attack_coeff_max = defender_attack_coeff_max
    # Run the simulation 200,000 occasions by default
    self.num_battles = num_battles

  # Use a coefficient to change the assault worth in favour of the defender
  def attack_value(self, assault, defence, coeff):
    return coeff * (assault + assault) / (assault + defence)
    
  # Variety of occasions you wish to run the battle simulation
  def run_battles(self):
    attacker_wins = 0
    defender_wins = 0

    for _ in vary(self.num_battles):
      attacker_hp_simulation = self.attacker_hp
      defender_hp_simulation = self.defender_hp

      whereas attacker_hp_simulation > 0 and defender_hp_simulation > 0:
        # Randomly distribute the worth per assault
        # Favour the defender by modifying the attacker's assault worth to be a multiplication 
        # of a random quantity between 0 and self.attacker_attack_coeff_max
        attacker_attack_coeff = random.uniform(0, self.attacker_attack_coeff_max)
        # Favour the defender by modifying the attacker's assault worth to be a random 
        # quantity between 0 and self.defender_attack_coeff_max
        defender_attack_coeff = random.uniform(0, self.defender_attack_coeff_max)
        # Attacker is attacking
        defender_hp_simulation -= self.attack_value(self.attack_attacker, self.defence_defender, attacker_attack_coeff)
        # Defender is attacking
        attacker_hp_simulation -= self.attack_value(self.attack_defender, self.defence_attacker, defender_attack_coeff)

      if attacker_hp_simulation < defender_hp_simulation:
        defender_wins += 1
      else:
        attacker_wins += 1


    attacker_win_rate = (attacker_wins / self.num_battles) * 100
    defender_win_rate = (defender_wins / self.num_battles) * 100
    print(f"Attacker received {attacker_wins} occasions and defender received {defender_wins} occasions.")
    print(f"Attacker win probability: {attacker_win_rate}%")
    print(f"Defender win probability: {defender_win_rate}%")
    return defender_win_rate

I get 55% in favour of the defender operating with:

bs = BattleSimulationCoeff(
    50.0, 
    50.0, 
    50.0, 
    50.0, 
    attacker_attack_coeff_max=0.992, 
    defender_attack_coeff_max=1)
bs.run_battles()

I get 60% in favour of the defender with:

bs = BattleSimulationCoeff(
    attack_attacker=50.0, 
    # +0.7 assault to defender
    attack_defender=50.7, 
    defence_attacker=50.0, 
    defence_defender=50.0, 
    attacker_attack_coeff_max=0.992, 
    defender_attack_coeff_max=1,
    num_battles=100_000)
bs.run_battles()

I get 50% with

bs = BattleSimulationCoeff(
    # +0.7 assault to attacker
    attack_attacker=50.7, 
    attack_defender=50.0, 
    defence_attacker=50.0, 
    defence_defender=50.0, 
    attacker_attack_coeff_max=0.992, 
    defender_attack_coeff_max=1,
    num_battles=100_000)
bs.run_battles()

Altering every participant’s values however having them equal additionally gave me 55%

bs = BattleSimulationCoeff(
    attack_attacker=65.7, 
    attack_defender=65.7, 
    defence_attacker=65.7, 
    defence_defender=65.7, 
    attacker_attack_coeff_max=0.992, 
    defender_attack_coeff_max=1,
    num_battles=100_000)
bs.run_battles()

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments