What are the best practices for structuring PHP functions to handle complex game logic, such as determining winning combinations like small straße or große straße?

To handle complex game logic like determining winning combinations such as small straße or große straße in PHP functions, it is best to break down the logic into smaller, reusable functions for better maintainability and readability. By creating separate functions to check for each winning combination, the code becomes more modular and easier to test. Additionally, using clear and descriptive function names can help make the code more understandable to others.

function checkSmallStraße($diceValues) {
    sort($diceValues);
    $uniqueValues = array_unique($diceValues);
    
    if(count($uniqueValues) >= 4) {
        $consecutiveCount = 1;
        
        for($i = 0; $i < count($uniqueValues) - 1; $i++) {
            if($uniqueValues[$i] + 1 == $uniqueValues[$i + 1]) {
                $consecutiveCount++;
            }
        }
        
        if($consecutiveCount >= 4) {
            return true;
        }
    }
    
    return false;
}

function checkGroßeStraße($diceValues) {
    sort($diceValues);
    $uniqueValues = array_unique($diceValues);
    
    if(count($uniqueValues) == 5 && ($uniqueValues[4] - $uniqueValues[0]) == 4) {
        return true;
    }
    
    return false;
}