dimanche 6 octobre 2019

Render tournament bracket for next stage

I would like to ask how do I render tournament bracket for next stages? Currently I am implementing bracket placement proposed by Tournament bracket placement algorithm .The result Im getting now is https://i.imgur.com/X5iL6sw.png but I wanted to loop for next stages like so https://i.imgur.com/Zi3ytgl.png .Do I need to create a logic for each stages or addup attributes in migration table in order to save specific rounds?

(bracketscontroller)

if($bracket->type == "Single Elimination")
        {
            $numOfParticipant = $bracket->size;
            $rounds = ceil(log($numOfParticipant)/log(2));
            $bracketSize = pow(2, $rounds);
            $requiredByes = $bracketSize - $numOfParticipant;

            if($numOfParticipant<2)
            {
                return [];
            }

            $matches = array(array(1,2));

            for($round=1; $round<$rounds; $round++)
            {
                $roundMatches = [];
                $sum = pow(2, $round + 1) + 1;

                foreach($matches as $match)
                {
                    $teamA = $this->changeIntoBye($match[0], $numOfParticipant);
                    $teamB = $this->changeIntoBye($sum - $match[0], $numOfParticipant);
                    $roundMatches[] = array($teamA, $teamB);
                    $teamA = $this->changeIntoBye($sum - $match[1], $numOfParticipant);
                    $teamB = $this->changeIntoBye($match[1], $numOfParticipant);
                    $roundMatches[] = array($teamA, $teamB);
                }

                $matches = $roundMatches;
            }

public function changeIntoBye($seed,  $numOfParticipant)
    {
        return $seed <= $numOfParticipant ?  $seed : null;
    }

(bladefile)

<div class="round r-of-2-se-4">
    @foreach($matches as $match)
        <div class="bracket-game">
                <div class="player top">
                 &nbsp;&nbsp;
                 <div class="score">
                   0
                 </div>
            </div>
            <div class="player bot">
                 &nbsp;&nbsp;
                 <div class="score">
                  0
                 </div>
             </div>
         </div>
     @endforeach
</div>


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire