Skip to content

Commit

Permalink
v0.1.56
Browse files Browse the repository at this point in the history
  • Loading branch information
REllEK-IO committed May 1, 2024
1 parent 355d8fd commit a858391
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 34 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ When in doubt simplify.
* [Unified Turing Machine](https://github.com/Phuire-Research/Stratimux/blob/main/The-Unified-Turing-Machine.md) - The governing concept for this entire framework.

## Change Log ![Tests](https://github.com/Phuire-Research/Stratimux/actions/workflows/node.js.yml/badge.svg)
### v0.1.56 5/01/24
* May now properly update each plans intended KeyedSelectors to control when they are ran.
### v0.1.55 4/24/24
* Changed ActionNodeOptions to allow for successNode and failureNode to be left absent. Continued effort towards decreasing boilerplate.
* Refined original paper.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "stratimux",
"license": "GPL-3.0",
"version": "0.1.55",
"version": "0.1.56",
"description": "Unified Turing Machine",
"main": "dist/index.js",
"module": "dist/index.mjs",
Expand Down
68 changes: 44 additions & 24 deletions src/model/stagePlanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,25 +211,26 @@ const handleStageDelimiter =
];
};

const handleNewStageOptions = (plan: Plan, options: dispatchOptions, next: number): boolean => {
let evaluate = false;
if (options.newPriority) {
plan.stages[plan.stage].priority = options.newPriority;
evaluate = true;
}
if (options.newSelectors) {
plan.stages[plan.stage].selectors = options.newSelectors;
evaluate = true;
}
if (options.newBeat) {
plan.stages[plan.stage].beat = options.newBeat;
if (next === -1) {
plan.beat = options.newBeat;
}
evaluate = true;
}
return evaluate;
};
// const handleNewStageOptions = (plan: Plan, options: dispatchOptions, next: number): boolean => {
// let evaluate = false;
// if (options.newPriority) {
// plan.stages[plan.stage].priority = options.newPriority;
// evaluate = true;
// }
// if (options.newSelectors) {
// plan.stages[plan.stage].selectors = options.newSelectors;
// // this.handleAddSelector(plan.stages[plan.stage].selectors, plan.id);
// evaluate = true;
// }
// if (options.newBeat) {
// plan.stages[plan.stage].beat = options.newBeat;
// if (next === -1) {
// plan.beat = options.newBeat;
// }
// evaluate = true;
// }
// return evaluate;
// };

const Inner = 0;
const Base = 1;
Expand Down Expand Up @@ -274,6 +275,28 @@ export class UnifiedSubject extends Subject<Concepts> {
selectors.forEach(selector => this.addSelector(selector, id));
}

protected handleNewStageOptions = (plan: Plan, options: dispatchOptions, next: number): boolean => {
let evaluate = false;
if (options.newPriority) {
plan.stages[plan.stage].priority = options.newPriority;
evaluate = true;
}
if (options.newSelectors) {
this.handleRemoveSelector(plan.stages[plan.stage].selectors, plan.id);
plan.stages[plan.stage].selectors = options.newSelectors;
this.handleAddSelector(plan.stages[plan.stage].selectors, plan.id);
evaluate = true;
}
if (options.newBeat) {
plan.stages[plan.stage].beat = options.newBeat;
if (next === -1) {
plan.beat = options.newBeat;
}
evaluate = true;
}
return evaluate;
};

