fix: incorrect wagon count while generating a r.stock

This commit is contained in:
2024-02-14 15:04:23 +01:00
parent ed191d597b
commit 7fb4b0ae26
+7 -8
View File
@@ -222,30 +222,29 @@ export default defineComponent({
}; };
for (let i = 0; i < 10; i++) { for (let i = 0; i < 10; i++) {
const headingLoco = this.store.stockList[0]?.isLoco ? this.store.stockList[0] : undefined; this.store.stockList.splice(this.store.stockList[0]?.isLoco ? 1 : 0);
this.store.stockList.length = headingLoco ? 1 : 0; let carCount = 0;
const maxMass = this.store.acceptableMass > 0 ? Math.min(this.store.acceptableMass, this.maxMass) : this.maxMass; const maxMass = this.store.acceptableMass > 0 ? Math.min(this.store.acceptableMass, this.maxMass) : this.maxMass;
let exceeded = false; // eslint-disable-next-line no-constant-condition
while (true) {
while (!exceeded) {
const randomStockType = generatedChosenStockList[~~(Math.random() * generatedChosenStockList.length)]; const randomStockType = generatedChosenStockList[~~(Math.random() * generatedChosenStockList.length)];
const { carWagon, cargo } = randomStockType.carPool[~~(Math.random() * randomStockType.carPool.length)]; const { carWagon, cargo } = randomStockType.carPool[~~(Math.random() * randomStockType.carPool.length)];
if ( if (
this.store.totalMass + (cargo?.totalMass || carWagon.mass) > maxMass || this.store.totalMass + (cargo?.totalMass || carWagon.mass) > maxMass ||
this.store.totalLength + carWagon.length > this.maxLength || this.store.totalLength + carWagon.length > this.maxLength ||
this.store.stockList.length > this.maxCarCount carCount >= this.maxCarCount
) { ) {
exceeded = true;
break; break;
} }
this.addCarWagon(carWagon, cargo); this.addCarWagon(carWagon, cargo);
carCount++;
} }
const currentGenerationValue = this.store.totalLength + this.store.totalMass + this.store.stockList.length; const currentGenerationValue = this.store.totalLength + this.store.totalMass + carCount;
if (bestGeneration.value < currentGenerationValue) { if (bestGeneration.value < currentGenerationValue) {
bestGeneration.stockList = this.store.stockList; bestGeneration.stockList = this.store.stockList;