This is a dog racing game, there are videos and the first 3 winners are known for each video, the players choose the winners within a X limit time. Based on their betting the algorithm chooses the proper video to keep the returning percentage of each Point Of Sale / Client, at its previously specified amount.
Something like this:
% Returning Specific Return Configuration, range: 50%~90%:
POS1: 65%
POS2: 78%
POS3: 50%
...
...
POSN: XX%
Each POS has different income and should return back depending on its configuration:
Ex: [pos] [cashes] [should return] [returns] [step]
-------------------------------------------------------
POS1 100 65 60 44
POS2 100 78 50 45
POS3 500 250 150 45
Based on certain combinations happens that the return is lower, so the remaining is considered as a debt. This is due to the fact that each shop is selling numbers like:
POS1: [Cashes] ["Winners" Number] [Possible Return]
50 12 150
50 13 60
so the algorithm tries to find the nearest combination in restricted possibilities that returns that value + accumulated month debt, based on each step like:
sum([should return]) of step 45
+ lowest not returned part of the month ([should return]-[returns])
of the stores present at that step (45)
At the end of a relative long period (~30 days, that is the duration phase of the process) the specific returning has been:
POS1: 64.4%
POS2: 72.9%
POS3: 49.2%
...
It is working 8 months now, and have no apparent problem but if i have been clear enough is it the right logic?
Each step lasts 5 minutes
*** EDIT ***
It happens that using some extra bonus over the returned percentage the negative difference, so "clients debt", depending on the value causes a block to the returns for every step, till that POS returns to its percentage.
So i changed the "lowest not returned part of the month ([should return]-[returns]) " to a random picked of the players in that step. This helps but not enough because when that negative player pos is alone in many consecutive steps... actually it doesn't give any return. Not really a nice thing, so I added some limit of what actually i use from this negative debt and the range of the random factor is
sum([should return]) of step 45
+ ((case when the debt is negative under some relative "considerable" limit)
random[range(-0.01, 0.2)] * not returned part of the month ([should return]-[returns])
else the ([should return]-[returns]))
Actually range(-0.01, 0.2) means that the pos can return under some relative limits, and in fact the store started returning again even playing alone.