Files
fast/format/Game17.php
xiadc 94a540ac96 feat(shopro): 优化比赛模块功能和流程
- 新增赛制说明接口和页面
- 实现比赛列表和对阵详情页面
- 添加比赛计分功能
- 优化比赛报名和参赛者分配逻辑
- 重构赛制配置和对阵安排方法
2025-05-27 08:51:27 +08:00

92 lines
3.0 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace format;
class Game17 implements GameInterface
{
// 赛制说明
public function describe(): string
{
return '双打+八人转 比赛说明:
每个人与其他人各搭档1次决出个人排名
数 4 ≦ n ≦ 16 (Default8)
轮数 3 ≦ mn (Default7)
报名费 0 ≦ m ≦ 10 元 (Default: 5)
由前几名按比例瓜分 (可调 Default40%/30%/20%/10%)';
}
// 首轮对阵安排
public function match($game, $users): array
{
$math = $team = [];
$utotal = count($users);
//队伍分配
for ($i = 0; $i < $utotal; $i++) {
for ($j = $i + 1; $j < $utotal; $j++) {
$teamName = 'team' . $i . $j;
// $team[] = json_encode([
$team[] = ([
'name' => $teamName,
'user' => [
[
'user_id' => $users[$i]['user_id'],
'gender' => $users[$i]['gender'],
'avatar' => $users[$i]['avatar'],
'name' => $users[$i]['name'],
],
[
'user_id' => $users[$j]['user_id'],
'gender' => $users[$j]['gender'],
'avatar' => $users[$j]['avatar'],
'name' => $users[$j]['name'],
]
]
]);
$users[$i]['team'] = $users[$j]['team'] = $teamName;
}
}
// dd($team);
// 对阵分配
$ttotal = count($team);
df("$utotal 人:");
$n = 1;
for ($i = 0; $i < $ttotal; $i++) {
for ($j = $i + 1; $j < $ttotal; $j++) {
if (array_intersect(array_column($team[$i]['user'], 'user_id'), array_column($team[$j]['user'], 'user_id'))) {
continue;//一个人不能同时在两边队伍
}
$math[] = [
'gym_id' => $game['gym_id'],
'club_id' => $game['club_id'],
'act_id' => $game['act_id'],
'game_id' => $game['id'],
'level' => 1, //轮次
'turn' => $n, //场次
'teamA' => json_encode($team[$i]), //队伍A
'teamB' => json_encode($team[$j]), //队伍B
];
// $ta =array_column($team[$i]['user'],'user_id');
// $tb =array_column($team[$j]['user'],'user_id');
// df("第 $n 场:".$ta[0].'/'.$ta[1].' VS '.$tb[0].'/'.$tb[1]);
$n++;
}
}
// dd($math);
$this->next($game, $math);
return $math;
}
// 下一轮对阵安排
public function next($game, $math): array
{
$math = [];
return $math;
}
// 奖金分配
public function prize($rank): array
{
return $rank;
}
}