From 2e66717ae44aaa833dfa8fda18f6a85ffd19eee7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20B=C3=B6ckelmann?= Date: Fri, 12 Apr 2024 14:27:50 +0200 Subject: [PATCH] Refactor ProductGamesystemGenerator to consider other alternative implementations of product systems --- .../AbstractProductGamesystemGenerator.ts | 174 +++++++++++++++- .../ProductGamesystemGenerator.ts | 191 ++---------------- 2 files changed, 186 insertions(+), 179 deletions(-) diff --git a/src/app/project/game-model/gamesystems/productSystemGenerator/AbstractProductGamesystemGenerator.ts b/src/app/project/game-model/gamesystems/productSystemGenerator/AbstractProductGamesystemGenerator.ts index 495f0f1..fe340a4 100644 --- a/src/app/project/game-model/gamesystems/productSystemGenerator/AbstractProductGamesystemGenerator.ts +++ b/src/app/project/game-model/gamesystems/productSystemGenerator/AbstractProductGamesystemGenerator.ts @@ -3,21 +3,181 @@ import {ScriptAccountAction} from "../actions/ScriptAccountAction"; import {ScriptAccountCondition} from "../conditions/ScriptAccountCondition"; import {State} from "../states/State"; import {ProductGamesystem} from "../ProductGamesystem"; +import {ProductGenerationData} from "./ProductGenerationData"; +import {ProductGeneratorResult} from "./ProductGeneratorResult"; +import {ProductState} from "../states/ProductState"; +import {ProductTransition} from "../transitions/ProductTransition"; +import {Transition} from "../transitions/Transition"; export abstract class AbstractProductGamesystemGenerator { - - protected integratedSystems: Gamesystem[] = [] + productGamesystem: ProductGamesystem - prepare() { - this.integratedSystems = [] + constructor(productGamesystem: ProductGamesystem) { + this.productGamesystem = productGamesystem; } - abstract generateFromChildsystems(ProductGamesystem: ProductGamesystem): void; + generateFromChildsystems(): void { + if(this.productGamesystem.innerGamesystems.length < 2) return; + const leftInitialData = this.prepareChildsystemForGeneration(this.productGamesystem.innerGamesystems[0]) + const rightInitialData = this.prepareChildsystemForGeneration(this.productGamesystem.innerGamesystems[1]) - abstract generateFromBinaryChildsystems(leftSystem: Gamesystem, rightSystem: any, left_temp: boolean): void; + const initialGenerationResult = this.generateFromBinaryChildsystems(leftInitialData, rightInitialData); + if(this.productGamesystem.innerGamesystems.length > 2) { + for(let i=2; i, rightInnerState: State, left_temp: boolean): State; + const generationResult = this.generateFromBinaryChildsystems(leftData, rightData); + this.productGamesystem.states = generationResult.states; + this.productGamesystem.transitions = generationResult.transitions; + } + } else { + this.productGamesystem.states = initialGenerationResult.states; + this.productGamesystem.transitions = initialGenerationResult.transitions + } + } + protected prepareChildsystemForGeneration(childsystem: Gamesystem) { + if(childsystem instanceof ProductGamesystem) { + childsystem.productGamesystemGenerator.generateFromChildsystems(); + } + + return new ProductGenerationData(childsystem.states, childsystem.transitions) + } + + protected generateFromBinaryChildsystems(leftSystemData: ProductGenerationData, rightSystemData: ProductGenerationData): ProductGeneratorResult { + const generatedProductStates: ProductState[] = [] + const generatedProductTransitions: ProductTransition[] = [] + + leftSystemData.states.forEach(leftState => { + rightSystemData.states.forEach(rightState => { + for(let i=0; i, rightState: State, usedTransition: Transition): ProductTransition; + + protected abstract generateBinaryProductTransitionMulti(leftState: State, rightState: State, leftTransition: Transition, rightTransition: Transition): ProductTransition | undefined + + protected abstract generateBinaryProductState(leftState: State, rightState: State, generadedStates: ProductState[]): ProductState | undefined + + protected findGeneratedProductState(innerStates: State[], productStates: ProductState[]) { + return undefined + } + + protected generateCombinedActions(leftActions: ScriptAccountAction[], rightActions: ScriptAccountAction[]): ScriptAccountAction[] { + const combinedActions: ScriptAccountAction[] = [] + for(let i=0; i 2) { - for(let i=2; i) { - if(childsystem instanceof ProductGamesystem) { - childsystem.productGamesystemGenerator.generateFromChildsystems(); - } - - return new ProductGenerationData(childsystem.states, childsystem.transitions) - } - - private generateFromBinaryChildsystems(leftSystemData: ProductGenerationData, rightSystemData: ProductGenerationData): ProductGeneratorResult { - const generatedProductStates: ProductState[] = [] - const generatedProductTransitions: ProductTransition[] = [] - - leftSystemData.states.forEach(leftState => { - rightSystemData.states.forEach(rightState => { - for(let i=0; i) { + protected generateBinaryProductTransition(startingState: ProductState, endingState: ProductState, usedTransition: Transition) { const transition = new ProductTransition(startingState, endingState); transition.scriptAccountActions = [... usedTransition.scriptAccountActions]; transition.scriptAccountConditions = [... usedTransition.scriptAccountConditions]; @@ -133,7 +21,22 @@ export class ProductGamesystemGenerator { return transition; } - private generateBinaryProductState(leftState: State, rightState: State, generatedStates: ProductState[]): ProductState | undefined { + protected generateBinaryProductTransitionMulti(startingState: ProductState, endingState: ProductState, leftTransition: Transition, rightTransition: Transition) { + const leftConditions = leftTransition.scriptAccountConditions; + const rightConditions = rightTransition.scriptAccountConditions; + + if(!this.contradictCombinedConditions(leftConditions, rightConditions)) { + const transition = new ProductTransition(startingState, endingState) + transition.scriptAccountActions = this.generateCombinedActions(leftTransition.scriptAccountActions, rightTransition.scriptAccountActions); + transition.scriptAccountConditions = this.generateCombinedConditions(leftTransition.scriptAccountConditions, rightTransition.scriptAccountConditions); + + return transition; + } + + return undefined; + } + + protected generateBinaryProductState(leftState: State, rightState: State, generatedStates: ProductState[]): ProductState | undefined { const combinedStateConditions: ScriptAccountCondition[] = leftState.conditions.concat(rightState.conditions); for(let i=0; i[], productStates: ProductState[]) { - return undefined - } - private generateCombinedActions(leftActions: ScriptAccountAction[], rightActions: ScriptAccountAction[]): ScriptAccountAction[] { - const combinedActions: ScriptAccountAction[] = [] - for(let i=0; i