protected addSelector(selector: KeyedSelector, id: number) {
const s = this.selectors.get(selector.keys);
if (s) {
Expand Down Expand Up @@ -576,6 +599,7 @@ export class UnifiedSubject extends Subject<Concepts> {
this.stageDelimiters.set(plan.id, stageDelimiter);
if (!throttle && run) {
let next = -1;
const evaluate = this.handleNewStageOptions(plan, options, next);
if (options?.iterateStage) {
next = plan.stage + 1;
// this.updatePlanSelector(plan, plan.stage, next < plan.stages.length ? next : undefined);
Expand All @@ -590,21 +614,18 @@ export class UnifiedSubject extends Subject<Concepts> {
this.handleRemoveSelector(plan.stages[plan.stage].selectors, plan.id);
}
plan.stage = next;
this.manageQues();
if (plan.stages[plan.stage]) {
this.handleAddSelector(plan.stages[plan.stage].selectors, plan.id);
}
this.manageQues();
const beat = plan.stages[plan.stage].beat;
plan.beat = beat !== undefined ? beat : -1;
stageDelimiter.prevActions = [];
stageDelimiter.unionExpiration = [];
stageDelimiter.runOnceMap = new Map();
this.stageDelimiters.set(plan.id, stageDelimiter);
}
const evaluate = handleNewStageOptions(plan, options, next);
if (evaluate && next === -1) {
this.handleRemoveSelector(plan.stages[plan.stage].selectors, plan.id);
this.handleAddSelector(plan.stages[plan.stage].selectors, plan.id);
this.manageQues();
}
// Horrifying
Expand Down Expand Up @@ -709,7 +730,6 @@ export class UnifiedSubject extends Subject<Concepts> {
});
}
}

const notification = (id: number) => {
const ready = notifyIds.get(id);
const plan = this.currentPlans.get(id);
Expand Down
35 changes: 26 additions & 9 deletions src/test/onChange.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,52 @@ $>*/
/*<#*/
import { createAxium } from '../model/axium';
import { strategyBegin } from '../model/actionStrategy';
import { selectState } from '../model/selector';
import { selectSlice, selectState } from '../model/selector';
import { CounterState, createCounterConcept, countingStrategy, counterName } from '../concepts/counter/counter.concept';
import { AxiumState } from '../concepts/axium/axium.concept';
import { countingTopic } from '../concepts/counter/strategies/counting.strategy';
import { createStage } from '../model/stagePlanner';
import { counterSelectCount } from '../concepts/counter/counter.selector';
import { axiumSelectLastStrategy } from '../concepts/axium/axium.selector';
import { axiumKick } from '../concepts/axium/qualities/kick.quality';
import { initializeTopic } from '../concepts/axium/strategies/initialization.strategy';
import { Concepts } from '../model/concept';

test('Axium Counting Strategy Test', (done) => {
const selectorRouter = {
[axiumSelectLastStrategy.keys]: (concepts: Concepts) =>
console.log('CHECK: ', selectSlice(concepts, axiumSelectLastStrategy))
};
const axium = createAxium('axiumStrategyTest', [createCounterConcept()], true, true);
const plan = axium.plan('Counting Strategy Stage',
[
createStage((_, dispatch) => {
dispatch(strategyBegin(countingStrategy()), {
iterateStage: true
createStage((concepts, dispatch) => {
if (selectSlice(concepts, axiumSelectLastStrategy) === initializeTopic) {
dispatch(strategyBegin(countingStrategy()), {
iterateStage: true
});
}
}, {selectors: [axiumSelectLastStrategy]}),
createStage((concepts, dispatch, changes) => {
console.log('Check Changes: ', changes);
changes?.forEach(keyed => {
selectorRouter[keyed.keys] ? selectorRouter[keyed.keys](concepts) : null;
});
}),
createStage((concepts, _, changes) => {
console.log(changes);
const axiumState = concepts[0].state as AxiumState;
const counter = selectState<CounterState>(concepts, counterName);
if (axiumState.lastStrategy === countingTopic) {
const counter = selectState<CounterState>(concepts, counterName);
expect(counter?.count).toBe(1);
setTimeout(() => {done();}, 500);
plan.conclude();
axium.close();
} else {
dispatch(axiumKick(), {
newSelectors: [counterSelectCount, axiumSelectLastStrategy],
throttle: 0
});
}
}, {
selectors: [counterSelectCount, axiumSelectLastStrategy]
selectors: [counterSelectCount]
})
]);
});
Expand Down

0 comments on commit a858391

Please sign in to comment.