Search Unity

How to calculate outcome of events based on percentage and "modifiers"?

Discussion in 'Game Design' started by Railon23, Jan 28, 2017.

  1. Railon23

    Railon23

    Joined:
    Jan 30, 2014
    Posts:
    32
    Hi there,

    I'm currently thinking about (the best) a good way to design the outcome of events. Let's take a soccer game as an example. E.g. a penalty. Player A shoots in the left corner. The goalkeeper of team B jumps in that corner, so it's possible he can stop the ball.
    Important: The game should be calculated very fast and only highlights (e.g. "big chances", like 50%+ that the result is a goal) should be visible to the player.

    #1 basic approach:
    The chance is 75% percent that the ball finds the net. So it's general a 75-25 chance to score if the goalkeeper and the ball is in the same area (player can shoot left, right or middle). Lets define this as "initial event chance". That's easy to calculate and the outcome is clear.
    #2 advanced approach one side:
    There should be an option to miss the goal. This could be a fixed value like 5%, which later could also be modified by attributes of the penalty taker (high technical skill would decrease that value. playing in an away match or being a young player could increase the miss chance).

    Now the game design/logic question: What's a good way to use these (and many more) modifiers to calculate the outcome of game events/situations. Or what type of ways do you know?
    I could think of:
    1. Put everything into one calculation: The advanced approach would need to take the 5% miss chance into account. I can think of two ways:
      1. Add the 5% miss modifier (and all future modifiers) to the total of 100% (75 + 25) and "bring" it back to 100 percent so the chances are 71,429 hit to goal, 23,81 save by goalkeeper and 4,762 miss the goal. Then calculate a random number between 0 and 100 and you get the result.
        Pros: All in one calculation. It's easy to say if it's a "big chance" (50%+ to score).
      2. "Take" the 5% of the given event rule. So it would be "real" 5% from the 100%. Meaning that the 75:25 would be like 71,25:23,75 (a total of 95%). The chances are 71,25 hit to goal, 23,75 save by goalkeeper and 5 miss the goal.
        Negative: Looks good at first, but if there are a lot of modifiers, they take a huge part of the "initial event chance".
    2. Multiple calculations: So first let's see if the player hits the left area of the goal. Basic miss chance is 5%. If he "wins" that first calculation (95:5), the next one is the against the goalkeeper. That's then a 75% chance to hit the net (75:25).
      Negative(?): This could mean a lot of calculations in different, more complicated events other than a penalty. Making it harder to define a "big chance"?
    3. Other solutions?

    #3 advanced approach two sides:
    Let's say the players have attributes. The penalty taker is really bad at shooting and the goalkeeper is really good at penalty stopping. Would these attributes also be like the modifier from #2? So bad shooting would be a 5% decrease for scoring and good penalty stopping a 10% chance to stop the ball.
    But these modifier would directly influence the "initial event chance" percentage in this case. With the basic approach only using the initial event chance of 75:25, this would be 70:35 and mean 66,666:33,333 for hitting the net.

    Please share your thoughts and/or point me in the right direction. This could be approaches from other games or links where this topic is also discussed. I guess that I also could have a look at some RPG rulebooks where resistence, crit chance and other attributes are used. What would you recommend?
    Thanks
     
  2. Railon23

    Railon23

    Joined:
    Jan 30, 2014
    Posts:
    32
    Short update, I hope this is ok. I read a lot of stuff now and find this one very helpful:
    http://www.redblobgames.com/articles/probability/damage-rolls.html
    There's are interactive slider to change values in the functions and you see the result in the graphs. Also the part about how to create your own lock-up tables is nice.
     
  3. LMan

    LMan

    Joined:
    Jun 1, 2013
    Posts:
    493
    What is the motive for the randomness?

    randomness in games has very significant design implications- mostly to do with the fact that random outcomes don't feel random. When the user/player looks at an event, they only see the context of that one event.

    For instance, in XCOM, a soldier takes a shot at an enemy in partial cover. Lets say the percentage to hit is 75% - if it hits, the player will feel it's fair, as 3/4 is good odds and therefore they have been rewarded for taking the best shot. However if it misses, the player will feel it's a little unfair, seeing as how they saw that the enemy was more exposed than other enemies, moved that soldier into position to take advantage of that weakness- they played well, but lost anyway.

    Then imagine the player takes two more shots at the same enemy in the same circumstances- both miss. The player is now SURE that the game has cheated him- since the odds were in his favor, but he missed 3 times in a row. The player has not taken into account that if he looked at all the shots he had ever taken, they would indeed average out to the probabilities the game has given him, but he doesn't have that data, and it wouldn't matter if he did- the player only cares about the current event he is reacting to.
     
    Xepherys likes this.
  4. Railon23

    Railon23

    Joined:
    Jan 30, 2014
    Posts:
    32
    Hi LMan,

    thanks for your response.
    Well the randomness is one part of the gameplay. Let's stay at the soccer example. Think of a freekick. It's a difference if a good player like Ronaldo or a "normal" player shoots. Also it depends on the position from where the freekick is shot etc. So there would be multiple values effecting the chance to score. The user can increase the chance to score by having a good freekick taker, playing at home, trained freekicks etc. On the other side it depends on defending freekick training, goalkeeper stats etc.

    It's like positioning / flanking, skills, equipment etc. in XCOM. But in the end a dice is rolled and the user the result is presented to the player.

    The randomness is part of the game (and life...). In soccer there are so called clear cut chances or 100% chance. I mean in real life now. Still even Messi or Ronaldo sometimes miss these opportunities. Thats what somehow has to happen in the game as well.

    Upadate on my approach:
    Right now I'm thinking in direction #1.1, but instead of real percentage the modifiers are numbers which are added to the "initial event chance".
     
    Xepherys likes this.
  5. LMan

    LMan

    Joined:
    Jun 1, 2013
    Posts:
    493
    I guess what I'm asking is why is randomness a part of your game?

    Soccer is a game of skill- goals are determined by the position, speed, angle of the kick, and the position, speed of the goalie at the time of the kick. It seems to me like an odd thing to roll for. Not saying you can't or shouldn't, I just want to hear your thought process.

    Is it a management context? Where the player doesn't see the game itself but places players at positions, then sees the data (shots, goals, saves) breakdown after the match?

    Realism is only desirable in conjunction with user experience- sure it's realistic for shots in XCOM to roll for hits, but is it more fun?
     
  6. MV10

    MV10

    Joined:
    Nov 6, 2015
    Posts:
    1,889
    Your first post sort of answers the question you're asking. There is no generically "best" approach, it comes down to the game you're building and the corresponding behaviors you think are appropriate. You listed many ways to solve the problem and you observed they may have various pros and cons. The best approach is the one that meets the needs of your game.

    You can make it as simple or complex as you wish. In an early version of my turn-based space combat game, I adapted the combat resolution rules from an existing dice-rolling tabletop game just so I could focus on the rest of the game without having to worry about balance issues during early development. (Later it will change to an actual combat simulation using a different part of the game I'm writing now.)

    This would probably be an example of "complex" :) and seems to be similar to your "two sides" approach. But I'll reiterate these are really just basic game design decisions. The only right answer is the one that accomplishes your goals for your game. (And I certainly don't recommend anyone uses this mess or attempts to emulate this, but you did ask for code...)

    Code (csharp):
    1.     private void CalcResults()
    2.     {
    3.         /*
    4.         Add the total Military Attack or total Diplomatic Leadership values of the attacking units.
    5.         Subtract the corresponding Defense values of the defending units.
    6.         This is the combat differential.
    7.         Clamp the final value from -6 to +6 inclusive.
    8.  
    9.         Three random numbers from 0 to 9 (inclusive) are generated:
    10.         ...the combat lookup value,
    11.         ...the attacker lookup modifier,
    12.         ...and the defender lookup modifier.
    13.  
    14.         Add the highest Leadership value to each side’s modifier.
    15.         Apply any event-based modifiers.
    16.         Add the attacker’s modifier to the lookup and subtract the defender’s modifier.
    17.         Clamp the final lookup value from -2 to +11 (inclusive).
    18.         */
    19.         int attackerMaxLeadership = attacker.MaxLeadership(sectorId);
    20.         int defenderMaxLeadership = defenders.Sum(f => f.MaxLeadership(sectorId));
    21.         int attackerValue = attacker.combat.Sum(u => (usage != Usage.Diplomatic) ? u.Attack() : u.Leadership(attacker.factionType));
    22.         int defenderValue = defenders.Sum(f => f.combat.Sum(u => u.Defense()));
    23.         int combatDifferential = Mathf.Clamp(attackerValue - defenderValue, -6, 6);
    24.  
    25.         int combatLookup = Random.Range(0, 10);
    26.         int attackerLookup = Random.Range(0, 10) + attackerMaxLeadership;
    27.         int defenderLookup = Random.Range(0, 10) + defenderMaxLeadership;
    28.  
    29.         if(empireAttacking) GameData.persistentEvents.ForEach((e) => attackerLookup = e.ImperialCombatModifier(attackerLookup));
    30.         if(empireDefending) GameData.persistentEvents.ForEach((e) => defenderLookup = e.ImperialCombatModifier(defenderLookup));
    31.  
    32.         combatLookup = Mathf.Clamp(combatLookup + attackerLookup - defenderLookup, -2, 11);
    33.  
    34.         int x = combatDifferential + 6;
    35.         int y = combatLookup + 2;
    36.         int index = ((y * 13) + x) * 2;
    37.         const string grid = "A3A3A3A3A3A3A3A3A3A3A3A3A3A3A3A3A3A3A3A3A3A3A3A3A3A2A3A3A3A3A3A3A3A3A2A2A2A2A2A3A3A3A3A3A3A2A2A2A1A1A1D0A3A3A3A3A2A2A2A1A1A1D0D0D1A3A3A2A2A2A2A1A1D0D0D1D1D2A2A2A2A2A1A1D0D0D1D1D2D2D2A2A2A2A1A1D0D0D1D1D1D2D2D2A2A1A1D0D0D1D1D2D2D2D2D3D3A1D0D0D1D1D1D2D2D3D3D3D3D3D0D1D1D1D2D2D2D3D3D3D3D3D3D1D2D2D2D2D3D3D3D3D3D3D3D3D2D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3";
    38.         resultCode = grid.Substring(index, 2);
    39.     }
     
  7. Railon23

    Railon23

    Joined:
    Jan 30, 2014
    Posts:
    32
    Hi guys,
    thanks for your feedback. I'm traveling a few days and can only post on the smartphone. So I can't set quotes correctly.

    "Soccer is a game of skill- goals are determined by the position, speed, angle of the kick, and the position, speed of the goalie at the time of the kick. It seems to me like an odd thing to roll for."
    Yes, this is true if you would/can simulate all of the aspects of the real life. But on the other hand that would also mean Christiano Ronaldo would hit every freekick from a certain distance to the goal? So also real life has some kind of randomness (You can say it's luck or misfortune). I guess that's what developers want to achieve with the randomness.
    I read an article about D&D and the intention of critical hit. The idea was the possibility to hit an important part of the enemy and therefore decrease the health a lot immediately.

    "Is it a management context?"
    Yes, the game idea is not like Fifa where the user has direct control via controller of the soccer player. It's more like a soccer manager. So the user can define formation and tactic. A big part is the available players and their attributes und skills. Also other soccer game related stats (home/away, weather, etc) could influence the outcome (calculations) in the match.
    I think in this management context the randomness can be of great use. Coming back to the clear cut chance (90:10 percent to score). A player missing three of these chances in a row could experience a "personal crisis", which decreases his overall stats or so. The user then has to think about a replacement in the starting eleven to get rid of the "debuff" in an important game. He would start that player against a weaker opponent to get him scoring again and get rid of the debuff.

    Not really sure if I'm going in circles here.
    I really like the idea with the randomness. I guess it could get a tough think to balance. But I don't see how to work without randomness. The results would always be the same?(!) So the team with the better players wins.

    MV10, I'll have a look at your code when I'm back home and have some time. Thanks for sharing.
     
  8. MV10

    MV10

    Joined:
    Nov 6, 2015
    Posts:
    1,889
    It's terrible code, the point is the "correct" complexity is an arbitrary design decision.
     
  9. LMan

    LMan

    Joined:
    Jun 1, 2013
    Posts:
    493
    Okay I begin to understand now, you're right, if the player only sees all the data in the context of an entire match rather than a specific shot, randomness begins to make sense.

    Does the player make any decisions mid-game? Swapping players in and out, changing positions, the equivalent of calling "plays" in American football? It might be interesting to give the odds a push in one direction, and then the player has to adjust his strategy to accommodate the new problems.
     
  10. Not_Sure

    Not_Sure

    Joined:
    Dec 13, 2011
    Posts:
    3,546
    Lie to the player.

    If it's 75%, tell them it's 50%.

    If it's 50%, tell them it's 40%.

    Problem solved.
     
  11. LMan

    LMan

    Joined:
    Jun 1, 2013
    Posts:
    493
    I disagree- the whole point of rolls is to encourage the player to make decisions to manage risk. If a player can't do that effectively because we're fooling with the numbers, it's not worth it for him to do anything but maximize the number of shots he takes, rather than on trying to take the "right" shots.

    I think it's actually more fun to give a guaranteed success as a result of playing well. Of course it goes the other way too- guaranteed fail as a result of playing poorly. That may not be fun, but if the player is going to just reload/reset after a bad roll anyway, it could work.

    You can also "mitigate" as in it requires more successful rolls to win, so that giving one away isn't worth as much- then of course you need the opportunity for those additional rolls.

    Or, as is the case with the management game being discussed here, you can get away with using straight RNG as long as the results are presented as a set of rolls, and not as individual rolls. If the player looks at the results in context of a large enough sample, the nature of RNG makes sense.
     
  12. Not_Sure

    Not_Sure

    Joined:
    Dec 13, 2011
    Posts:
    3,546
    I think that sharing the actual math with players is WAY over rated and giving approximations that make them feel lucky is just fine.

    If they were to ever catch on, then they have the extra added challenge of reverse engineering the math to figure out the actual mechanics. And believe it or not, munchkins love that sort of stuff. It means that there's hidden knowledge that can give them a leg up in the game that no one else has.
     
    MV10 likes this.
  13. MV10

    MV10

    Joined:
    Nov 6, 2015
    Posts:
    1,889
    Indeed, that's how XCOM became the poster-child for questions about fudging percentages: a bunch of people tracked thousands of actual results against the game's stated percentages and proved statistically it was lying to the players. (In the old days, we'd have just disassembled the damned thing and read the code.)
     
  14. Railon23

    Railon23

    Joined:
    Jan 30, 2014
    Posts:
    32
    Yes, let's talk about that, changing tactics (e.g. be more offensive) to increase the success rate of a chance.

    I'm thinking about giving the player total insight into the calculations. Is that a bad idea?
    I saw you guys were talking about players trying to understand the game in every detail. Why not show it to them? I mean not everything at once. But if you're really interested in the different modifiers which increase/decrease your chances to succeed you can have a look.

    Just found this video here explaining the combat log of Pillars of Eternity:


    Let's come back to my idea: Here's a scribble of an event. (a) the "initial event chance" and (b) the same event with one modifier. I just made this "Offensive" tactic modifier up. Positive: 15% percentage of scoring. Negative: 10% chance for counter attack for the other team. Later there can be a lot more modifiers, but let's keep it simple for now.

    2017-02-08_scoring-event.jpg
    The first idea is to present only the success rate as percentage value. That's the basic view. Maybe like in XCOM. I think also Pillars of Eternity had a "hit chance" percentage shown when you hover over opponents. If the player wants to know more details something like the bar above could be shown with a list below containing all modifiers for that event.

    I'm not really sure, but I hope to get the user excited about the modifiers and their impact on the outcome of the calculation(s). Think about showing them also the roll on top of that bar (e.g. little arrow graphic). Let's say the user rolled a 75. In the normal / "initial event" without modifiers he would miss the chance. With the "offensive" tactic he would score, because the roll is in that modifier zone. So his tactic and risk to play more offensive helped him to shot that (very important) goal in overtime.
    Your thoughts?
     
  15. MV10

    MV10

    Joined:
    Nov 6, 2015
    Posts:
    1,889
    The lesson from XCOM is that human beings are notoriously awful at understanding statistics.

    The whole reason XCOM fakes the data in the first place is because the players "felt" the exposed modifiers were already being faked -- when they were not. If you show a person a 90% success rate three times in a row, and they still fail three times in a row, thanks to legitimate random bad luck, they're going to assume that 90% is fake and the game is cheating them out of a sure thing.

    It's human nature.

    There are very narrow categories of gamers (I think of them as the strategy wargame types, but that's a bias since I'm one of them) who won't react this way but your average person always overestimates their chances of success. Otherwise nobody would play the lottery...
     
    LMan, Not_Sure and Railon23 like this.
  16. Railon23

    Railon23

    Joined:
    Jan 30, 2014
    Posts:
    32
    I googled and read some interesting articles about XCOM:
    How the game difficulty levels "cheat" for you: http://www.giantbomb.com/xcom-2/3030-49817/forums/xcom-2-is-un-fair-1792143/
    A bit about randomness: http://techland.time.com/2012/10/12...metimes-arent-and-you-should-play-on-ironman/
    Player reactions/discussion: http://www.escapistmagazine.com/forums/read/9.391083-X-com-isnt-hard-its-stupid?page=1
     
    MV10 likes this.