From 9c20f169c671104e548629a68da67e126705d38a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20B=C3=B6ckelmann?= Date: Fri, 12 Apr 2024 18:28:52 +0200 Subject: [PATCH] Fix (hopefully) duplicate transitions inside generated gamesystems --- .../AbstractProductGamesystemGenerator.ts | 23 ++++++++----------- .../ProductGamesystemGenerator.ts | 8 ++++--- .../gamesystems/transitions/Transition.ts | 4 ++++ 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/src/app/project/game-model/gamesystems/productSystemGenerator/AbstractProductGamesystemGenerator.ts b/src/app/project/game-model/gamesystems/productSystemGenerator/AbstractProductGamesystemGenerator.ts index 31bcbac..4278ed5 100644 --- a/src/app/project/game-model/gamesystems/productSystemGenerator/AbstractProductGamesystemGenerator.ts +++ b/src/app/project/game-model/gamesystems/productSystemGenerator/AbstractProductGamesystemGenerator.ts @@ -64,22 +64,17 @@ export abstract class AbstractProductGamesystemGenerator { if(startingState != undefined) { const endingState_right = this.generateBinaryProductState(leftState, rightState.outgoingTransitions[j].endingState, generatedProductStates); if(endingState_right != undefined) { - const transition_right = this.generateBinaryProductTransition(startingState, endingState_right, rightState.outgoingTransitions[j]) - generatedProductTransitions.push(transition_right) + this.generateBinaryProductTransition(startingState, endingState_right, rightState.outgoingTransitions[j], generatedProductTransitions); } const endingState_left = this.generateBinaryProductState(leftState.outgoingTransitions[i].endingState, rightState, generatedProductStates); if(endingState_left != undefined) { - const transition = this.generateBinaryProductTransition(startingState, endingState_left, leftState.outgoingTransitions[i]) - generatedProductTransitions.push(transition) + this.generateBinaryProductTransition(startingState, endingState_left, leftState.outgoingTransitions[i], generatedProductTransitions) } const endingState_left_right = this.generateBinaryProductState(leftState.outgoingTransitions[i].endingState, rightState.outgoingTransitions[j].endingState, generatedProductStates); if(endingState_left_right != undefined) { - const transition = this.generateBinaryProductTransitionMulti(startingState, endingState_left_right, leftState.outgoingTransitions[i], rightState.outgoingTransitions[j]); - if(transition != undefined) { - generatedProductTransitions.push(transition); - } + this.generateBinaryProductTransitionMulti(startingState, endingState_left_right, leftState.outgoingTransitions[i], rightState.outgoingTransitions[j], generatedProductTransitions); } } } @@ -89,8 +84,8 @@ export abstract class AbstractProductGamesystemGenerator { const endingState = this.generateBinaryProductState(leftState.outgoingTransitions[i].endingState, rightState, generatedProductStates); if(startingState != undefined && endingState != undefined) { - const transition = this.generateBinaryProductTransition(startingState, endingState, leftState.outgoingTransitions[i]) - generatedProductTransitions.push(transition) + this.generateBinaryProductTransition(startingState, endingState, leftState.outgoingTransitions[i], generatedProductTransitions) + } } } @@ -101,8 +96,8 @@ export abstract class AbstractProductGamesystemGenerator { const endingState = this.generateBinaryProductState(leftState, rightState.outgoingTransitions[j].endingState, generatedProductStates); if(startingState != undefined && endingState != undefined) { - const transition = this.generateBinaryProductTransition(startingState, endingState, rightState.outgoingTransitions[j]); - generatedProductTransitions.push(transition) + this.generateBinaryProductTransition(startingState, endingState, rightState.outgoingTransitions[j], generatedProductTransitions); + } } @@ -113,9 +108,9 @@ export abstract class AbstractProductGamesystemGenerator { return new ProductGeneratorResult(generatedProductStates, generatedProductTransitions); } - protected abstract generateBinaryProductTransition(leftState: State, rightState: State, usedTransition: Transition): ProductTransition; + protected abstract generateBinaryProductTransition(leftState: State, rightState: State, usedTransition: Transition, generatedTransitions: ProductTransition[]): void; - protected abstract generateBinaryProductTransitionMulti(leftState: State, rightState: State, leftTransition: Transition, rightTransition: Transition): ProductTransition | undefined + protected abstract generateBinaryProductTransitionMulti(leftState: State, rightState: State, leftTransition: Transition, rightTransition: Transition, generatedTransitions: ProductTransition[]): void protected abstract generateBinaryProductState(leftState: State, rightState: State, generadedStates: ProductState[]): ProductState | undefined diff --git a/src/app/project/game-model/gamesystems/productSystemGenerator/ProductGamesystemGenerator.ts b/src/app/project/game-model/gamesystems/productSystemGenerator/ProductGamesystemGenerator.ts index 095777c..a5a16cf 100644 --- a/src/app/project/game-model/gamesystems/productSystemGenerator/ProductGamesystemGenerator.ts +++ b/src/app/project/game-model/gamesystems/productSystemGenerator/ProductGamesystemGenerator.ts @@ -13,15 +13,17 @@ import {AbstractProductGamesystemGenerator} from "./AbstractProductGamesystemGen export class ProductGamesystemGenerator extends AbstractProductGamesystemGenerator{ - protected generateBinaryProductTransition(startingState: ProductState, endingState: ProductState, usedTransition: Transition) { + protected generateBinaryProductTransition(startingState: ProductState, endingState: ProductState, usedTransition: Transition, generatedTransitions: ProductTransition[]) { const transition = new ProductTransition(startingState, endingState); transition.scriptAccountActions = [... usedTransition.scriptAccountActions]; transition.scriptAccountConditions = [... usedTransition.scriptAccountConditions]; - return transition; + if(generatedTransitions.find(generatedTransition => generatedTransition.equalsTransition(transition)) == undefined) { + generatedTransitions.push(transition) + } } - protected generateBinaryProductTransitionMulti(startingState: ProductState, endingState: ProductState, leftTransition: Transition, rightTransition: Transition) { + protected generateBinaryProductTransitionMulti(startingState: ProductState, endingState: ProductState, leftTransition: Transition, rightTransition: Transition, generatedTransitions: ProductTransition[]) { const leftConditions = leftTransition.scriptAccountConditions; const rightConditions = rightTransition.scriptAccountConditions; diff --git a/src/app/project/game-model/gamesystems/transitions/Transition.ts b/src/app/project/game-model/gamesystems/transitions/Transition.ts index e4a5e39..292e10b 100644 --- a/src/app/project/game-model/gamesystems/transitions/Transition.ts +++ b/src/app/project/game-model/gamesystems/transitions/Transition.ts @@ -57,4 +57,8 @@ export abstract class Transition> { findScriptAccountConditionByScriptAccount(scriptAccount: ScriptAccount): ScriptAccountCondition | undefined { return this.scriptAccountConditions.find(condition => condition.scriptAccount === scriptAccount); } + + equalsTransition(transition: Transition): boolean { + return this.startingState.equals(transition.startingState) && this.endingState.equals(transition.endingState) + } }