lucagentile/roundrobin-scheduler

此包已被废弃且不再维护。未建议替代包。

轮询赛事的实用工具。Laravel 兼容。

dev-master 2017-08-18 17:46 UTC

This package is not auto-updated.

Last update: 2022-05-04 10:04:19 UTC


README

您可以轻松创建赛事的轮询轮次。

Laravel 兼容。

有两种方法。一种是 BergerAlgorithm($teams),它接受一个包含队伍的数组作为参数,并返回比赛集合。

给定一个包含队伍的数组,如

['Juventus', 'Milan', 'Roma', 'Napoli', 'Inter']    

该方法返回一个多层数组,其中第一层是比赛日

[
    [
        ['REST', 'Juventus'], ['Inter', 'Milan'],  ['Napoli', 'Roma']
    ],
    [
        ['Juventus', 'Milan'], ['Roma', 'REST'], ['Napoli', 'Inter']
    ],
    [
        ['Roma', 'Juventus'], ['Milan', 'Napoli'], ['REST', 'Inter']
    ],
    [
        ['Juventus', 'Napoli'], ['Inter', 'Roma'], ['REST', 'Milan']
    ],
    [
        ['Inter', 'Juventus'], ['Napoli', 'REST'], ['Roma', 'Milan']
    ]
]

如果队伍数量为奇数,它会添加一个虚拟队伍。

另一种是 distributeAmongRounds($teams, $rounds),它接受一个包含队伍的数组以及期望的轮次数量作为参数。建议您在将团队数据集提供给函数之前对其进行 shuffle()。

给定一个包含队伍的数组以及期望的轮次数量 '3' 如此

['Milan', 'Roma', 'Juventus', 'Napoli', 'Inter', 'Lazio', 'Fiorentina', 'Udinese', 'Sampdoria', 'Genoa'],

该方法返回一个多层数组

[
    ['Genoa', 'Fiorentina', 'Napoli', 'Milan'],
    ['Sampdoria', 'Lazio', 'Juventus'],
    ['Udinese', 'Inter', 'Roma']
]

安装

composer require lucagentile\roundrobin-scheduler

Laravel

在 config/app.php 的 'providers' 下添加 ServiceProvider 类名称 https://laravel.net.cn/docs/5.4/providers#registering-providers

Gautile\RoundRobin\RoundRobinSchedulerServiceProvider::class

然后在 'aliases' 下添加 Facade 的别名

'RoundRobinScheduler' => Gautile\RoundRobin\Facades\RoundRobinScheduler::class,

许可证

MIT