This commit is contained in:
parent
57d7babf71
commit
311b7ee7bb
@ -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);
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
});
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
@ -63,6 +63,76 @@ export class ProductGamesystem extends Gamesystem<ProductState, ProductTransitio
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
generateFromChildsystems() {
|
||||||
|
//Assume that childsystems that are productsystems are already generated
|
||||||
|
let gamesystem: ProductGamesystem = ProductGamesystem.generateFromChildsystems(this.innerGamesystems[0], this.innerGamesystems[1], false);
|
||||||
|
for(let i=2; i<this.innerGamesystems.length; i++) {
|
||||||
|
gamesystem = ProductGamesystem.generateFromChildsystems(gamesystem, this.innerGamesystems[i], true);
|
||||||
|
}
|
||||||
|
this.states = gamesystem.states;
|
||||||
|
this.transitions = gamesystem.transitions;
|
||||||
|
}
|
||||||
|
|
||||||
|
static generateFromChildsystems(leftSystem: Gamesystem<any, any>, rightSystem: Gamesystem<any, any>, 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<leftState.outgoingTransitions.length; i++) {
|
||||||
|
for(let j=0; j<rightState.outgoingTransitions.length; j++) {
|
||||||
|
const startingState = productGamesystem.generateBinaryProductState(leftState, rightState, left_temp);
|
||||||
|
const endingState_right = productGamesystem.generateBinaryProductState(leftState, rightState.outgoingTransitions[j].endingState, left_temp);
|
||||||
|
const transition_right = productGamesystem.createTransition(startingState, endingState_right)!;
|
||||||
|
|
||||||
|
const endingState_left = productGamesystem.generateBinaryProductState(leftState.outgoingTransitions[i].endingState, rightState, left_temp);
|
||||||
|
const transition_left = productGamesystem.createTransition(startingState, endingState_left)!;
|
||||||
|
|
||||||
|
const endingState_left_right = productGamesystem.generateBinaryProductState(leftState.outgoingTransitions[i].endingState, rightState.outgoingTransitions[j].endingState, left_temp);
|
||||||
|
const transition_left_right = productGamesystem.createTransition(startingState, endingState_left_right)!;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(rightState.outgoingTransitions.length == 0) {
|
||||||
|
const startingState = productGamesystem.generateBinaryProductState(leftState, rightState, left_temp);
|
||||||
|
const endingState = productGamesystem.generateBinaryProductState(leftState.outgoingTransitions[i].endingState, rightState, left_temp);
|
||||||
|
const transition = productGamesystem.createTransition(startingState, endingState);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(leftState.outgoingTransitions.length == 0) {
|
||||||
|
for(let j=0; j<rightState.outgoingTransitions.length; j++) {
|
||||||
|
const startingState = productGamesystem.generateBinaryProductState(leftState, rightState, left_temp);
|
||||||
|
const endingState = productGamesystem.generateBinaryProductState(leftState, rightState.outgoingTransitions[j].endingState, left_temp);
|
||||||
|
const transition = productGamesystem.createTransition(startingState, endingState);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
})
|
||||||
|
})
|
||||||
|
return productGamesystem;
|
||||||
|
}
|
||||||
|
|
||||||
|
generateBinaryProductState(leftInnerState: State<any>, rightInnerState: State<any>, left_temp: boolean) {
|
||||||
|
let innerStates: State<any>[] = [];
|
||||||
|
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<State<any>, Transition<any>>) {
|
addChildGamesystem(gamesystem: Gamesystem<State<any>, Transition<any>>) {
|
||||||
this.innerGamesystems.push(gamesystem);
|
this.innerGamesystems.push(gamesystem);
|
||||||
|
Loading…
Reference in New Issue
Block a user