Consider Transition Conditions and Transition Actions while generating ProductTransitions
All checks were successful
E2E Testing / test (push) Successful in 1m35s
All checks were successful
E2E Testing / test (push) Successful in 1m35s
This commit is contained in:
parent
530cc5ea67
commit
7bb992200f
@ -8,6 +8,7 @@ import {SimpleGamesystem} from "./SimpleGamesystem";
|
|||||||
import {GameModel} from "../GameModel";
|
import {GameModel} from "../GameModel";
|
||||||
import {ProductStateTrainer} from "../../../../e2e/game-model/gamesystems/productGamesystems/ProductStateTrainer";
|
import {ProductStateTrainer} from "../../../../e2e/game-model/gamesystems/productGamesystems/ProductStateTrainer";
|
||||||
import {ScriptAccountCondition} from "./conditions/ScriptAccountCondition";
|
import {ScriptAccountCondition} from "./conditions/ScriptAccountCondition";
|
||||||
|
import {ScriptAccountAction} from "./actions/ScriptAccountAction";
|
||||||
|
|
||||||
export class ProductGamesystem extends Gamesystem<ProductState, ProductTransition> {
|
export class ProductGamesystem extends Gamesystem<ProductState, ProductTransition> {
|
||||||
|
|
||||||
@ -104,18 +105,36 @@ export class ProductGamesystem extends Gamesystem<ProductState, ProductTransitio
|
|||||||
if(startingState != undefined) {
|
if(startingState != undefined) {
|
||||||
const endingState_right = productGamesystem.generateBinaryProductState(leftState, rightState.outgoingTransitions[j].endingState, left_temp);
|
const endingState_right = productGamesystem.generateBinaryProductState(leftState, rightState.outgoingTransitions[j].endingState, left_temp);
|
||||||
if(endingState_right != undefined) {
|
if(endingState_right != undefined) {
|
||||||
const transition_right = productGamesystem.createTransition(startingState, endingState_right)!;
|
const transition_right = productGamesystem.createTransition(startingState, endingState_right);
|
||||||
|
if(transition_right != undefined) {
|
||||||
|
transition_right.scriptAccountActions = [...rightState.outgoingTransitions[j].scriptAccountActions]
|
||||||
|
transition_right.scriptAccountConditions = [... rightState.outgoingTransitions[j].scriptAccountConditions]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const endingState_left = productGamesystem.generateBinaryProductState(leftState.outgoingTransitions[i].endingState, rightState, left_temp);
|
const endingState_left = productGamesystem.generateBinaryProductState(leftState.outgoingTransitions[i].endingState, rightState, left_temp);
|
||||||
if(endingState_left != undefined) {
|
if(endingState_left != undefined) {
|
||||||
const transition_left = productGamesystem.createTransition(startingState, endingState_left)!;
|
const transition_left = productGamesystem.createTransition(startingState, endingState_left);
|
||||||
|
if(transition_left != undefined) {
|
||||||
|
transition_left.scriptAccountActions = [... leftState.outgoingTransitions[i].scriptAccountActions]
|
||||||
|
transition_left.scriptAccountConditions = [...leftState.outgoingTransitions[i].scriptAccountConditions]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const endingState_left_right = productGamesystem.generateBinaryProductState(leftState.outgoingTransitions[i].endingState, rightState.outgoingTransitions[j].endingState, left_temp);
|
const endingState_left_right = productGamesystem.generateBinaryProductState(leftState.outgoingTransitions[i].endingState, rightState.outgoingTransitions[j].endingState, left_temp);
|
||||||
if(endingState_left_right != undefined) {
|
if(endingState_left_right != undefined) {
|
||||||
|
const leftConditions = leftState.outgoingTransitions[i].scriptAccountConditions;
|
||||||
|
const rightConditions = rightState.outgoingTransitions[j].scriptAccountConditions;
|
||||||
|
if(!this.contradictCombinedConditions(leftConditions, rightConditions)) {
|
||||||
const transition_left_right = productGamesystem.createTransition(startingState, endingState_left_right)!;
|
const transition_left_right = productGamesystem.createTransition(startingState, endingState_left_right)!;
|
||||||
|
|
||||||
|
if(transition_left_right != undefined) {
|
||||||
|
transition_left_right.scriptAccountActions = this.generateCombinedActions(leftState.outgoingTransitions[i].scriptAccountActions, rightState.outgoingTransitions[j].scriptAccountActions)
|
||||||
|
transition_left_right.scriptAccountConditions = this.generateCombinedConditions(leftState.outgoingTransitions[i].scriptAccountConditions, rightState.outgoingTransitions[j].scriptAccountConditions)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -127,6 +146,10 @@ export class ProductGamesystem extends Gamesystem<ProductState, ProductTransitio
|
|||||||
|
|
||||||
if(startingState != undefined && endingState != undefined) {
|
if(startingState != undefined && endingState != undefined) {
|
||||||
const transition = productGamesystem.createTransition(startingState, endingState);
|
const transition = productGamesystem.createTransition(startingState, endingState);
|
||||||
|
if(transition != undefined) {
|
||||||
|
transition.scriptAccountActions = [... leftState.outgoingTransitions[i].scriptAccountActions]
|
||||||
|
transition.scriptAccountConditions = [...leftState.outgoingTransitions[i].scriptAccountConditions]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -138,6 +161,10 @@ export class ProductGamesystem extends Gamesystem<ProductState, ProductTransitio
|
|||||||
|
|
||||||
if(startingState != undefined && endingState != undefined) {
|
if(startingState != undefined && endingState != undefined) {
|
||||||
const transition = productGamesystem.createTransition(startingState, endingState);
|
const transition = productGamesystem.createTransition(startingState, endingState);
|
||||||
|
if(transition != undefined) {
|
||||||
|
transition.scriptAccountActions = [... rightState.outgoingTransitions[j].scriptAccountActions]
|
||||||
|
transition.scriptAccountConditions = [...rightState.outgoingTransitions[j].scriptAccountConditions]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -149,6 +176,60 @@ export class ProductGamesystem extends Gamesystem<ProductState, ProductTransitio
|
|||||||
return productGamesystem;
|
return productGamesystem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static generateCombinedActions(leftActions: ScriptAccountAction[], rightActions: ScriptAccountAction[]) {
|
||||||
|
const combinedActions: ScriptAccountAction[] = []
|
||||||
|
for(let i=0; i<leftActions.length; i++) {
|
||||||
|
for(let j=0; j<rightActions.length; j++) {
|
||||||
|
const combinedAction = leftActions[i].combineActions(rightActions[j])
|
||||||
|
if(combinedAction == undefined) {
|
||||||
|
if(!combinedActions.includes(leftActions[i])) {
|
||||||
|
combinedActions.push(leftActions[i])
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!combinedActions.includes(rightActions[j])) {
|
||||||
|
combinedActions.push(rightActions[j])
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
|
||||||
|
combinedActions.push(combinedAction)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return combinedActions;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static generateCombinedConditions(leftConditions: ScriptAccountCondition[], rightConditions: ScriptAccountCondition[]) {
|
||||||
|
const combinedConditions: ScriptAccountCondition[] = [];
|
||||||
|
for(let i=0; i<leftConditions.length; i++) {
|
||||||
|
for(let j=0; j<rightConditions.length; j++) {
|
||||||
|
const combinedCondition = leftConditions[i].combineCondition(rightConditions[j]);
|
||||||
|
if(combinedCondition == undefined) {
|
||||||
|
if(!combinedConditions.includes(leftConditions[i])) {
|
||||||
|
combinedConditions.push(leftConditions[i])
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!combinedConditions.includes(rightConditions[j])) {
|
||||||
|
combinedConditions.push(rightConditions[j])
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
combinedConditions.push(combinedCondition)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return combinedConditions;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static contradictCombinedConditions(leftConditions: ScriptAccountCondition[], rightConditions: ScriptAccountCondition[]): boolean {
|
||||||
|
for(let i=0; i<leftConditions.length; i++) {
|
||||||
|
for(let j=0; j<rightConditions.length; j++) {
|
||||||
|
if(leftConditions[i].isContradicting(rightConditions[j])) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
generateBinaryProductState(leftInnerState: State<any>, rightInnerState: State<any>, left_temp: boolean) {
|
generateBinaryProductState(leftInnerState: State<any>, rightInnerState: State<any>, left_temp: boolean) {
|
||||||
const combinedStateConditions: ScriptAccountCondition[] = leftInnerState.conditions.concat(rightInnerState.conditions)
|
const combinedStateConditions: ScriptAccountCondition[] = leftInnerState.conditions.concat(rightInnerState.conditions)
|
||||||
for(let i=0; i<combinedStateConditions.length; i++) {
|
for(let i=0; i<combinedStateConditions.length; i++) {
|
||||||
@ -215,4 +296,6 @@ export class ProductGamesystem extends Gamesystem<ProductState, ProductTransitio
|
|||||||
private existsState(state: ProductState) {
|
private existsState(state: ProductState) {
|
||||||
return this.states.find(s => s.equals(state)) != undefined;
|
return this.states.find(s => s.equals(state)) != undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import {ScriptAccount} from "../../scriptAccounts/ScriptAccount";
|
import {ScriptAccount} from "../../scriptAccounts/ScriptAccount";
|
||||||
|
import {ScriptAccountCondition} from "../conditions/ScriptAccountCondition";
|
||||||
|
|
||||||
export class ScriptAccountAction {
|
export class ScriptAccountAction {
|
||||||
scriptAccount: ScriptAccount
|
scriptAccount: ScriptAccount
|
||||||
@ -9,4 +10,13 @@ export class ScriptAccountAction {
|
|||||||
this.scriptAccount = scriptAccount;
|
this.scriptAccount = scriptAccount;
|
||||||
this.changingValue = changingValue;
|
this.changingValue = changingValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
combineActions(otherAction: ScriptAccountAction) {
|
||||||
|
if(otherAction.scriptAccount === this.scriptAccount) {
|
||||||
|
return new ScriptAccountAction(this.scriptAccount, this.changingValue + otherAction.changingValue)
|
||||||
|
} else {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,15 @@ export class ScriptAccountCondition {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
combineCondition(condition: ScriptAccountCondition) {
|
||||||
|
if(condition.scriptAccount === this.scriptAccount) {
|
||||||
|
const scriptAccount = new ScriptAccountCondition(this.scriptAccount, this.minValue, this.maxValue);
|
||||||
|
scriptAccount.combineCondition(condition);
|
||||||
|
return scriptAccount;
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
isContradicting(condition: ScriptAccountCondition) {
|
isContradicting(condition: ScriptAccountCondition) {
|
||||||
return condition.scriptAccount === this.scriptAccount &&
|
return condition.scriptAccount === this.scriptAccount &&
|
||||||
(this.maxValue < condition.minValue || this.minValue > condition.maxValue)
|
(this.maxValue < condition.minValue || this.minValue > condition.maxValue)
|
||||||
|
Loading…
Reference in New Issue
Block a user