Fix horse race seed pool payouts
This commit is contained in:
+22
-12
@@ -114,33 +114,43 @@ class HorseRace extends Model
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据注池计算各马匹实时赔率(彩池制,扣除庄家抽水后按比例分配)。
|
||||
* 计算本场可派奖总池。
|
||||
*
|
||||
* @param int $horseBetAmounts 各马匹的注额数组 [horse_id => amount]
|
||||
* @param int $housePercent 庄家抽水百分比
|
||||
* 可派奖池 = 系统初始化资金池 + 玩家总下注 - 抽水,
|
||||
* 且至少不低于中奖马匹总下注,避免出现“押中反亏”的体验。
|
||||
*
|
||||
* @param array<int, int|float> $horseBetAmounts
|
||||
*/
|
||||
public static function calcDistributablePool(array $horseBetAmounts, int $housePercent, int $seedPool = 0, int $winnerPool = 0): float
|
||||
{
|
||||
$totalPool = array_sum($horseBetAmounts);
|
||||
$netPlayerPool = $totalPool * (1 - $housePercent / 100);
|
||||
|
||||
return max($netPlayerPool + max(0, $seedPool), $winnerPool);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据注池计算各马匹实时赔率(含系统初始化资金池)。
|
||||
*
|
||||
* @param array<int, int|float> $horseBetAmounts 各马匹的注额数组 [horse_id => amount]
|
||||
* @return array<int, float> horse_id => 赔率(含本金)
|
||||
*/
|
||||
public static function calcOdds(array $horseBetAmounts, int $housePercent): array
|
||||
public static function calcOdds(array $horseBetAmounts, int $housePercent, int $seedPool = 0): array
|
||||
{
|
||||
$totalPool = array_sum($horseBetAmounts);
|
||||
|
||||
if ($totalPool <= 0) {
|
||||
// 尚无下注,返回等额赔率
|
||||
$count = count($horseBetAmounts);
|
||||
|
||||
return array_map(fn () => 1.0, $horseBetAmounts);
|
||||
}
|
||||
|
||||
$netPool = $totalPool * (1 - $housePercent / 100);
|
||||
$distributablePool = static::calcDistributablePool($horseBetAmounts, $housePercent, $seedPool);
|
||||
$odds = [];
|
||||
|
||||
foreach ($horseBetAmounts as $horseId => $amount) {
|
||||
if ($amount <= 0) {
|
||||
// 无人押注的马,赔率设为理论最大值
|
||||
$odds[$horseId] = round($netPool, 2);
|
||||
$odds[$horseId] = round($distributablePool, 2);
|
||||
} else {
|
||||
// 赔率 = 净注池 / 该马注额(含本金返还)
|
||||
$odds[$horseId] = round($netPool / $amount, 2);
|
||||
$odds[$horseId] = round($distributablePool / $amount, 2);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user