# Combat Analysis

*1,565*pages on

this wiki

### OverviewEdit

Based on knowledge of how combat works in LevynLight, it is possible to predict the likelihood of a player winning a given encounter. Several factors need to be taken into account. First, some method of handling random events (traits and luck must be decided upon. There are two major ways of handling this, each with their advantages and disadvantages. Secondly, once the combination of traits and luck has been determined and the final powers compute, the likelihood of a player winning must be decided.

### Accounting for Traits and Critical ChanceEdit

The are two principle methods for accounting for traits and critical chance. The first is using average expected values, which is based on computing the average benefit or penalty gained from a given trait (or from critical chance) and summing that for each side, then using those sums to determine the final power values. The second method, referred to as 'Actual Win Chance (AWC)', examines every possible combination of trait activation and critical chance and calculates a weighted sum based on how likely those combinations are expected to be.

#### Using Average Expected ValuesEdit

The advantage of this approach is that it is relatively quick and easy to compute. There is only once value to compute for each trait, and only one set of power values to determine the win chance for. However, this method is less accurate, perhaps greatly so.

For example, take a Level 6 Player using the Farm Spade and the Initiate's Tunic against a Unicow. The Player has a raw attack of 26 (11 Weapon Attack + 2 Base Attack, doubled) and a raw defense of 2 (1 Armor Defense + 1 Base Defense). The Unicow has 11 raw attack, 1 raw defense, and a 53% chance of 'Moo', which provides 1 Attack. The average expected benefit from Moo is 0.53 Attack. The expected benefit from critical chance for both sides is 1%. Thus, using this method, the Player has a turn power of 25.25 ((26-1)*1.01) and the Unicow has a turn power of 9.63 ((11-2+0.53)*1.01). As the next section will explain, the Player has a 82.92% chance to win.

#### Actual Win ChanceEdit

AWC has the advantage of being prefectly precise in determining the likelihood of a player to win (or lose). It is, however, extremely computation intensive, rapidly scaling to the point where doing the math by hand takes a prohibitive amount of time. It works by examining all of the possible combinations of traits and critical chance and determining a pair of power values (player and opponent) for each. The likelihood of winning is then determined for each of these power value pairs and summed, using weighs based on the likelihood of that match-up occuring. The final sum is an exact calculation of the player's chance to beat an opponent.

Note that the number of power combinations for a given player and opponent is equal to 2^(T+2), where T is the total number of traits on both sides. Each event (critical chance activating or not activating, traits activating or not activating, is an independent event. Because of this, the likelihood of a given match-up (set of events) occuring is equal to the product of the likelihood of each individual event happening.

Take the example given previously of a Level 6 Player using the Farm Spade and Initiate's Tunic against a Unicow. As previously stated, the player has 26 raw attack and 2 raw defense. The Unicow has 11 raw attack, 1 raw defense, and a 53% chance of Moo (+1 Attack). Both sides have 1% critical chance. There are eight possible combinations, which are:

Player critical hit | Enemy critical hit | Enemy Trait activated | Probability |
---|---|---|---|

No | No | No | 46% |

No | No | Yes | 53% |

Yes | No | No | 0.46% |

Yes | No | Yes | 0.53% |

No | Yes | No | 0.46% |

No | Yes | Yes | 0.53% |

Yes | Yes | No | 0.0046% |

Yes | Yes | Yes | 0.0053% |

Each combination has a slightly different set of final powers, based on which the likelihood of the player winning that given combination of events can be determined. Those values can be summed, weighted based on the likelihoods listed above, to give the player's AWC (roughly 82.8%). Note that the likelihood values above may not sum to 100% due to rounding.

While the difference in the win chance for the examples given is not large (roughly 0.12%), this is a very simple example using a very weak trait and low critical chance values. With increasing encounter complexity, the difference can become much larger.

### Accounting for Total PowerEdit

Based on a known total power for each side, it is possible to compute the likelihood of a given side winning. Winning is determined on the random amount of damage each side does. The range of values for each side is one to their total power, inclusive and the random numbers are evenly distributed (all equally likely). Calculating the likelihood of a given side winning can be viewed in a number of ways, of which three: visually, as a summation, and as a quadratic equation, are discussed here.

The final equations that are arrived at depend on whether or not the player is the side with the greater power total. If the player has the higher power total, the player's chance to win is equal to:

If the player has less power, the player's chance to win is:

- (0.5 * PLAYER_POWER^2 + 0.5 * PLAYER_POWER) / (PLAYER_POWER * OPPONENT_POWER)

And if both sides have equal power, either equation can be used and will return the same results.

#### Combat Rolls as a Game BoardEdit

When the game goes to determine a winner in an encounter, it rolls two dice. This can also be visualized as a rectangular game board with a number of rows equal to the total power of the player and a number of columns equal to the total power of the opponent. The game effectively is picking a square from the board at random and deciding which side wins based on the number of the row and column the square is in. Each square results in either a win or a lose for the player, and there are a total number of squares equal to the product of the player's power and the opponent's power. The player's chance of winning is equal to the likelihood of a winning square being chosen from the board, which is equal to the number of winning squares for the player divided by the total number of squares.

#### Combat Rolls as a SummationEdit

Based on the range of values for the two rolls, there are a finite number of winning combinations for the player amid the total number of combinations. These values can be computed as a summation. However, because the space of combinations is not usually square, there are issues. Specifically, these deal with the cases where the side with the higher power is guaranteed to win because their roll is higher than any number the other side can roll. If you think of all of the combinations of the two die rolls as a game board, these cases correspond to the area of the board you would have to cut off to make the board square. One solution is to view the problem from the view point of the side with less power. All of the combinations where the weaker side will win fall inside the 'square' region of the board and the summation to describe this area is much simpler. For any given roll by the weaker player, they are guaranteed to win a number of encounters equal to the value of the roll minus one. The number of winning combinations is then the summation of this value across all possible rolls for the weaker player, or:

- SUM(N=1 to Lower Power::N-1)

This does not account for ties, however. There are number of combinations which result in ties in rolls equal to the power of the weaker side. Players always win these combinations, and opponents always lose them. Thus, if the player has the lower total power, the number of winning combinations is equal to the above summation plus the lower power, or:

- SUM(N=1 to PLAYER_POWER::N)

Neither of these equations addresses the number of winning combinations for the stronger side, but the answer can be derived from them. There is a total number of combinations equal to the product of the two total powers, and all combinations that are not winning states for the weaker side are winning states for the stronger side. As such, if the player is the stronger side, the number of winning states is:

- (PLAYER_POWER * OPPONENT_POWER) - SUM(N=1 to OPPONENT_POWER::N-1)

The likelihood of the player winning is equal to the number of winning combinations for the player divided by the total number of combinations.

#### Combat Rolls as a Quadratic EquationEdit

The number of winning combinations for a given side can be computed alegebracially based on the total powers of the two sides. This is most readily done by computing the number of winning combinations for the weaker side using the summation method above and determining the equation that models the number of winning states for each 'step' of the summation. As such, the number of winning states for the player when the player is the weaker side is:

- 0.5 * PLAYER_POWER^2 + 0.5 * PLAYER_POWER

This is based on the fact that the number of winning combinations for a weaker player is (for increasing total power starting at one): 1, 3, 6, 10, 15 and so on. These are the exact values the preceding equation gives for the appropriate total power. When the player is the stronger side, the number of winning combinations progresses depending upon the power of the opponent and can be determined based on the difference between the total number of combinations and the number of winning combinations for the opponent:

- (PLAYER_POWER * OPPONENT_POWER) - 0.5 * OPPONENT_POWER^2 + 0.5 * OPPONENT_POWER^2

The above equations determine the number of winning combinations for the player, not the player's win chance. The player's win chance is equal to the number of winning combinations (as determined by the equations above) divided by the total number of combinations.