Author Topic: Algorithm for dividing loot  (Read 927 times)

Offline Chris

  • Game Owner
  • Level 35
  • *
  • Posts: 2,217
  • Reputation: +28/-1
    • View Profile
Algorithm for dividing loot
« on: July 03, 2011, 09:17:18 AM »
There is a pirate ship, each player(pirate) has certain power. They just looted a merchant ship and got limited number of coins as a reward. The pirates will divide the loot depending on the individual pirates power. How to make algorithm to divide the loot? (alternatively, you can think of it as sultans with varied fame&wealth trying to get the most girls to their harem from a limited pool of girls; whatever make you think better :))

The reward is divided based on power.
The reward is a low number (like 20 rewards to divide among 10 players), so simply getting sum of the total power of all players and calculating how much power 1 reward need won't necessarily do the trick.

Ideally, if the difficulty of getting next reward is much higher than getting the first (example: power 1=1 reward, power 3=2 rewards, power 6=3 rewards).
I could live with the rewards being distributed as estimate (like there is 20 rewards in theory but the algorithm distribute 19 or 21).

Offline Nox

  • Level 35
  • **
  • Posts: 767
  • Reputation: +12/-2
    • View Profile
Re: Algorithm for dividing loot
« Reply #1 on: July 03, 2011, 01:17:02 PM »
Use the relations of power=reward you described, then make a sum of the reward, calc ratio of this sum and actual total reward and recalc it back, round it and if the distributed total is lower - imho shouldn't be by more than 1 point - give it to one of them...

Following your attitude it would be to strongest player
To make it more friendly then to weakest player ('d like this better)
Or at random ('d like this the most)

Example
Code: [Select]
$totalReward = 30;
$rewardClaims = array(9,3,2);
$claimTotal = array_sum($rewardClaims); // 14
$ratio = $totalReward / $claimTotal; // 2.14

$rewards = $rewardClaims;

foreach($rewards as $key => $reward)
  $rewards[$key] = round($reward * $ratio, 0);

$rewards[ mt_rand(0, count($rewards)-1) ] += max($totalReward - array_sum($rewards), 0);
Meet us at an IRC irc.freenode.net #bbg as well
https://vimeo.com/36579366 (a must-watch) | Join BOINC - no longer a hype, but you can help never the less

Offline Chris

  • Game Owner
  • Level 35
  • *
  • Posts: 2,217
  • Reputation: +28/-1
    • View Profile
Re: Algorithm for dividing loot
« Reply #2 on: July 03, 2011, 03:13:45 PM »
Right... first step of simple ratio and second step of distributing modulus, it might work...

Quote
To make it more friendly then to weakest player
This might result in claim 2 being better than claim 3 (if ratio is below 0.3).

Now about difficulty of getting next reward becoming much higher. I thought that maybe some math function to reduce the claim value? Something that would keep 2 as 2, 3 as 2.8, 9 as 5. How is such function called (I really sux at math :D)?

Offline Nox

  • Level 35
  • **
  • Posts: 767
  • Reputation: +12/-2
    • View Profile
Re: Algorithm for dividing loot
« Reply #3 on: July 03, 2011, 04:16:48 PM »
true...so anyway, 'd give it as a random little bonus

logarithm?
Meet us at an IRC irc.freenode.net #bbg as well
https://vimeo.com/36579366 (a must-watch) | Join BOINC - no longer a hype, but you can help never the less

Offline CygnusX

  • Level 24
  • *
  • Posts: 303
  • Reputation: +3/-2
    • View Profile
    • Lords of Midnight
Re: Algorithm for dividing loot
« Reply #4 on: July 03, 2011, 11:01:59 PM »
Perhaps if you have players A, B, C that all work together, splitting would be something like:

A Loot = sqrt(a) / sum(sqrt(A) + sqrt(b) + sqrt(C)) * Gold captured

This would make it increasingly more difficult for more powerful players to gain gold.


Offline saljutin

  • Level 22
  • *
  • Posts: 266
  • Reputation: +6/-0
    • View Profile
Re: Algorithm for dividing loot
« Reply #5 on: July 04, 2011, 12:15:40 PM »
I think that you (chris) want to create some sort of "fair" system where gap between player because of power does not raise so quick

this SQRT system should be good...but lets say this if you have A and B
A=10, B=1000 power - B gets 10 times of loot that A gets
so here is catch - how does player grow from 10 to 11 and 1000 to 1001? you need to calculate this cost into your formula to make it good and create "economy"

when player A goes from 10 to 11, and B stays at 1000 he gains only 9.534x more then player A that is 5,34% gain
if player B goes to 1001, and A stays at 10 then he gets 10,005x more so that is only 0,05% gain
if both goes from 10 to 11 and 1000 to 1001 then this means 9,539x more

so how to make this work?
do like 100 iterations...lets say A=10 and B=1000 and THEY DONT upgrade...they attack that ship 100 times and spend money gained to upgrade power, so what is then? that gap is not 10x large but how much?

BUT nevertheless the gap ALWAYS stays with such systems - but in time it gets so small...it converges factor 1.00 which means 2 players are the same -> which is not GOOD solution if both players used same tactics and one player stared 1month before...

Offline Chris

  • Game Owner
  • Level 35
  • *
  • Posts: 2,217
  • Reputation: +28/-1
    • View Profile
Re: Algorithm for dividing loot
« Reply #6 on: July 08, 2011, 03:58:47 AM »
Yes... SQRT will make very high numbers silly and useless. Not sure if there is a fix for this (except for keeping the numbers reasonably low and similar)... Maybe mix SQRT with some linear function or use a different function above certain claim thereshold?

OK, so far we have:
Code: [Select]
$rewardClaims = array(sqrt(9),sqrt(3),sqrt(2));Now, I wanted to add a cap. Each player can get maximum 10 rewards(coins). So, a player can get between 0 and 10 rewards based on claim power. How to do it?

Offline cylentwolf

  • Level 3
  • *
  • Posts: 6
  • Reputation: +0/-0
    • View Profile
Re: Algorithm for dividing loot
« Reply #7 on: August 26, 2011, 12:07:22 PM »
I'd go through and give everyone 1 coin first to make sure that everyone gets something then use your formula.  you could even do it a few times until caps are reached and just remove that player from the pool.

Also if you limit the gap between powerful player and weak player then why would the powerful player help?  better for him to solo and get all the loot.

Offline Chris

  • Game Owner
  • Level 35
  • *
  • Posts: 2,217
  • Reputation: +28/-1
    • View Profile
Re: Algorithm for dividing loot
« Reply #8 on: August 29, 2011, 06:32:22 AM »
I'd go through and give everyone 1 coin first to make sure that everyone gets something then use your formula.  you could even do it a few times until caps are reached and just remove that player from the pool.

Also if you limit the gap between powerful player and weak player then why would the powerful player help?  better for him to solo and get all the loot.
They can't solo. The example was simplified, actualy there will be for medieval kingdom war. But for the sake of of this topic assume there are only 10 ships total in the game and new ships won't appear, so they have to fight as a group :)

No, there is no need for everyone to get something (it's OK to get nothing at the very beginning, it's only one of the rewards). I'm more concerned with the top power players. Maybe make it that top 3 power/claim pirates get +1 coin?

 


SimplePortal 2.3.3 © 2008-2010, SimplePortal