Axis & Allies .org Forums
    • Home
    • Categories
    • Recent
    • Popular
    • Users
    • Register
    • Login
    1. Home
    2. mshih
    0% for April
    M
    • Profile
    • Following 0
    • Followers 0
    • Topics 1
    • Posts 8
    • Best 5
    • Controversial 0
    • Groups 0

    mshih

    @mshih

    5
    Reputation
    9
    Profile views
    8
    Posts
    0
    Followers
    0
    Following
    Joined Last Online
    Age 25

    mshih Unfollow Follow

    Best posts made by mshih

    • RE: Implementation of "true" probability calculator

      This is in response to Dash’s comments about how to compute the probability terms used in his calculator.

      P(n units getting k hits, if p is the probability of 1 unit getting one hit) = (n choose k)p^k(1-p)^(n-k).

      Since axis & allies has non-homogenous forces (i.e. infantry + armor + bombers), these terms need to be further combined with complicated algorithms.

      There’s a simplification to this problem, if we assume fixed order of loss.

      Let p(i) == the probability of the ith unit getting a hit.  (e.g. for attacking inf ==> 1/6, attacking armor 3/6, etc…)
      Let p(i) be defined in the reverse order of loss.  This can be initialized trivially.

      Let P(i, j) == the probability that i units gets j hits.  This is the matrix that we’re trying to fill in.

      The following recurrence relation holds:
        P(i, j) = P(i-1, j-1) * p(i) + P(i-1, j) * (1-p(i))

      We then just need to define the initial conditions:
        P(0, 0) = 1
        P(0, j) = 0 for all j > 0
        P(i, 0) = P(i-1, 0) * (1 - p(i))

      We can now fill in P(i, j) for all i, j and compute all of the probability terms that will be needed for the attackers.

      The beauty of this formulation:

      • No powers
      • No factorials
      • No special logic needed to handle non-homogenous forces.
      • Complexity to compute all probability terms needed is O(n^2) :).
      • All of the subproblems solved are needed and will be used.

      Unfortunately, I believe updating the probabilities themselves is O(n^4).  So the computation of the probability terms themselves shouldn’t really be the bottleneck if they are precomputed.

      • Mitchell
      posted in Software
      M
      mshih
    • RE: Implementation of "true" probability calculator

      Actually fixed order of loss is pretty reasonable assumption for odds calculator…. We have to assume some type of standard order of loss.  It doesn’t have to be strictly decreasing…  For example, if attacker wants to capture at all costs, we can lose fighters and bombers before tanks.  Or if attacker wants to capture with at least 10 ground units, that’s also possible.

      AA guns can be handled by constructing separate tables corresponding to number of AA gun hits.

      So if attacker has 2i, 2a, 2f, and we’re facing AA gun, we need to solve
      F(f, f, a, a, i, i)  ;; 0 AA hits
      F(f, a, a, i, i)  ;; 1 AA hit
      F(a, a, i, i)  ;; 2 AA hits

      Subs only hitting ships can be handled in similar approach…
      Suppose the defending force is 2 fighters, 1 carrier, 1 battleship

      If the attacking force has some subs, then we may need to remove units out of order.  So we need to compute:
      F(B, C, f, f)    ;; 0 naval hits
      F(B, f, f) ;; 1 naval hit
      F(f, f) ;; 2 naval hits

      posted in Software
      M
      mshih
    • RE: mshih's aa1942calc2

      @djensen If you’re using typescript/javascript, my engine is available on npm.

      npm install aacalc2

      The webpage is basically something I vibe coded to showcase the engine.

      posted in Software
      M
      mshih
    • RE: mshih's aa1942calc2

      @djensen Aside from the pure speed. My calculator has some neat advanced features like:

      1. Compute the probability of winning for all sub-battles in one pass. This allows a second pass to implement things like retreat if the probability of winning the battle is too low.

      2. Compute the Expected profit for all sub-battles in one pass. This allows a second pass to implement retreat if the EV profit is too low (typically retreat if EV is negative).

      3. Strafe analysis is_deadzone, combined with the territory value can be used to model a variety of strafe scenarios.

      e.g. If strafing from a capital with a large army next door… a large negative value is warranted. (russia IPC’s * 2 + russia territory IPC value. + value of other allied units lost if the strafe turns into take. Using large values like -50 IPC’s is fair.

      If strafing from W.Russia… and W Russia is safe even if the strafe fails and the territory is captured, a normal positive territory value is good enough.

      1. Army recommendation - which can compute optimal strafes. If you set is_deadzone – and an appropriate territory value (positive or negative based on the situation), the army recommendation can recommend the sub-army that gives maximum expected profit.

      #1 and #2 are simple recurrence relations that I can share

      posted in Software
      M
      mshih
    • RE: mshih's aa1942calc2

      To compute EV profit for all sub-problems, the recurrence relation is:

      EV(i, j) = profit of state i attackers and j defenders.
      profit(ii, jj, i, j) = the incremental profit for moving from state (i, j) to (ii, jj).
      p(ii,jj) = probability of reaching state ii,jj from i, j
      
      EV(i, j) = sum( all next states ii, jj) {
            p(ii,jj) * profit(ii,jj, i, j)   + EV(ii,jj)
      }
      

      This doesn’t consider that you might retreat in the future… to handle that:

      EV(i, j) = sum( all next states ii, jj) {
            p(ii,jj) * profit(ii,jj, i, j)   + EV(ii,jj) > retreatThreshold ? EV(ii,jj) : 0
      }
      

      To compute Pwin for all sub-problems, the recurrence relation is:

      Pwin(i, j) = probability of winning
      
      Pwin(i, j) = sum (all next states ii, jj) {
           isRetreat = Pwin(ii, jj) < threshold;
           isRetreat ? 0 : p(ii,jj) * Pwin(ii,jj)
      }
      
      posted in Software
      M
      mshih

    Latest posts made by mshih

    • RE: mshih's aa1942calc2

      To compute EV profit for all sub-problems, the recurrence relation is:

      EV(i, j) = profit of state i attackers and j defenders.
      profit(ii, jj, i, j) = the incremental profit for moving from state (i, j) to (ii, jj).
      p(ii,jj) = probability of reaching state ii,jj from i, j
      
      EV(i, j) = sum( all next states ii, jj) {
            p(ii,jj) * profit(ii,jj, i, j)   + EV(ii,jj)
      }
      

      This doesn’t consider that you might retreat in the future… to handle that:

      EV(i, j) = sum( all next states ii, jj) {
            p(ii,jj) * profit(ii,jj, i, j)   + EV(ii,jj) > retreatThreshold ? EV(ii,jj) : 0
      }
      

      To compute Pwin for all sub-problems, the recurrence relation is:

      Pwin(i, j) = probability of winning
      
      Pwin(i, j) = sum (all next states ii, jj) {
           isRetreat = Pwin(ii, jj) < threshold;
           isRetreat ? 0 : p(ii,jj) * Pwin(ii,jj)
      }
      
      posted in Software
      M
      mshih
    • RE: mshih's aa1942calc2

      @djensen Aside from the pure speed. My calculator has some neat advanced features like:

      1. Compute the probability of winning for all sub-battles in one pass. This allows a second pass to implement things like retreat if the probability of winning the battle is too low.

      2. Compute the Expected profit for all sub-battles in one pass. This allows a second pass to implement retreat if the EV profit is too low (typically retreat if EV is negative).

      3. Strafe analysis is_deadzone, combined with the territory value can be used to model a variety of strafe scenarios.

      e.g. If strafing from a capital with a large army next door… a large negative value is warranted. (russia IPC’s * 2 + russia territory IPC value. + value of other allied units lost if the strafe turns into take. Using large values like -50 IPC’s is fair.

      If strafing from W.Russia… and W Russia is safe even if the strafe fails and the territory is captured, a normal positive territory value is good enough.

      1. Army recommendation - which can compute optimal strafes. If you set is_deadzone – and an appropriate territory value (positive or negative based on the situation), the army recommendation can recommend the sub-army that gives maximum expected profit.

      #1 and #2 are simple recurrence relations that I can share

      posted in Software
      M
      mshih
    • RE: mshih's aa1942calc2

      @djensen Sure. Even if you don’t directly use the engine., maybe you can take advantage of some of the techniques?

      I think the speed of my engine is due to:

      1. Precompute everything up front
        For each node (unique sub-army)
        get any needed probability with an array lookup
        get the next state index for any casualty type with an array lookup.
        I don’t use any hash/maps in the tight inner loop. Only for postprocessing the output, or preprocessing the input.
      2. Pruning. I use a pruning threshold 1e-12. If a state’s seed probability is smaller than this threshold – I prune to zero – and don’t update child states.
      3. Roundless evaluation. I don’t roll multiple rounds of battle. The 2-D probability matrix is solved only one time.
      posted in Software
      M
      mshih
    • RE: mshih's aa1942calc2

      @djensen If you’re using typescript/javascript, my engine is available on npm.

      npm install aacalc2

      The webpage is basically something I vibe coded to showcase the engine.

      posted in Software
      M
      mshih
    • RE: mshih's aa1942calc2

      At the time of my post. So last couple days. For example. Try 80 inf/art vs. 80 inf/art (160 vs. 160). My calculator runs in 0.2 seconds. I think yours currently crashes. But if you reduce to 120 vs. 120 (60 each), then yours takes 10+ seconds.
      My calculator can handle 400 vs 400 (200 inf/art vs. 200 inf/art) in 10 seconds.

      You can check out my repo on github: https://github.com/mshih01/aacalc2

      The readme has a discussion on the algorithm… and it should be pretty fast – and memory efficient.

      • Mitchell
      posted in Software
      M
      mshih
    • mshih's aa1942calc2

      I’ve also been working on a calculator based on math.

      Here’s a link: https://mshih01.github.io/aacalc2/

      It has most of the features of aa1942calc.com… multiwave support, rounds of battle, amphibious assault. (the missing feature is the monte carlo analysis to support extra large battles )

      It also has advanced retreat options…
      number of rounds.
      number of attacking units <=
      expected profit continuing < threshold
      probability of winning < threshold
      probability of losing air > threshold.
      probability of killing defenders > threshold (strafe analysis).

      The territory can also be marked as deadzone in the profit computation – in which case attacking captured land units count inf(-2), art(-3), arm(-4.5) towards the profit computation.

      I think it’s even faster than your implementation. If you like, we can discuss implementation details.

      posted in Software
      M
      mshih
    • RE: Implementation of "true" probability calculator

      Actually fixed order of loss is pretty reasonable assumption for odds calculator…. We have to assume some type of standard order of loss.  It doesn’t have to be strictly decreasing…  For example, if attacker wants to capture at all costs, we can lose fighters and bombers before tanks.  Or if attacker wants to capture with at least 10 ground units, that’s also possible.

      AA guns can be handled by constructing separate tables corresponding to number of AA gun hits.

      So if attacker has 2i, 2a, 2f, and we’re facing AA gun, we need to solve
      F(f, f, a, a, i, i)  ;; 0 AA hits
      F(f, a, a, i, i)  ;; 1 AA hit
      F(a, a, i, i)  ;; 2 AA hits

      Subs only hitting ships can be handled in similar approach…
      Suppose the defending force is 2 fighters, 1 carrier, 1 battleship

      If the attacking force has some subs, then we may need to remove units out of order.  So we need to compute:
      F(B, C, f, f)    ;; 0 naval hits
      F(B, f, f) ;; 1 naval hit
      F(f, f) ;; 2 naval hits

      posted in Software
      M
      mshih
    • RE: Implementation of "true" probability calculator

      This is in response to Dash’s comments about how to compute the probability terms used in his calculator.

      P(n units getting k hits, if p is the probability of 1 unit getting one hit) = (n choose k)p^k(1-p)^(n-k).

      Since axis & allies has non-homogenous forces (i.e. infantry + armor + bombers), these terms need to be further combined with complicated algorithms.

      There’s a simplification to this problem, if we assume fixed order of loss.

      Let p(i) == the probability of the ith unit getting a hit.  (e.g. for attacking inf ==> 1/6, attacking armor 3/6, etc…)
      Let p(i) be defined in the reverse order of loss.  This can be initialized trivially.

      Let P(i, j) == the probability that i units gets j hits.  This is the matrix that we’re trying to fill in.

      The following recurrence relation holds:
        P(i, j) = P(i-1, j-1) * p(i) + P(i-1, j) * (1-p(i))

      We then just need to define the initial conditions:
        P(0, 0) = 1
        P(0, j) = 0 for all j > 0
        P(i, 0) = P(i-1, 0) * (1 - p(i))

      We can now fill in P(i, j) for all i, j and compute all of the probability terms that will be needed for the attackers.

      The beauty of this formulation:

      • No powers
      • No factorials
      • No special logic needed to handle non-homogenous forces.
      • Complexity to compute all probability terms needed is O(n^2) :).
      • All of the subproblems solved are needed and will be used.

      Unfortunately, I believe updating the probabilities themselves is O(n^4).  So the computation of the probability terms themselves shouldn’t really be the bottleneck if they are precomputed.

      • Mitchell
      posted in Software
      M
      mshih