feat(游戏模块): 重构比赛逻辑并添加赛制支持
- 移除了原有的比赛时间检查逻辑 - 引入了赛制类文件,实现了比赛自动编排功能 - 新增了 GameMatch 模型用于存储比赛对阵信息 - 优化了数据库事务处理逻辑 - 更新了 Composer 自动加载配置,添加 format 命名空间
This commit is contained in:
72
format/Game17.php
Normal file
72
format/Game17.php
Normal file
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
namespace format;
|
||||
|
||||
class Game17 implements GameInterface
|
||||
{
|
||||
// 赛制说明
|
||||
public function describe(): string
|
||||
{
|
||||
return '双打+八人转 比赛说明:
|
||||
每个人与其他人各搭档1次,决出个人排名
|
||||
数 4 ≦ n ≦ 16 (Default:8)
|
||||
轮数 3 ≦ m<n (Default:7)
|
||||
报名费 0 ≦ m ≦ 10 元 (Default: 5)
|
||||
由前几名按比例瓜分 (可调 Default:40%/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++) {
|
||||
$team[] = json_encode([
|
||||
'name' => 'team' . $i . $j,
|
||||
'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'],
|
||||
]
|
||||
]
|
||||
]);
|
||||
}
|
||||
}
|
||||
// dd($team);
|
||||
$ttotal = count($users);
|
||||
$n = 1;
|
||||
for ($i = 0; $i < $ttotal; $i++) {
|
||||
for ($j = $i + 1; $j < $ttotal; $j++) {
|
||||
$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' => $team[$i],
|
||||
'teamB' => $team[$j],
|
||||
];
|
||||
$n++;
|
||||
}
|
||||
}
|
||||
// dd($math);
|
||||
|
||||
return $math;
|
||||
}
|
||||
|
||||
// 奖金分配
|
||||
public function prize($rank): array
|
||||
{
|
||||
return $rank;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user