Compare commits

...

4 Commits

Author SHA1 Message Date
Spythere 5c840a7525 Merge do wersji 1.4.2
Wersja 1.4.2
2023-06-11 17:17:21 +02:00
Spythere 1fa3d4c3a1 fix: efektywniejsze generowanie składu 2023-06-11 17:12:42 +02:00
Spythere 89ceb6ae7f bump: 1.4.2 2023-06-11 16:38:49 +02:00
Spythere 445b799ff5 fix: generowanie składów 2023-06-11 16:38:38 +02:00
3 changed files with 33 additions and 28 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "pojazdownik", "name": "pojazdownik",
"version": "1.4.1", "version": "1.4.2",
"private": true, "private": true,
"scripts": { "scripts": {
"dev": "vite", "dev": "vite",
+32 -11
View File
@@ -99,7 +99,7 @@ import { defineComponent } from 'vue';
import { useStore } from '../../store'; import { useStore } from '../../store';
import stockMixin from '../../mixins/stockMixin'; import stockMixin from '../../mixins/stockMixin';
import { ICargo, ICarWagon } from '../../types'; import { ICargo, ICarWagon, IStock } from '../../types';
import warningsMixin from '../../mixins/warningsMixin'; import warningsMixin from '../../mixins/warningsMixin';
export default defineComponent({ export default defineComponent({
@@ -180,21 +180,42 @@ export default defineComponent({
return acc; return acc;
}, [] as { constructionType: string; carPool: { carWagon: ICarWagon; cargo?: ICargo }[] }[]); }, [] as { constructionType: string; carPool: { carWagon: ICarWagon; cargo?: ICargo }[] }[]);
const headingLoco = this.store.stockList[0]?.isLoco ? this.store.stockList[0] : undefined; let bestGeneration: { stockList: IStock[]; value: number } = { stockList: [], value: 0 };
this.store.stockList.length = headingLoco ? 1 : 0; for (let i = 0; i < 10; i++) {
const maxMass = this.store.acceptableMass || this.maxMass; const headingLoco = this.store.stockList[0]?.isLoco ? this.store.stockList[0] : undefined;
this.store.stockList.length = headingLoco ? 1 : 0;
new Array(this.maxCarCount).fill(0).forEach(() => { const maxMass =
const randomStockType = generatedChosenStockList[~~(Math.random() * generatedChosenStockList.length)]; this.store.acceptableMass > 0 ? Math.min(this.store.acceptableMass, this.maxMass) : this.maxMass;
const { carWagon, cargo } = randomStockType.carPool[~~(Math.random() * randomStockType.carPool.length)];
if (this.store.totalMass + (cargo?.totalMass || carWagon.mass) > maxMass) return; let exceeded = false;
if (this.store.totalLength + carWagon.length > this.maxLength) return;
this.addCarWagon(carWagon, cargo); while (!exceeded) {
}); const randomStockType = generatedChosenStockList[~~(Math.random() * generatedChosenStockList.length)];
const { carWagon, cargo } = randomStockType.carPool[~~(Math.random() * randomStockType.carPool.length)];
if (
this.store.totalMass + (cargo?.totalMass || carWagon.mass) > maxMass ||
this.store.totalLength + carWagon.length > this.maxLength ||
this.store.stockList.length > this.maxCarCount
) {
exceeded = true;
break;
}
this.addCarWagon(carWagon, cargo);
}
const currentGenerationValue = this.store.totalLength + this.store.totalMass + this.store.stockList.length;
if (bestGeneration.value < currentGenerationValue) {
bestGeneration.stockList = this.store.stockList;
bestGeneration.value = currentGenerationValue;
}
}
this.store.stockList = bestGeneration.stockList;
this.store.stockSectionMode = 'stock-list'; this.store.stockSectionMode = 'stock-list';
}, },
-16
View File
@@ -43,13 +43,6 @@ export default defineComponent({
}, },
addLocomotive(loco: ILocomotive) { addLocomotive(loco: ILocomotive) {
// const previousStock =
// this.store.stockList.length > 0 ? this.store.stockList[this.store.stockList.length - 1] : null;
// if (previousStock && previousStock.type == loco.type) {
// this.store.stockList[this.store.stockList.length - 1].count++;
// return;
// }
const stockObj = this.getStockObject(loco); const stockObj = this.getStockObject(loco);
if (this.store.stockList.length > 0 && !this.store.stockList[0].isLoco) this.store.stockList.unshift(stockObj); if (this.store.stockList.length > 0 && !this.store.stockList[0].isLoco) this.store.stockList.unshift(stockObj);
@@ -57,15 +50,6 @@ export default defineComponent({
}, },
addCarWagon(car: ICarWagon, cargo?: ICargo) { addCarWagon(car: ICarWagon, cargo?: ICargo) {
// const previousStock =
// this.store.stockList.length > 0 ? this.store.stockList[this.store.stockList.length - 1] : null;
// if (previousStock && previousStock.type == car.type && previousStock.cargo?.id == cargo?.id) {
// this.store.stockList[this.store.stockList.length - 1].count++;
// return;
// }
const stockObj = this.getStockObject(car, cargo); const stockObj = this.getStockObject(car, cargo);
this.store.stockList.push(stockObj); this.store.stockList.push(stockObj);