Heroyt / tournament-generator

A set of classes used to create multiple kinds of tournament brackets in PHP
MIT License
60 stars 15 forks source link

Help Needed #1

Closed OptiMous28 closed 3 years ago

OptiMous28 commented 4 years ago

Hey,

Just a FYI, this package is amazing, it seem's to have all of the functionality i need to create my football tournaments. There is only a small problem i am hoping you can help me with.

I'm struggling to get this to work with my Laravel application.

Currently i have an array of teams that are in my database. How can i use your package to generate round-robin tournament matches (either one round or two round) and then record the schedule in my database?

Any help would be appreciated, thank you.

Heroyt commented 4 years ago

Hi,

I haven't worked on this project for a year now, but I would like to continue it in close future and database export would be my #1 thing to implement. Right now the easiest solution would be to generate a tournament and then store the Tournament class serialized. You could go the extra step and get all games and teams from the Tournament and store them separately, but there is currently no easy way to reconstruct the original classes.

I hope this helps a little and I will try to get time to work on this once more as soon as possible.

OptiMous28 commented 4 years ago

Hi @Heroyt,

Thanks for your response.

Currently I'm working on a football tournament application (hobby). What I currently do..

Create a Tournament and store it in the database Update the Tournament settings with configurations such as date, time, location, pitches, break length, match length etc.. Players opt in to play either as a team or individual players Group all players into teams e.g 6 teams of 7 players each

What i'm stuck on... Once i have the teams, i now need to generate the matches. There are 2 types of tournaments i need to create, a round robin where each team plays the other time either once or twice. And knockouts where only the winning team progresses into the next stage.

Starting with round robin, I am lost on how to generate matches so each team plays another team once/twice in a home or away type game. In addition, matches need to be given a time e.g. 9am, and separated based on the number of pitches available. If 2 pitches are booked, 2 matches can happen at the same time. I also need to ensure the same team isn't playing twice at the same time. If a 10min break is between each match, the time needs to change between each match as well.

I just thought i'd share this here in case you have any ideas around how i can better achieve this. For now, i'll continue trying to use your package and see if i can get it to work.

Thanks!

Heroyt commented 4 years ago

My package can generate round robin and single elimination brackets. I have also implemented a simple time tracking, where you can specify a game and break length, but without paralel games yet.

If you decide to try and create your own solution, you're more then welcome to look at and use my code - for generation: src/TournamentGenerator/Utilis/Generator.php. There, you can find methods to generate Round robin for up to 4 teams playing against each other (Generator::r_rGames()). For single elimination, you can look at src/TournamentGenerator/Preset/SingleElimination.php, but this may be a bit harder to understand, because I'm using my system of progressions and groups.

OptiMous28 commented 4 years ago

That's amazing thank you. I appreciate you taking the time to help.

OptiMous28 commented 4 years ago

Your code is rather advanced, I don't quite understand how you're doing some of the magic behind generating the matches for these tournaments!

Heroyt commented 4 years ago

Can you be more specific? Maybe I can help and explain something.

OptiMous28 commented 4 years ago

Using the basic example in the docs for reference...

I generate the tournament, define the Play and GameWait minutes and then generate 1 round. For my scenario, all teams play each other once.

i then pull my teams from the db and foreach them into the $tournament->team($name) object so all of my teams get populated.

When i run genGames(), i get a null array back. The matches aren't generating. Any ideas?

Heroyt commented 4 years ago

The problem is that you need to create a Group. This package generates all games based on groups.

In my implementation a Tournament is divided into Categories (optional - can be only rounds) and Rounds. Each round then has 1 or more Group. Round is just an array of multiple Groups that play at the same time.

For example: The tournament starts with 10 teams divided into two Groups A and B. Both of these groups play paralel of alternate between each other, but teams from group A only play with their opponents in the same group. Next, we would like a final group C where only the best 2 teams from group A and B will play against each other. This group will be created in its own Round. All in all, you have 2 rounds and 3 groups.

Try to look at my basic tournament creation example in docs.

Heroyt commented 4 years ago

The quickest way would be:

$group = $tournament->round('Round 1')->group('A');
foreach ($teams as $teamName) {
   $group->team($teamName);
}
$tournament->genGames();
OptiMous28 commented 4 years ago

Ok let me give this a try when I'm back home. Sorry to bother you.

Heroyt commented 4 years ago

No problem at all. I hope I helped you.

OptiMous28 commented 4 years ago

Ok so this is what I have...

    ```

$teams = $tournaments->teams; // collection of teams returned from my database

    $tournament = new Tournament('Tournament name'); // from here onwards, this is using your package classes

    $tournament
        ->setPlay($tournaments->settings->match_length)
        ->setGameWait($tournaments->settings->break_length)
        ->setRoundWait(0);

    $round = $tournament->round("1st Leg");

    $group = $round->group('Round One');

    foreach ($teams as $team) {
        $group->team($team->name);
    }

    $group->genGames();

    dd($tournament);


$tournament now shows me all of my games generated but i'm not entirely sure of how to work with this data. I was expecting the match to have a carbon timestamp to use for the timing of the match. I couldn't find anywhere the timing itself being stored. Essentially I want to loop through all games, update my database with the teams facing each other and the time.

Any ideas?
DQ318 commented 3 years ago

Hi @Heroyt !

Very cool this package of classes. I'm still getting the hang of PHP and would like a little help from you, if possible. How do I see the results of the championship example, that you pass in this link below? Just echoing the variables I can see but I can't get a real view of how the class works that way. Could you help me with this exit? Thanks for listening.

*I followed the guidelines on this page (https://github.com/Heroyt/tournament-generator/blob/master/docs/examples/basic.md)

Heroyt commented 3 years ago

Hello guys (@mous2890, @DQ318),

sorry for not responding to your questions. I haven't touched this project in 2 years (mainly because of school), but now I am returning to work on it once again. I don't know if you are still using this package, or not but I have pushed a new version out. It consists mainly of refactoring and other "small" but necessary updates.

I will be working on a way to export the brackets / scores (into a DB) in the coming weeks.

I'm gonna close this issue for now, but if you still want to use this package and have some problems, do create a new one.