isolated-state-generation #39

Merged
sebastian merged 7 commits from isolated-state-generation into assymetric-template-relation-systems 2024-04-19 20:03:10 +02:00
2 changed files with 57 additions and 0 deletions
Showing only changes of commit 3d9db9b143 - Show all commits

View File

@ -11,6 +11,7 @@ import {ScriptAccountAction} from "./actions/ScriptAccountAction";
import {ProductSystemGenerator} from "./productSystemGenerator/ProductSystemGenerator"; import {ProductSystemGenerator} from "./productSystemGenerator/ProductSystemGenerator";
import {TemplateType} from "../templates/TemplateType"; import {TemplateType} from "../templates/TemplateType";
import {ProductTemplateSystem} from "../templates/productGamesystem/ProductTemplateSystem"; import {ProductTemplateSystem} from "../templates/productGamesystem/ProductTemplateSystem";
import {IsolatedProductStateGenerator} from "./productSystemGenerator/IsolatedProductStateGenerator";
export class ProductGamesystem extends Gamesystem<ProductState, ProductTransition> { export class ProductGamesystem extends Gamesystem<ProductState, ProductTransition> {
@ -74,6 +75,9 @@ export class ProductGamesystem extends Gamesystem<ProductState, ProductTransitio
generateFromChildsystems() { generateFromChildsystems() {
const productGenerator = new ProductSystemGenerator(this); const productGenerator = new ProductSystemGenerator(this);
productGenerator.generateFromChildsystems(); productGenerator.generateFromChildsystems();
const isolatedStatesGenerator = new IsolatedProductStateGenerator(this);
isolatedStatesGenerator.generateIsolatedProductStates();
} }
addChildGamesystem(gamesystem: Gamesystem<State<any>, Transition<any>>) { addChildGamesystem(gamesystem: Gamesystem<State<any>, Transition<any>>) {

View File

@ -0,0 +1,53 @@
import {ProductSystemGenerator} from "./ProductSystemGenerator";
import {ProductGenerationData} from "./ProductGenerationData";
import {ProductGeneratorResult} from "./ProductGeneratorResult";
import {ProductState} from "../states/ProductState";
export class IsolatedProductStateGenerator extends ProductSystemGenerator {
generateIsolatedProductStates() {
if(this.productGamesystem.innerGamesystems.length < 2) return;
const leftInitialData = this.prepareChildsystemForGeneration(this.productGamesystem.innerGamesystems[0])
const rightInitialData = this.prepareChildsystemForGeneration(this.productGamesystem.innerGamesystems[1])
const initialGenerationResult = this.generateBinaryIsolatedProductStates(leftInitialData, rightInitialData);
if(this.productGamesystem.innerGamesystems.length > 2) {
for(let i=2; i<this.productGamesystem.innerGamesystems.length; i++) {
const leftData = initialGenerationResult.productGenerationData;
const rightData = this.prepareChildsystemForGeneration(this.productGamesystem.innerGamesystems[i]);
const generationResult = this.generateBinaryIsolatedProductStates(leftData, rightData);
this.assignGeneratedStatesAndTransitions(generationResult)
}
} else {
this.assignGeneratedStatesAndTransitions(initialGenerationResult)
}
}
protected assignGeneratedStatesAndTransitions(generationResult: ProductGeneratorResult) {
this.productGamesystem.states = generationResult.states;
}
generateBinaryIsolatedProductStates(leftSystemData: ProductGenerationData, rightSystemData: ProductGenerationData): ProductGeneratorResult {
const generatedProductStates: ProductState[] = []
leftSystemData.states.forEach(leftState => {
if(leftState.outgoingTransitions.length == 0 && leftState.incomingTransitions.length == 0) {
rightSystemData.states.forEach(rightState => {
if(rightState.outgoingTransitions.length == 0 && rightState.incomingTransitions.length == 0) {
const leftConditions = this.getStateConditions(leftState, true);
const rightConditions = this.getStateConditions(rightState, true);
if(!this.contradictCombinedConditions(leftConditions, rightConditions)) {
this.generateBinaryProductState(leftState, rightState, generatedProductStates);
}
}
})
}
})
return new ProductGeneratorResult(generatedProductStates, []);
}
}