Skip to content

Unofficial Patch - Senbatsu Infix function bugs & Proposed fixes #1

Description

@ExSlam

Unofficial Patch Infix function - I see the use of 3f in two of the conditional statements. Also 100f/0 = Infinity, so you shouldn't set num2 to 0 if number of idols in senbatsu is 0 (although you can't actually proceed with 0 idols in the lineup, it's still good to have the check). Also, use f for the divisor so you get proper results.

public static float Infix(int num)
{
    // No idols => no rows => no bonus (avoids div-by-zero by returning 0)
    if (num <= 0)
        return 0f;

    // Clamp just in case
    if (num > 15)
        num = 15;

    float rowsUsed;

    // Row 1 = 1 slot (total 1)
    if (num == 1)
    {
        rowsUsed = 1f;
    }
    // Row 2 = 2 slots (total 3)
    else if (num <= 3)
    {
        rowsUsed = 1f + (num - 1) / 2f;
    }
    // Row 3 = 3 slots (total 6)
    else if (num <= 6)
    {
        rowsUsed = 2f + (num - 3) / 3f;
    }
    // Row 4 = 4 slots (total 10)
    else if (num <= 10)
    {
        rowsUsed = 3f + (num - 6) / 4f;
    }
    // Row 5 = 5 slots (total 15)
    else
    {
        rowsUsed = 4f + (num - 10) / 5f;
    }

    return 100f / rowsUsed;
}

OR we could use a purely mathematical solution and skip the if statements entirely. There is a formula for Triangular Numbers which applies to this sort of scenario were row 1 = 1 idol, row 2 = 2 idols and total = 1 + 2 +... and so on. In short, we can implement this formula to get the number of rows for our idol count

Image

So our code for Infix becomes:

public static float Infix(int idolCount)
{
    // Total rows in the senbatsu formation:
    // 1, 2, 3, 4, 5  (total capacity = 15)
    const int totalRows = 5;

    // Safety: if no idols, don't divide by zero.
    // (The game probably never passes 0, but this prevents Infinity/NaN.)
    if (idolCount <= 0)
        return 0f;

    // Triangular number inversion:
    // Assume that r represents the minimum required number of rows to fit all our idols represented by n
    // Find the smallest r such that r(r+1)/2 >= idolCount
    //
    // r = ceil((sqrt(8N + 1) - 1) / 2)
    float n = idolCount;
    float r = (Mathf.Sqrt(8f * n + 1f) - 1f) / 2f;

    int rowsUsed = Mathf.CeilToInt(r);

    // Clamp to the real formation size:
    // Anything above 15 idols still just uses all 5 rows.
    rowsUsed = Mathf.Clamp(rowsUsed, 1, totalRows);

    // The game wants a "percentage per used row" kind of factor.
    return 100f / rowsUsed;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions