• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[General] Gold Distribution - Maths Problem

Status
Not open for further replies.
Level 16
Joined
Mar 27, 2011
Messages
1,349
I have a tower defence map where gold is distributed to players at the end of each round. There is a gold pool which is split according to the pecentage of kills someone has. The idea is that the more kills someone has, the less of the gold pool they get. The less kills someone has, the more of the gold pool they get.

Here's the simplified version of my trigger

  • Add Point
    • Events
      • Unit - A unit owned by Player 11 (Dark Green) Dies
      • Unit - A unit owned by Player 12 (Brown) Dies
    • Conditions
    • Actions
      • Set leaderboard[(Player number of (Owner of (Killing unit)))] = (leaderboard[(Player number of (Owner of (Killing unit)))] + 1)
      • Set TotalKills = (TotalKills + 1)
      • Leaderboard - Change the value for (Owner of (Killing unit)) in (Last created leaderboard) to leaderboard[(Player number of (Owner of (Killing unit)))]
      • Leaderboard - Sort (Last created leaderboard) by Value in Descending order
  • Distribute Gold
    • Events
    • Conditions
    • Actions
      • Game - Display to (All players) for 15.00 seconds the text: Round Complete!
      • Set TempInteger = (Number of players in PlayersGroup)
      • Set GoldPool = 30.00
      • Player Group - Pick every player in PlayersGroup and do (Actions)
        • Loop - Actions
          • Set GoldPlayerPercentage[(Player number of (Picked player))] = ((Real(leaderboard[(Player number of (Picked player))])) / (Real(TotalKills)))
          • Set TempReal = ((1.00 - GoldPlayerPercentage[(Player number of (Picked player))]) x GoldPool)
          • Player - Add (Integer(TempReal)) to (Picked player) Current gold


The system worked fine when there are only 2 players, but I think the system won't work when there are more. Take a look at the screenshot from in game.

gold-distribution-bug-jpg.276726


30 total kills

player 1 has 30 kills
player 2 has 0 kill
player 3 has 0 kills

The system will award player 2 and 3 with 30 gold each. The total gold pool is 30, so they should each only get 15 each and player 1 should get nothing.

Can anyone help fix my system?
 
I thought of resolving this with an inversion, although this still seems hypothetical.

Take this instance, for example: (Note: this is in pseudo-code)
JASS:
...
player1_kill = 50
player2_kill = 0
player3_kill = 0

total_kill = 50
...

We get their additive conjugate in relation to their total sum:

JASS:
...
total_kill = 50

invert player1_kill = (50 - player1_kill) {0}
invert player2_kill = (50 - player2_kill) {50}
invert player3_kill = (50 - player2_kill) {50}

total_kill = 100

if total_kill == 0
    //abort
    return
end

We then compute the ratio in order to get the desired percentage:

JASS:
player1_goldRatio = player1_kill / total_kill {0.}
player2_goldRatio = player2_kill / total_kill {0.5}
player3_goldRatio = player3_kill / total_kill {0.5}

In the scenario above, a certain player's gold can be 0 if and only if no other players secured a kill. It will only approach 0 when there is at least 1 kill.

Another Example:
JASS:
...
player1_kill = 15
player2_kill = 270
player3_kill = 15

total_kill = 300
...

JASS:
invert player1_kill = 285
invert player2_kill = 30
invert player3_kill = 285

total_kill = 600

JASS:
player1_goldRatio = player1_kill / total_kill {0.475}
player2_goldRatio = player2_kill / total_kill {0.05}
player3_goldRatio = player3_kill / total_kill {0.475}
 
Level 16
Joined
Mar 27, 2011
Messages
1,349
Thanks for taking some time to write this up. I however couldn't get it to yield the results I'm after. Here's my modified code:

  • Set TempInteger = (Number of players in PlayersGroup)
  • Set GoldPool = 20.00
  • Player Group - Pick every player in PlayersGroup and do (Actions)
    • Loop - Actions
      • Set InvertPlayerKills = (TotalKills - PlayersKills[(Player number of (Picked player))])
      • Set TempTotalKills = (TempTotalKills + InvertPlayerKills)
  • Player Group - Pick every player in PlayersGroup and do (Actions)
    • Loop - Actions
      • Set GoldPlayerDecimal[(Player number of (Picked player))] = ((Real(PlayersKills[(Player number of (Picked player))])) / (Real(TempTotalKills)))
      • Set TempReal = (GoldPlayerDecimal[(Player number of (Picked player))] x GoldPool)
      • Player - Add (Integer(TempReal)) to (Picked player) Current gold
20 gold pool

Player 1 got 10 gold (should have got 0). Players 2 and 3 got nothing (should have got 10 each). Did I do something wrong? BTW, I'm going to bed now, will check forums tomorrow.
 
Thanks for taking some time to write this up. I however couldn't get it to yield the results I'm after. Here's my modified code:

  • Set TempInteger = (Number of players in PlayersGroup)
  • Set GoldPool = 20.00
  • Player Group - Pick every player in PlayersGroup and do (Actions)
    • Loop - Actions
      • Set InvertPlayerKills = (TotalKills - PlayersKills[(Player number of (Picked player))])
      • Set TempTotalKills = (TempTotalKills + InvertPlayerKills)
  • Player Group - Pick every player in PlayersGroup and do (Actions)
    • Loop - Actions
      • Set GoldPlayerDecimal[(Player number of (Picked player))] = ((Real(PlayersKills[(Player number of (Picked player))])) / (Real(TempTotalKills)))
      • Set TempReal = (GoldPlayerDecimal[(Player number of (Picked player))] x GoldPool)
      • Player - Add (Integer(TempReal)) to (Picked player) Current gold
20 gold pool

Player 1 got 10 gold (should have got 0). Players 2 and 3 got nothing (should have got 10 each). Did I do something wrong? BTW, I'm going to bed now, will check forums tomorrow.

This part...

  • Set GoldPlayerDecimal[(Player number of (Picked player))] = ((Real(PlayersKills[(Player number of (Picked player))])) / (Real(TempTotalKills)))
can be redefined as

  • Set GoldPlayerDecimal[(Player number of (Picked player))] = ((Real(TotalKills - PlayersKills[(Player number of (Picked player))])) / (Real(TempTotalKills)))
Hopefully, that worked out fine.
 
Status
Not open for further replies.
Top