Fix (hopefully) duplicate states inside generated gamesystems
Some checks failed
E2E Testing / test (push) Failing after 2m7s

This commit is contained in:
Sebastian Böckelmann 2024-04-12 14:54:04 +02:00
parent 2e66717ae4
commit de5b622e6d
6 changed files with 73 additions and 10 deletions

View File

@ -5,7 +5,6 @@ test.describe('Test Create ProductStates', () => {
test("Test simple Binary Product State", async () => { test("Test simple Binary Product State", async () => {
const gamesystem = ProductSystemGenerationTrainer.givenSimplestProductSystem(); const gamesystem = ProductSystemGenerationTrainer.givenSimplestProductSystem();
gamesystem.generateFromChildsystems(); gamesystem.generateFromChildsystems();
expect(gamesystem.states.length).toEqual(4); expect(gamesystem.states.length).toEqual(4);
expect(gamesystem.transitions.length).toEqual(5); expect(gamesystem.transitions.length).toEqual(5);
}) })

View File

@ -8,6 +8,7 @@ import {ProductGeneratorResult} from "./ProductGeneratorResult";
import {ProductState} from "../states/ProductState"; import {ProductState} from "../states/ProductState";
import {ProductTransition} from "../transitions/ProductTransition"; import {ProductTransition} from "../transitions/ProductTransition";
import {Transition} from "../transitions/Transition"; import {Transition} from "../transitions/Transition";
import {state} from "@angular/animations";
export abstract class AbstractProductGamesystemGenerator { export abstract class AbstractProductGamesystemGenerator {
productGamesystem: ProductGamesystem productGamesystem: ProductGamesystem
@ -23,7 +24,10 @@ export abstract class AbstractProductGamesystemGenerator {
const rightInitialData = this.prepareChildsystemForGeneration(this.productGamesystem.innerGamesystems[1]) const rightInitialData = this.prepareChildsystemForGeneration(this.productGamesystem.innerGamesystems[1])
const initialGenerationResult = this.generateFromBinaryChildsystems(leftInitialData, rightInitialData); const initialGenerationResult = this.generateFromBinaryChildsystems(leftInitialData, rightInitialData);
console.log("Debug msg2")
if(this.productGamesystem.innerGamesystems.length > 2) { if(this.productGamesystem.innerGamesystems.length > 2) {
console.log("Deeper construction")
for(let i=2; i<this.productGamesystem.innerGamesystems.length; i++) { for(let i=2; i<this.productGamesystem.innerGamesystems.length; i++) {
const leftData = initialGenerationResult.productGenerationData; const leftData = initialGenerationResult.productGenerationData;
const rightData = this.prepareChildsystemForGeneration(this.productGamesystem.innerGamesystems[i]); const rightData = this.prepareChildsystemForGeneration(this.productGamesystem.innerGamesystems[i]);
@ -33,6 +37,7 @@ export abstract class AbstractProductGamesystemGenerator {
this.productGamesystem.transitions = generationResult.transitions; this.productGamesystem.transitions = generationResult.transitions;
} }
} else { } else {
console.log("Simple construction ", initialGenerationResult.states)
this.productGamesystem.states = initialGenerationResult.states; this.productGamesystem.states = initialGenerationResult.states;
this.productGamesystem.transitions = initialGenerationResult.transitions this.productGamesystem.transitions = initialGenerationResult.transitions
} }
@ -57,26 +62,22 @@ export abstract class AbstractProductGamesystemGenerator {
const startingState = this.generateBinaryProductState(leftState, rightState, generatedProductStates); const startingState = this.generateBinaryProductState(leftState, rightState, generatedProductStates);
if(startingState != undefined) { if(startingState != undefined) {
generatedProductStates.push(startingState);
const endingState_right = this.generateBinaryProductState(leftState, rightState.outgoingTransitions[j].endingState, generatedProductStates); const endingState_right = this.generateBinaryProductState(leftState, rightState.outgoingTransitions[j].endingState, generatedProductStates);
if(endingState_right != undefined) { if(endingState_right != undefined) {
const transition_right = this.generateBinaryProductTransition(startingState, endingState_right, rightState.outgoingTransitions[j]) const transition_right = this.generateBinaryProductTransition(startingState, endingState_right, rightState.outgoingTransitions[j])
generatedProductTransitions.push(transition_right) generatedProductTransitions.push(transition_right)
generatedProductStates.push(endingState_right)
} }
const endingState_left = this.generateBinaryProductState(leftState.outgoingTransitions[i].endingState, rightState, generatedProductStates); const endingState_left = this.generateBinaryProductState(leftState.outgoingTransitions[i].endingState, rightState, generatedProductStates);
if(endingState_left != undefined) { if(endingState_left != undefined) {
const transition = this.generateBinaryProductTransition(startingState, endingState_left, leftState.outgoingTransitions[i]) const transition = this.generateBinaryProductTransition(startingState, endingState_left, leftState.outgoingTransitions[i])
generatedProductTransitions.push(transition) generatedProductTransitions.push(transition)
generatedProductStates.push(endingState_left)
} }
const endingState_left_right = this.generateBinaryProductState(leftState.outgoingTransitions[i].endingState, rightState.outgoingTransitions[j].endingState, generatedProductStates); const endingState_left_right = this.generateBinaryProductState(leftState.outgoingTransitions[i].endingState, rightState.outgoingTransitions[j].endingState, generatedProductStates);
if(endingState_left_right != undefined) { if(endingState_left_right != undefined) {
const transition = this.generateBinaryProductTransitionMulti(startingState, endingState_left_right, leftState.outgoingTransitions[i], rightState.outgoingTransitions[j]); const transition = this.generateBinaryProductTransitionMulti(startingState, endingState_left_right, leftState.outgoingTransitions[i], rightState.outgoingTransitions[j]);
if(transition != undefined) { if(transition != undefined) {
generatedProductStates.push(endingState_left_right);
generatedProductTransitions.push(transition); generatedProductTransitions.push(transition);
} }
} }
@ -88,8 +89,6 @@ export abstract class AbstractProductGamesystemGenerator {
const endingState = this.generateBinaryProductState(leftState.outgoingTransitions[i].endingState, rightState, generatedProductStates); const endingState = this.generateBinaryProductState(leftState.outgoingTransitions[i].endingState, rightState, generatedProductStates);
if(startingState != undefined && endingState != undefined) { if(startingState != undefined && endingState != undefined) {
generatedProductStates.push(startingState)
generatedProductStates.push(endingState)
const transition = this.generateBinaryProductTransition(startingState, endingState, leftState.outgoingTransitions[i]) const transition = this.generateBinaryProductTransition(startingState, endingState, leftState.outgoingTransitions[i])
generatedProductTransitions.push(transition) generatedProductTransitions.push(transition)
} }
@ -102,8 +101,6 @@ export abstract class AbstractProductGamesystemGenerator {
const endingState = this.generateBinaryProductState(leftState, rightState.outgoingTransitions[j].endingState, generatedProductStates); const endingState = this.generateBinaryProductState(leftState, rightState.outgoingTransitions[j].endingState, generatedProductStates);
if(startingState != undefined && endingState != undefined) { if(startingState != undefined && endingState != undefined) {
generatedProductStates.push(startingState)
generatedProductStates.push(endingState)
const transition = this.generateBinaryProductTransition(startingState, endingState, rightState.outgoingTransitions[j]); const transition = this.generateBinaryProductTransition(startingState, endingState, rightState.outgoingTransitions[j]);
generatedProductTransitions.push(transition) generatedProductTransitions.push(transition)
} }
@ -123,7 +120,7 @@ export abstract class AbstractProductGamesystemGenerator {
protected abstract generateBinaryProductState(leftState: State<any>, rightState: State<any>, generadedStates: ProductState[]): ProductState | undefined protected abstract generateBinaryProductState(leftState: State<any>, rightState: State<any>, generadedStates: ProductState[]): ProductState | undefined
protected findGeneratedProductState(innerStates: State<any>[], productStates: ProductState[]) { protected findGeneratedProductState(innerStates: State<any>[], productStates: ProductState[]) {
return undefined return productStates.find(productState => productState.equalInnerStates(innerStates));
} }
protected generateCombinedActions(leftActions: ScriptAccountAction[], rightActions: ScriptAccountAction[]): ScriptAccountAction[] { protected generateCombinedActions(leftActions: ScriptAccountAction[], rightActions: ScriptAccountAction[]): ScriptAccountAction[] {

View File

@ -50,6 +50,7 @@ export class ProductGamesystemGenerator extends AbstractProductGamesystemGenerat
let binaryProductState: ProductState | undefined = this.findGeneratedProductState(innerStates, generatedStates); let binaryProductState: ProductState | undefined = this.findGeneratedProductState(innerStates, generatedStates);
if(binaryProductState == undefined) { if(binaryProductState == undefined) {
binaryProductState = new ProductState(innerStates); binaryProductState = new ProductState(innerStates);
generatedStates.push(binaryProductState)
} }
binaryProductState.determineInitialProperty() binaryProductState.determineInitialProperty()

View File

@ -0,0 +1,12 @@
{
"componentName": "ProductGamesystem",
"componentDescription": "",
"childsystems": [
{
"componentName": "SimpleGamesystem 1"
},
{
"componentName": "SimpleGamesystem 2"
}
]
}

View File

@ -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
}

View File

@ -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
}