From de5b622e6d022d53e44951becd7fb077d2a3a031 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20B=C3=B6ckelmann?= Date: Fri, 12 Apr 2024 14:54:04 +0200 Subject: [PATCH] Fix (hopefully) duplicate states inside generated gamesystems --- .../ProductStateGeneration.spec.ts | 1 - .../AbstractProductGamesystemGenerator.ts | 15 +++++------ .../ProductGamesystemGenerator.ts | 1 + .../ProductGamesystem/ProductGamesystem.json | 12 +++++++++ .../ProductGamesystem/SimpleGamesystem 1.json | 27 +++++++++++++++++++ .../ProductGamesystem/SimpleGamesystem 2.json | 27 +++++++++++++++++++ 6 files changed, 73 insertions(+), 10 deletions(-) create mode 100644 testModel/gamesystems/ProductGamesystem/ProductGamesystem.json create mode 100644 testModel/gamesystems/ProductGamesystem/SimpleGamesystem 1.json create mode 100644 testModel/gamesystems/ProductGamesystem/SimpleGamesystem 2.json diff --git a/e2e/game-model/gamesystems/productGamesystems/ProductStateGeneration.spec.ts b/e2e/game-model/gamesystems/productGamesystems/ProductStateGeneration.spec.ts index d1ae17a..2e6e2d7 100644 --- a/e2e/game-model/gamesystems/productGamesystems/ProductStateGeneration.spec.ts +++ b/e2e/game-model/gamesystems/productGamesystems/ProductStateGeneration.spec.ts @@ -5,7 +5,6 @@ test.describe('Test Create ProductStates', () => { test("Test simple Binary Product State", async () => { const gamesystem = ProductSystemGenerationTrainer.givenSimplestProductSystem(); gamesystem.generateFromChildsystems(); - expect(gamesystem.states.length).toEqual(4); expect(gamesystem.transitions.length).toEqual(5); }) diff --git a/src/app/project/game-model/gamesystems/productSystemGenerator/AbstractProductGamesystemGenerator.ts b/src/app/project/game-model/gamesystems/productSystemGenerator/AbstractProductGamesystemGenerator.ts index fe340a4..31bcbac 100644 --- a/src/app/project/game-model/gamesystems/productSystemGenerator/AbstractProductGamesystemGenerator.ts +++ b/src/app/project/game-model/gamesystems/productSystemGenerator/AbstractProductGamesystemGenerator.ts @@ -8,6 +8,7 @@ import {ProductGeneratorResult} from "./ProductGeneratorResult"; import {ProductState} from "../states/ProductState"; import {ProductTransition} from "../transitions/ProductTransition"; import {Transition} from "../transitions/Transition"; +import {state} from "@angular/animations"; export abstract class AbstractProductGamesystemGenerator { productGamesystem: ProductGamesystem @@ -23,7 +24,10 @@ export abstract class AbstractProductGamesystemGenerator { const rightInitialData = this.prepareChildsystemForGeneration(this.productGamesystem.innerGamesystems[1]) const initialGenerationResult = this.generateFromBinaryChildsystems(leftInitialData, rightInitialData); + console.log("Debug msg2") + if(this.productGamesystem.innerGamesystems.length > 2) { + console.log("Deeper construction") for(let i=2; i, rightState: State, generadedStates: ProductState[]): ProductState | undefined protected findGeneratedProductState(innerStates: State[], productStates: ProductState[]) { - return undefined + return productStates.find(productState => productState.equalInnerStates(innerStates)); } protected generateCombinedActions(leftActions: ScriptAccountAction[], rightActions: ScriptAccountAction[]): ScriptAccountAction[] { diff --git a/src/app/project/game-model/gamesystems/productSystemGenerator/ProductGamesystemGenerator.ts b/src/app/project/game-model/gamesystems/productSystemGenerator/ProductGamesystemGenerator.ts index 9823870..095777c 100644 --- a/src/app/project/game-model/gamesystems/productSystemGenerator/ProductGamesystemGenerator.ts +++ b/src/app/project/game-model/gamesystems/productSystemGenerator/ProductGamesystemGenerator.ts @@ -50,6 +50,7 @@ export class ProductGamesystemGenerator extends AbstractProductGamesystemGenerat let binaryProductState: ProductState | undefined = this.findGeneratedProductState(innerStates, generatedStates); if(binaryProductState == undefined) { binaryProductState = new ProductState(innerStates); + generatedStates.push(binaryProductState) } binaryProductState.determineInitialProperty() diff --git a/testModel/gamesystems/ProductGamesystem/ProductGamesystem.json b/testModel/gamesystems/ProductGamesystem/ProductGamesystem.json new file mode 100644 index 0000000..0897002 --- /dev/null +++ b/testModel/gamesystems/ProductGamesystem/ProductGamesystem.json @@ -0,0 +1,12 @@ +{ + "componentName": "ProductGamesystem", + "componentDescription": "", + "childsystems": [ + { + "componentName": "SimpleGamesystem 1" + }, + { + "componentName": "SimpleGamesystem 2" + } + ] +} \ No newline at end of file diff --git a/testModel/gamesystems/ProductGamesystem/SimpleGamesystem 1.json b/testModel/gamesystems/ProductGamesystem/SimpleGamesystem 1.json new file mode 100644 index 0000000..43a50cd --- /dev/null +++ b/testModel/gamesystems/ProductGamesystem/SimpleGamesystem 1.json @@ -0,0 +1,27 @@ +{ + "componentName": "SimpleGamesystem 1", + "componentDescription": "", + "states": [ + { + "initial": false, + "conditions": [], + "stateLabel": "A", + "stateDescription": "" + }, + { + "initial": false, + "conditions": [], + "stateLabel": "B", + "stateDescription": "" + } + ], + "transitions": [ + { + "scriptAccountActions": [], + "scriptAccountConditions": [], + "startingState": "A", + "endingState": "B" + } + ], + "templateType": 0 +} \ No newline at end of file diff --git a/testModel/gamesystems/ProductGamesystem/SimpleGamesystem 2.json b/testModel/gamesystems/ProductGamesystem/SimpleGamesystem 2.json new file mode 100644 index 0000000..9279f93 --- /dev/null +++ b/testModel/gamesystems/ProductGamesystem/SimpleGamesystem 2.json @@ -0,0 +1,27 @@ +{ + "componentName": "SimpleGamesystem 2", + "componentDescription": "", + "states": [ + { + "initial": false, + "conditions": [], + "stateLabel": "1", + "stateDescription": "" + }, + { + "initial": false, + "conditions": [], + "stateLabel": "2", + "stateDescription": "" + } + ], + "transitions": [ + { + "scriptAccountActions": [], + "scriptAccountConditions": [], + "startingState": "1", + "endingState": "2" + } + ], + "templateType": 0 +} \ No newline at end of file