mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-22 05:51:12 -05:00
Fix company type distribution logic
This commit is contained in:
@@ -376,18 +376,22 @@ Deno.serve(async (req) => {
|
||||
|
||||
console.info(`✓ Selected company types (${selectedCompanyTypes.length}):`, selectedCompanyTypes);
|
||||
|
||||
// Calculate fair distribution: base amount per type + extras
|
||||
const basePerType = Math.floor(plan.companies / selectedCompanyTypes.length);
|
||||
const extras = plan.companies % selectedCompanyTypes.length;
|
||||
|
||||
console.info(`Distribution plan: ${basePerType} base per type, ${extras} extra(s) to first types`);
|
||||
|
||||
let companiesCreatedTotal = 0;
|
||||
|
||||
for (let typeIndex = 0; typeIndex < selectedCompanyTypes.length; typeIndex++) {
|
||||
const compType = selectedCompanyTypes[typeIndex];
|
||||
const pluralType = pluralizeCompanyType(compType);
|
||||
|
||||
// Calculate fair distribution: remaining companies / remaining types
|
||||
const remainingCompanies = plan.companies - companiesCreatedTotal;
|
||||
const remainingTypes = selectedCompanyTypes.length - typeIndex;
|
||||
const count = Math.ceil(remainingCompanies / remainingTypes);
|
||||
// Each type gets base amount, first N types get +1 extra
|
||||
const count = basePerType + (typeIndex < extras ? 1 : 0);
|
||||
|
||||
console.info(`✓ Generating ${count} companies of type ${compType} (${remainingCompanies} remaining, ${remainingTypes} types left)`);
|
||||
console.info(`✓ Generating ${count} companies of type ${compType}`);
|
||||
|
||||
for (let i = 0; i < count; i++) {
|
||||
console.info(` Creating company ${i + 1}/${count} (type: ${compType})`);
|
||||
|
||||
Reference in New Issue
Block a user