issue-5-product-gamesystems #10

Merged
sebastian merged 31 commits from issue-5-product-gamesystems into main 2024-02-16 18:00:29 +01:00
3 changed files with 29 additions and 6 deletions
Showing only changes of commit e2cfe97b61 - Show all commits

View File

@ -23,5 +23,12 @@ test.describe('Test Create ProductStates', () => {
expect(gamesystem.transitions.length).toEqual(5);
})
test("Test simple triple Product State", async () => {
const gamesystem = ProductSystemGenerationTrainer.givenTrippleProductSystem();
gamesystem.generateFromChildsystems();
expect(gamesystem.states.length).toEqual(8);
expect(gamesystem.transitions.length).toEqual(19)
})
});

View File

@ -6,12 +6,16 @@ export class ProductSystemGenerationTrainer {
static PRODUCTGAMESYSTEMNAME = "ProductGamesystem";
static CHILDGAMESYSTEMNAME_LEFT = "Left Child System";
static CHILDGAMESYSTEMNAME_RIGHT = "Right Child System";
static CHILDGAMESYSTEMNAME_MIDDLE = "Middle 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 MIDDLECHILDSYSTEM_A_NODE_NAME = "Sun";
static MIDDLECHILDSYSTEM_B_NODE_NAME = "Rain";
static givenSimplestProductSystem() {
const productsystem = new ProductGamesystem(ProductSystemGenerationTrainer.PRODUCTGAMESYSTEMNAME);
const left_childsystem = new SimpleGamesystem(ProductSystemGenerationTrainer.CHILDGAMESYSTEMNAME_LEFT);
@ -26,4 +30,14 @@ export class ProductSystemGenerationTrainer {
return productsystem;
}
static givenTrippleProductSystem() {
const gamesystem = this.givenSimplestProductSystem();
const middle_childsystem = new SimpleGamesystem(this.CHILDGAMESYSTEMNAME_MIDDLE);
middle_childsystem.createTransition(middle_childsystem.createState(ProductSystemGenerationTrainer.MIDDLECHILDSYSTEM_A_NODE_NAME, "")!,
middle_childsystem.createState(ProductSystemGenerationTrainer.MIDDLECHILDSYSTEM_B_NODE_NAME, "")!);
gamesystem.addChildGamesystem(middle_childsystem);
return gamesystem;
}
}

View File

@ -65,18 +65,21 @@ 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);
const integratedSystems: Gamesystem<any, any>[] = [this.innerGamesystems[0], this.innerGamesystems[1]];
let gamesystem: ProductGamesystem = ProductGamesystem.generateFromChildsystems(this.innerGamesystems[0], this.innerGamesystems[1], false, integratedSystems);
for(let i=2; i<this.innerGamesystems.length; i++) {
gamesystem = ProductGamesystem.generateFromChildsystems(gamesystem, this.innerGamesystems[i], true);
integratedSystems.push(this.innerGamesystems[i]);
gamesystem = ProductGamesystem.generateFromChildsystems(gamesystem, this.innerGamesystems[i], true, integratedSystems);
}
this.states = gamesystem.states;
this.transitions = gamesystem.transitions;
}
static generateFromChildsystems(leftSystem: Gamesystem<any, any>, rightSystem: Gamesystem<any, any>, left_temp: boolean) {
static generateFromChildsystems(leftSystem: Gamesystem<any, any>, rightSystem: Gamesystem<any, any>, left_temp: boolean, integratedSystems: Gamesystem<any, any>[]) {
const productGamesystem = new ProductGamesystem("Temporary Gamesystem");
productGamesystem.addChildGamesystem(leftSystem);
productGamesystem.addChildGamesystem(rightSystem);
integratedSystems.forEach(integratedSystem => productGamesystem.addChildGamesystem(integratedSystem));
leftSystem.states.forEach(leftState => {
rightSystem.states.forEach(rightState => {
for(let i=0; i<leftState.outgoingTransitions.length; i++) {
@ -106,7 +109,6 @@ export class ProductGamesystem extends Gamesystem<ProductState, ProductTransitio
const transition = productGamesystem.createTransition(startingState, endingState);
}
}
})
})
return productGamesystem;