From 311b7ee7bb6b0b4b9815ef608d98380a09ca6bd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20B=C3=B6ckelmann?= Date: Sun, 11 Feb 2024 18:21:08 +0100 Subject: [PATCH] Generate ProductGamesystems --- .../ProductStateGeneration.spec.ts | 27 +++++++ .../ProductSystemGenerationTrainer.ts | 29 ++++++++ .../gamesystems/ProductGamesystem.ts | 70 +++++++++++++++++++ 3 files changed, 126 insertions(+) create mode 100644 e2e/game-model/gamesystems/productGamesystems/ProductStateGeneration.spec.ts create mode 100644 e2e/game-model/gamesystems/productGamesystems/ProductSystemGenerationTrainer.ts diff --git a/e2e/game-model/gamesystems/productGamesystems/ProductStateGeneration.spec.ts b/e2e/game-model/gamesystems/productGamesystems/ProductStateGeneration.spec.ts new file mode 100644 index 0000000..77f7c29 --- /dev/null +++ b/e2e/game-model/gamesystems/productGamesystems/ProductStateGeneration.spec.ts @@ -0,0 +1,27 @@ +import { BrowserContext, ElectronApplication, Page, _electron as electron } from 'playwright'; +import { test, expect } from '@playwright/test'; +import * as PATH from 'path'; +import {GameModel} from "../../../src/app/game-model/GameModel"; +import {Gamesystem} from "../../src/app/game-model/gamesystems/Gamesystem"; +import {ScriptAccount} from "../../../src/app/game-model/scriptAccounts/ScriptAccount"; +import {ModelComponentType} from "../../../src/app/game-model/ModelComponentType"; +import {SimpleGamesystem} from "../../../src/app/game-model/gamesystems/SimpleGamesystem"; +import exp = require("node:constants"); +import {end} from "electron-debug"; +import {GamesystemTrainer} from "./GamesystemTrainer"; +import {ProductGamesystem} from "../../../src/app/game-model/gamesystems/ProductGamesystem"; +import {ProductStateTrainer} from "./ProductStateTrainer"; +import {SimpleState} from "../../../../src/app/game-model/gamesystems/SimpleState"; +import {ProductSystemGenerationTrainer} from "./ProductSystemGenerationTrainer"; +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/e2e/game-model/gamesystems/productGamesystems/ProductSystemGenerationTrainer.ts b/e2e/game-model/gamesystems/productGamesystems/ProductSystemGenerationTrainer.ts new file mode 100644 index 0000000..f847f9a --- /dev/null +++ b/e2e/game-model/gamesystems/productGamesystems/ProductSystemGenerationTrainer.ts @@ -0,0 +1,29 @@ +import {ProductGamesystem} from "../../../../src/app/game-model/gamesystems/ProductGamesystem"; +import {SimpleGamesystem} from "../../../../src/app/game-model/gamesystems/SimpleGamesystem"; + +export class ProductSystemGenerationTrainer { + + static PRODUCTGAMESYSTEMNAME = "ProductGamesystem"; + static CHILDGAMESYSTEMNAME_LEFT = "Left Child System"; + static CHILDGAMESYSTEMNAME_RIGHT = "Right Child System"; + + static LEFTCHILDSYSTEM_A_NODE_NAME = "A"; + static LEFTCHILDSYSTEM_B_NODE_NAME = "B"; + + static RIGHTCHILDSYSTEM_A_NODE_NAME = "1"; + static RIGHTCHILDSYSTEM_B_NODE_NAME = "2"; + static givenSimplestProductSystem() { + const productsystem = new ProductGamesystem(ProductSystemGenerationTrainer.PRODUCTGAMESYSTEMNAME); + const left_childsystem = new SimpleGamesystem(ProductSystemGenerationTrainer.CHILDGAMESYSTEMNAME_LEFT); + const right_childsystem = new SimpleGamesystem(ProductSystemGenerationTrainer.CHILDGAMESYSTEMNAME_RIGHT); + + left_childsystem.createTransition(left_childsystem.createState(ProductSystemGenerationTrainer.LEFTCHILDSYSTEM_A_NODE_NAME, "")!, + left_childsystem.createState(ProductSystemGenerationTrainer.LEFTCHILDSYSTEM_B_NODE_NAME, "")!); + right_childsystem.createTransition(right_childsystem.createState(ProductSystemGenerationTrainer.RIGHTCHILDSYSTEM_A_NODE_NAME, "")!, + right_childsystem.createState(ProductSystemGenerationTrainer.RIGHTCHILDSYSTEM_B_NODE_NAME, "")!); + productsystem.addChildGamesystem(left_childsystem); + productsystem.addChildGamesystem(right_childsystem); + + return productsystem; + } +} diff --git a/src/app/game-model/gamesystems/ProductGamesystem.ts b/src/app/game-model/gamesystems/ProductGamesystem.ts index 0c8c30c..11583f3 100644 --- a/src/app/game-model/gamesystems/ProductGamesystem.ts +++ b/src/app/game-model/gamesystems/ProductGamesystem.ts @@ -63,6 +63,76 @@ export class ProductGamesystem extends Gamesystem, rightSystem: Gamesystem, left_temp: boolean) { + const productGamesystem = new ProductGamesystem("Temporary Gamesystem"); + productGamesystem.addChildGamesystem(leftSystem); + productGamesystem.addChildGamesystem(rightSystem); + leftSystem.states.forEach(leftState => { + rightSystem.states.forEach(rightState => { + for(let i=0; i, rightInnerState: State, left_temp: boolean) { + let innerStates: State[] = []; + if(!left_temp) { + innerStates = [leftInnerState, rightInnerState]; + } else { + const left_inner_product_state = leftInnerState as ProductState; + left_inner_product_state.innerStates.forEach(state => innerStates.push(state)); + innerStates.push(rightInnerState); + } + + + const binary_productState = this.findProductStateByInnerStates(innerStates); + if(binary_productState == undefined) { + return this.createState(innerStates)!; + } else { + return binary_productState!; + } + } + + + addChildGamesystem(gamesystem: Gamesystem, Transition>) { this.innerGamesystems.push(gamesystem);