template-systems #41
@ -0,0 +1,34 @@
|
||||
import {TemplateProductSystemGenerator} from "./TemplateProductSystemGenerator";
|
||||
import {ProductGenerationData} from "./ProductGenerationData";
|
||||
import {ProductGeneratorResult} from "./ProductGeneratorResult";
|
||||
import {ProductState} from "../states/ProductState";
|
||||
import {ProductTransition} from "../transitions/ProductTransition";
|
||||
import {ProductTemplateSystem} from "../../templates/productGamesystem/ProductTemplateSystem";
|
||||
|
||||
export class SymmetricProductTemplateGenerator extends TemplateProductSystemGenerator {
|
||||
protected generateFromBinaryChildsystems(leftSystemData: ProductGenerationData, rightSystemData: ProductGenerationData): ProductGeneratorResult {
|
||||
const generatedProductStates: ProductState[] = []
|
||||
const generatedProductTransitions: ProductTransition[] = []
|
||||
|
||||
leftSystemData.states.forEach(leftState => {
|
||||
rightSystemData.states.forEach(rightState => {
|
||||
if(leftState.equals(rightState)) {
|
||||
for(let i=0; i<leftState.outgoingTransitions.length; i++) {
|
||||
for(let j=0; j<rightState.outgoingTransitions.length; j++) {
|
||||
const startingState = this.generateBinaryProductState(leftState, rightState, generatedProductStates);
|
||||
if(startingState != undefined && leftState.outgoingTransitions[i].endingState.equals(rightState.outgoingTransitions[j].endingState)) {
|
||||
const endingState_left_right = this.generateBinaryProductState(leftState.outgoingTransitions[i].endingState, rightState.outgoingTransitions[j].endingState, generatedProductStates);
|
||||
if(endingState_left_right != undefined) {
|
||||
this.generateBinaryProductTransitionMulti(startingState, endingState_left_right, leftState.outgoingTransitions[i], rightState.outgoingTransitions[j], generatedProductTransitions);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
return new ProductGeneratorResult(generatedProductStates, generatedProductTransitions);
|
||||
}
|
||||
|
||||
}
|
@ -33,75 +33,6 @@ export class TemplateProductSystemGenerator extends ProductSystemGenerator {
|
||||
console.log("Template: ", generationResult.transitions.length)
|
||||
}
|
||||
|
||||
protected generateFromBinaryChildsystems(leftSystemData: ProductGenerationData, rightSystemData: ProductGenerationData): ProductGeneratorResult {
|
||||
const generatedProductStates: ProductState[] = []
|
||||
const generatedProductTransitions: ProductTransition[] = []
|
||||
|
||||
leftSystemData.states.forEach(leftState => {
|
||||
rightSystemData.states.forEach(rightState => {
|
||||
for(let i=0; i<leftState.outgoingTransitions.length; i++) {
|
||||
for(let j=0; j<rightState.outgoingTransitions.length; j++) {
|
||||
const startingState = this.generateBinaryProductState(leftState, rightState, generatedProductStates);
|
||||
|
||||
if(startingState != undefined) {
|
||||
|
||||
if(!(this.productGamesystem as ProductTemplateSystem).symmetric) {
|
||||
const endingState_right = this.generateBinaryProductState(leftState, rightState.outgoingTransitions[j].endingState, generatedProductStates);
|
||||
if(endingState_right != undefined) {
|
||||
this.generateBinaryProductTransition(startingState, endingState_right, rightState.outgoingTransitions[j], generatedProductTransitions, false);
|
||||
}
|
||||
|
||||
const endingState_left = this.generateBinaryProductState(leftState.outgoingTransitions[i].endingState, rightState, generatedProductStates);
|
||||
if(endingState_left != undefined) {
|
||||
this.generateBinaryProductTransition(startingState, endingState_left, leftState.outgoingTransitions[i], generatedProductTransitions, true)
|
||||
}
|
||||
}
|
||||
|
||||
const endingState_left_right = this.generateBinaryProductState(leftState.outgoingTransitions[i].endingState, rightState.outgoingTransitions[j].endingState, generatedProductStates);
|
||||
if(endingState_left_right != undefined) {
|
||||
if((this.productGamesystem as ProductTemplateSystem).symmetric) {
|
||||
if(leftState.equals(rightState) && leftState.outgoingTransitions[i].endingState.equals(rightState.outgoingTransitions[j].endingState)) {
|
||||
this.generateBinaryProductTransitionMulti(startingState, endingState_left_right, leftState.outgoingTransitions[i], rightState.outgoingTransitions[j], generatedProductTransitions);
|
||||
} else {
|
||||
console.log(startingState , endingState_left_right)
|
||||
}
|
||||
} else {
|
||||
this.generateBinaryProductTransitionMulti(startingState, endingState_left_right, leftState.outgoingTransitions[i], rightState.outgoingTransitions[j], generatedProductTransitions);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(rightState.outgoingTransitions.length == 0 && !(this.productGamesystem as ProductTemplateSystem).symmetric) {
|
||||
const startingState = this.generateBinaryProductState(leftState, rightState, generatedProductStates);
|
||||
const endingState = this.generateBinaryProductState(leftState.outgoingTransitions[i].endingState, rightState, generatedProductStates);
|
||||
|
||||
if(startingState != undefined && endingState != undefined) {
|
||||
this.generateBinaryProductTransition(startingState, endingState, leftState.outgoingTransitions[i], generatedProductTransitions, true)
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(leftState.outgoingTransitions.length == 0 && !(this.productGamesystem as ProductTemplateSystem).symmetric) {
|
||||
for(let j=0; j<rightState.outgoingTransitions.length; j++) {
|
||||
const startingState = this.generateBinaryProductState(leftState, rightState, generatedProductStates);
|
||||
const endingState = this.generateBinaryProductState(leftState, rightState.outgoingTransitions[j].endingState, generatedProductStates);
|
||||
|
||||
if(startingState != undefined && endingState != undefined) {
|
||||
this.generateBinaryProductTransition(startingState, endingState, rightState.outgoingTransitions[j], generatedProductTransitions, false);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
return new ProductGeneratorResult(generatedProductStates, generatedProductTransitions);
|
||||
}
|
||||
|
||||
protected getTransitionConditions(transition: Transition<any>, leftSystem: boolean) {
|
||||
const templateElement = this.determineTemplateElement(leftSystem)!;
|
||||
if(transition instanceof SimpleTemplateTransition && transition.conditionMap.has(templateElement)) {
|
||||
|
@ -7,6 +7,9 @@ import {SimpleGamesystem} from "../../gamesystems/SimpleGamesystem";
|
||||
import {GameModel} from "../../GameModel";
|
||||
import {TemplateType} from "../TemplateType";
|
||||
import {TemplateProductSystemGenerator} from "../../gamesystems/productSystemGenerator/TemplateProductSystemGenerator";
|
||||
import {
|
||||
SymmetricProductTemplateGenerator
|
||||
} from "../../gamesystems/productSystemGenerator/SymmetricProductTemplateGenerator";
|
||||
|
||||
export class ProductTemplateSystem extends ProductGamesystem implements TemplateGamesystem{
|
||||
|
||||
@ -22,8 +25,14 @@ export class ProductTemplateSystem extends ProductGamesystem implements Template
|
||||
}
|
||||
|
||||
addTemplateElement(templateElement: TemplateElement): void {
|
||||
if(this.symmetric) {
|
||||
const symmetricGenerator = new SymmetricProductTemplateGenerator(this, templateElement);
|
||||
symmetricGenerator.generateFromChildsystems()
|
||||
} else {
|
||||
const productTemplateGenerator = new TemplateProductSystemGenerator(this, templateElement);
|
||||
productTemplateGenerator.generateFromChildsystems()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user