src/Evaluators/HandEvaluator.php
/**
    * Group and sort the cards according to the count of each value
    * 
    * @return void
    */
Group and sort the cards according to the count of each value

@return void
Group and sort the cards according to the count of each value @return void
protected function generateValueHistogram(): Void
    {
        $values = [];
        foreach ($this->cards as $card) {
            $values[$card->getValueRank()][] = $card;
        }
        uasort($values, function($value1, $value2) {
            return (count($value2) === count($value1))
                        ? $value2[0]->getValueRank() <=> $value1[0]->getValueRank()
                        : count($value2) <=> count($value1);
        });
        foreach($values as $index => $value) {
            $sortedValues = $value;
            usort($sortedValues, fn($card1, $card2) => $card2->getSuitRank() <=> $card1->getSuitRank());
            $values[$index] = $sortedValues;
        }
        $this->valueHistogram = $values;
    }
protected function generateValueHistogram ( ) : Void { $ values = [ ] ; foreach ( $ this -> cards as $ card ) { $ values [ $ card -> getValueRank ( ) ] [ ] = $ card ; } uasort ( $ values , function ( $ value1 , $ value2 ) { return ( count ( $ value2 ) === count ( $ value1 ) ) ? $ value2 [ 0 ] -> getValueRank ( ) <=> $ value1 [ 0 ] -> getValueRank ( ) : count ( $ value2 ) <=> count ( $ value1 ) ; } ) ; foreach ( $ values as $ index => $ value ) { $ sortedValues = $ value ; usort ( $ sortedValues , fn ( $ card1 , $ card2 ) => $ card2 -> getSuitRank ( ) <=> $ card1 -> getSuitRank ( ) ) ; $ values [ $ index ] = $ sortedValues ; } $ this -> valueHistogram = $ values ; }
Group and sort the cards according to the count of each value
Group and sort the cards according to the count of each value
// Group all cards in to values // Sort values by count of cards in each value. // uasort is user defined sorting function which maintains keys which are numerical value of value // If count is the same, sort by card value rank // Else sort by number of cards for value // Sort cards of each value according to their suit rank highest first // Create copy of array to sort // Replace value array with sortedArray at index