Skip to content

Commit e88d784

Browse files
committed
Proper stochastics. Seedable RNG. Fixes StoneCypher/fsl#990, StoneCypher/fsl#991
1 parent 966c142 commit e88d784

38 files changed

+427
-187
lines changed

CHANGELOG.long.md

+33-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
All notable changes to this project will be documented in this file.
44

5-
1100 merges; 187 releases
5+
1102 merges; 187 releases
66

77

88

@@ -18,6 +18,38 @@ Published tags:
1818

1919

2020

21+
 
22+
23+
 
24+
25+
## [Untagged] - 10/25/2023 11:31:11 AM
26+
27+
Commit [966c142a44db8c5f890b2cc4edadca9faee2d625](https://github.com/StoneCypher/jssm/commit/966c142a44db8c5f890b2cc4edadca9faee2d625)
28+
29+
Author: `John Haugeland <[email protected]>`
30+
31+
Merges [9944585, bba1f0a]
32+
33+
* Merge branch 'main' into NewGraphicAssets
34+
35+
36+
37+
38+
&nbsp;
39+
40+
&nbsp;
41+
42+
## [Untagged] - 10/25/2023 11:29:11 AM
43+
44+
Commit [bba1f0a273ca73ffe105eed27619fc6b31247568](https://github.com/StoneCypher/jssm/commit/bba1f0a273ca73ffe105eed27619fc6b31247568)
45+
46+
Author: `John Haugeland <[email protected]>`
47+
48+
* update github action to cover more modern node versions to cover 20 and 21
49+
50+
51+
52+
2153
&nbsp;
2254

2355
&nbsp;

CHANGELOG.md

+34-37
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
All notable changes to this project will be documented in this file.
44

5-
1100 merges; 187 releases; Changlogging the last 10 commits; Full changelog at [CHANGELOG.long.md](CHANGELOG.long.md)
5+
1102 merges; 187 releases; Changlogging the last 10 commits; Full changelog at [CHANGELOG.long.md](CHANGELOG.long.md)
66

77

88

@@ -18,6 +18,38 @@ Published tags:
1818

1919

2020

21+
&nbsp;
22+
23+
&nbsp;
24+
25+
## [Untagged] - 10/25/2023 11:31:11 AM
26+
27+
Commit [966c142a44db8c5f890b2cc4edadca9faee2d625](https://github.com/StoneCypher/jssm/commit/966c142a44db8c5f890b2cc4edadca9faee2d625)
28+
29+
Author: `John Haugeland <[email protected]>`
30+
31+
Merges [9944585, bba1f0a]
32+
33+
* Merge branch 'main' into NewGraphicAssets
34+
35+
36+
37+
38+
&nbsp;
39+
40+
&nbsp;
41+
42+
## [Untagged] - 10/25/2023 11:29:11 AM
43+
44+
Commit [bba1f0a273ca73ffe105eed27619fc6b31247568](https://github.com/StoneCypher/jssm/commit/bba1f0a273ca73ffe105eed27619fc6b31247568)
45+
46+
Author: `John Haugeland <[email protected]>`
47+
48+
* update github action to cover more modern node versions to cover 20 and 21
49+
50+
51+
52+
2153
&nbsp;
2254

2355
&nbsp;
@@ -149,39 +181,4 @@ Author: `John Haugeland <[email protected]>`
149181
Merges [d04a575, 6337159]
150182

151183
* Merge pull request #556 from StoneCypher/FinalizeDenoSupport
152-
* Standard deno support
153-
154-
155-
156-
157-
&nbsp;
158-
159-
&nbsp;
160-
161-
## [Untagged] - 5/13/2023 11:35:56 PM
162-
163-
Commit [6337159890e2a5f96af18a926096d82876660903](https://github.com/StoneCypher/jssm/commit/6337159890e2a5f96af18a926096d82876660903)
164-
165-
Author: `John Haugeland <[email protected]>`
166-
167-
* Standard deno support
168-
169-
170-
171-
172-
&nbsp;
173-
174-
&nbsp;
175-
176-
<a name="5__89__0" />
177-
178-
## [5.89.0] - 5/7/2023 12:34:42 PM
179-
180-
Commit [d04a57542edb377085437d38e31d13a65fccdce8](https://github.com/StoneCypher/jssm/commit/d04a57542edb377085437d38e31d13a65fccdce8)
181-
182-
Author: `John Haugeland <[email protected]>`
183-
184-
Merges [ef4285a, 2a87cf1]
185-
186-
* Merge pull request #555 from StoneCypher/ReattemptDenoSupport
187-
* draft support for deno
184+
* Standard deno support

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,18 @@ Please edit the file it's derived from, instead: `./src/md/readme_base.md`
1818
1919
2020
21-
* Generated for version 5.89.6 at 10/25/2023, 11:25:13 AM
21+
* Generated for version 5.90.0 at 10/25/2023, 12:32:59 PM
2222
2323
-->
24-
# jssm 5.89.6
24+
# jssm 5.90.0
2525

2626
Easy. Small. Fast. TS, es6, es5. Node, Browser. 100% coverage. Property
2727
tests. Fuzz tests. Language tests for a dozen languages and emoji. Easy to
2828
share online. Easy to embed.
2929

3030
Readable, useful state machines as one-liner strings.
3131

32-
***4,923 tests*** run 5,814 times. 4,914 specs with 100.0% coverage, 9 fuzz tests with 13.1% coverage. With 2,834 lines, that's about 1.7 tests per line, or {{line_run_ratio}} generated tests per line.
32+
***4,937 tests*** run 5,828 times. 4,928 specs with 100.0% coverage, 9 fuzz tests with 13.0% coverage. With 2,855 lines, that's about 1.7 tests per line, or {{line_run_ratio}} generated tests per line.
3333

3434
***Meet your new state machine library.***
3535

dist/deno/README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,18 @@ Please edit the file it's derived from, instead: `./src/md/readme_base.md`
1818
1919
2020
21-
* Generated for version 5.89.6 at 10/25/2023, 11:25:13 AM
21+
* Generated for version 5.90.0 at 10/25/2023, 12:32:59 PM
2222
2323
-->
24-
# jssm 5.89.6
24+
# jssm 5.90.0
2525

2626
Easy. Small. Fast. TS, es6, es5. Node, Browser. 100% coverage. Property
2727
tests. Fuzz tests. Language tests for a dozen languages and emoji. Easy to
2828
share online. Easy to embed.
2929

3030
Readable, useful state machines as one-liner strings.
3131

32-
***4,923 tests*** run 5,814 times. 4,914 specs with 100.0% coverage, 9 fuzz tests with 13.1% coverage. With 2,834 lines, that's about 1.7 tests per line, or {{line_run_ratio}} generated tests per line.
32+
***4,937 tests*** run 5,828 times. 4,928 specs with 100.0% coverage, 9 fuzz tests with 13.0% coverage. With 2,855 lines, that's about 1.7 tests per line, or {{line_run_ratio}} generated tests per line.
3333

3434
***Meet your new state machine library.***
3535

dist/deno/jssm.d.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
declare type StateType = string;
22
import { JssmGenericState, JssmGenericConfig, JssmStateConfig, JssmTransition, JssmTransitionList, // JssmTransitionRule,
3-
JssmMachineInternalState, JssmAllowsOverride, JssmStateDeclaration, JssmStateStyleKeyList, JssmLayout, JssmHistory, JssmSerialization, FslDirection, FslDirections, FslTheme, HookDescription, HookHandler, HookContext, HookResult, HookComplexResult } from './jssm_types';
3+
JssmMachineInternalState, JssmAllowsOverride, JssmStateDeclaration, JssmStateStyleKeyList, JssmLayout, JssmHistory, JssmSerialization, FslDirection, FslDirections, FslTheme, HookDescription, HookHandler, HookContext, HookResult, HookComplexResult, JssmRng } from './jssm_types';
44
import { arrow_direction, arrow_left_kind, arrow_right_kind } from './jssm_arrow';
55
import { compile, make, wrap_parse } from './jssm_compiler';
66
import { seq, unique, find_repeated, weighted_rand_select, weighted_sample_select, histograph, weighted_histo_key } from './jssm_util';
@@ -40,8 +40,10 @@ declare class Machine<mDT> {
4040
_fsl_version?: string;
4141
_raw_state_declaration?: Array<Object>;
4242
_state_declarations: Map<StateType, JssmStateDeclaration>;
43-
_instance_name: string;
4443
_data?: mDT;
44+
_instance_name: string;
45+
_rng_seed: number;
46+
_rng: JssmRng;
4547
_graph_layout: JssmLayout;
4648
_dot_preamble: string;
4749
_arrange_declaration: Array<Array<StateType>>;
@@ -99,7 +101,7 @@ declare class Machine<mDT> {
99101
_start_state_style: JssmStateConfig;
100102
_end_state_style: JssmStateConfig;
101103
_state_labels: Map<string, string>;
102-
constructor({ start_states, end_states, complete, transitions, machine_author, machine_comment, machine_contributor, machine_definition, machine_language, machine_license, machine_name, machine_version, state_declaration, property_definition, state_property, fsl_version, dot_preamble, arrange_declaration, arrange_start_declaration, arrange_end_declaration, theme, flow, graph_layout, instance_name, history, data, default_state_config, default_active_state_config, default_hooked_state_config, default_terminal_state_config, default_start_state_config, default_end_state_config, allows_override, config_allows_override }: JssmGenericConfig<StateType, mDT>);
104+
constructor({ start_states, end_states, complete, transitions, machine_author, machine_comment, machine_contributor, machine_definition, machine_language, machine_license, machine_name, machine_version, state_declaration, property_definition, state_property, fsl_version, dot_preamble, arrange_declaration, arrange_start_declaration, arrange_end_declaration, theme, flow, graph_layout, instance_name, history, data, default_state_config, default_active_state_config, default_hooked_state_config, default_terminal_state_config, default_start_state_config, default_end_state_config, allows_override, config_allows_override, rng_seed }: JssmGenericConfig<StateType, mDT>);
103105
/********
104106
*
105107
* Internal method for fabricating states. Not meant for external use.
@@ -668,6 +670,8 @@ declare class Machine<mDT> {
668670
post_hook_any_transition(handler: HookHandler<mDT>): Machine<mDT>;
669671
post_hook_entry(to: string, handler: HookHandler<mDT>): Machine<mDT>;
670672
post_hook_exit(from: string, handler: HookHandler<mDT>): Machine<mDT>;
673+
get rng_seed(): number;
674+
set rng_seed(to: number | undefined);
671675
edges_between(from: string, to: string): JssmTransition<StateType, mDT>[];
672676
/*********
673677
*

dist/deno/jssm.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/deno/jssm_types.d.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ declare type JssmGenericConfig<StateType, DataType> = {
219219
default_hooked_state_config?: JssmStateStyleKeyList;
220220
default_terminal_state_config?: JssmStateStyleKeyList;
221221
default_active_state_config?: JssmStateStyleKeyList;
222+
rng_seed?: number | undefined;
222223
};
223224
declare type JssmCompileRule<StateType> = {
224225
agg_as: string;
@@ -359,4 +360,5 @@ declare type JssmErrorExtendedInfo = {
359360
requested_state?: StateType | undefined;
360361
};
361362
declare type JssmHistory<mDT> = circular_buffer<[StateType, mDT]>;
362-
export { JssmColor, JssmShape, JssmTransition, JssmTransitions, JssmTransitionList, JssmTransitionRule, JssmArrow, JssmArrowKind, JssmArrowDirection, JssmGenericConfig, JssmGenericState, JssmGenericMachine, JssmParseTree, JssmCompileSe, JssmCompileSeStart, JssmCompileRule, JssmPermitted, JssmPermittedOpt, JssmResult, JssmStateDeclaration, JssmStateDeclarationRule, JssmStateConfig, JssmStateStyleKey, JssmStateStyleKeyList, JssmBaseTheme, JssmTheme, JssmLayout, JssmHistory, JssmSerialization, JssmPropertyDefinition, JssmAllowsOverride, JssmParseFunctionType, JssmMachineInternalState, JssmErrorExtendedInfo, FslDirections, FslDirection, FslThemes, FslTheme, HookDescription, HookHandler, HookContext, HookResult, HookComplexResult };
363+
declare type JssmRng = () => number;
364+
export { JssmColor, JssmShape, JssmTransition, JssmTransitions, JssmTransitionList, JssmTransitionRule, JssmArrow, JssmArrowKind, JssmArrowDirection, JssmGenericConfig, JssmGenericState, JssmGenericMachine, JssmParseTree, JssmCompileSe, JssmCompileSeStart, JssmCompileRule, JssmPermitted, JssmPermittedOpt, JssmResult, JssmStateDeclaration, JssmStateDeclarationRule, JssmStateConfig, JssmStateStyleKey, JssmStateStyleKeyList, JssmBaseTheme, JssmTheme, JssmLayout, JssmHistory, JssmSerialization, JssmPropertyDefinition, JssmAllowsOverride, JssmParseFunctionType, JssmMachineInternalState, JssmErrorExtendedInfo, FslDirections, FslDirection, FslThemes, FslTheme, HookDescription, HookHandler, HookContext, HookResult, HookComplexResult, JssmRng };

dist/es6/jssm.d.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
declare type StateType = string;
22
import { JssmGenericState, JssmGenericConfig, JssmStateConfig, JssmTransition, JssmTransitionList, // JssmTransitionRule,
3-
JssmMachineInternalState, JssmAllowsOverride, JssmStateDeclaration, JssmStateStyleKeyList, JssmLayout, JssmHistory, JssmSerialization, FslDirection, FslDirections, FslTheme, HookDescription, HookHandler, HookContext, HookResult, HookComplexResult } from './jssm_types';
3+
JssmMachineInternalState, JssmAllowsOverride, JssmStateDeclaration, JssmStateStyleKeyList, JssmLayout, JssmHistory, JssmSerialization, FslDirection, FslDirections, FslTheme, HookDescription, HookHandler, HookContext, HookResult, HookComplexResult, JssmRng } from './jssm_types';
44
import { arrow_direction, arrow_left_kind, arrow_right_kind } from './jssm_arrow';
55
import { compile, make, wrap_parse } from './jssm_compiler';
66
import { seq, unique, find_repeated, weighted_rand_select, weighted_sample_select, histograph, weighted_histo_key } from './jssm_util';
@@ -40,8 +40,10 @@ declare class Machine<mDT> {
4040
_fsl_version?: string;
4141
_raw_state_declaration?: Array<Object>;
4242
_state_declarations: Map<StateType, JssmStateDeclaration>;
43-
_instance_name: string;
4443
_data?: mDT;
44+
_instance_name: string;
45+
_rng_seed: number;
46+
_rng: JssmRng;
4547
_graph_layout: JssmLayout;
4648
_dot_preamble: string;
4749
_arrange_declaration: Array<Array<StateType>>;
@@ -99,7 +101,7 @@ declare class Machine<mDT> {
99101
_start_state_style: JssmStateConfig;
100102
_end_state_style: JssmStateConfig;
101103
_state_labels: Map<string, string>;
102-
constructor({ start_states, end_states, complete, transitions, machine_author, machine_comment, machine_contributor, machine_definition, machine_language, machine_license, machine_name, machine_version, state_declaration, property_definition, state_property, fsl_version, dot_preamble, arrange_declaration, arrange_start_declaration, arrange_end_declaration, theme, flow, graph_layout, instance_name, history, data, default_state_config, default_active_state_config, default_hooked_state_config, default_terminal_state_config, default_start_state_config, default_end_state_config, allows_override, config_allows_override }: JssmGenericConfig<StateType, mDT>);
104+
constructor({ start_states, end_states, complete, transitions, machine_author, machine_comment, machine_contributor, machine_definition, machine_language, machine_license, machine_name, machine_version, state_declaration, property_definition, state_property, fsl_version, dot_preamble, arrange_declaration, arrange_start_declaration, arrange_end_declaration, theme, flow, graph_layout, instance_name, history, data, default_state_config, default_active_state_config, default_hooked_state_config, default_terminal_state_config, default_start_state_config, default_end_state_config, allows_override, config_allows_override, rng_seed }: JssmGenericConfig<StateType, mDT>);
103105
/********
104106
*
105107
* Internal method for fabricating states. Not meant for external use.
@@ -668,6 +670,8 @@ declare class Machine<mDT> {
668670
post_hook_any_transition(handler: HookHandler<mDT>): Machine<mDT>;
669671
post_hook_entry(to: string, handler: HookHandler<mDT>): Machine<mDT>;
670672
post_hook_exit(from: string, handler: HookHandler<mDT>): Machine<mDT>;
673+
get rng_seed(): number;
674+
set rng_seed(to: number | undefined);
671675
edges_between(from: string, to: string): JssmTransition<StateType, mDT>[];
672676
/*********
673677
*

dist/es6/jssm.js

+16-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { FslDirections } from './jssm_types';
44
import { arrow_direction, arrow_left_kind, arrow_right_kind } from './jssm_arrow';
55
import { compile, make, wrap_parse } from './jssm_compiler';
66
import { theme_mapping, base_theme } from './jssm_theme';
7-
import { seq, unique, find_repeated, weighted_rand_select, weighted_sample_select, histograph, weighted_histo_key, array_box_if_string, name_bind_prop_and_state, hook_name, named_hook_name } from './jssm_util';
7+
import { seq, unique, find_repeated, weighted_rand_select, weighted_sample_select, histograph, weighted_histo_key, array_box_if_string, name_bind_prop_and_state, hook_name, named_hook_name, gen_splitmix32 } from './jssm_util';
88
import * as constants from './jssm_constants';
99
const { shapes, gviz_shapes, named_colors } = constants;
1010
import { version, build_time } from './version'; // replaced from package.js in build
@@ -126,7 +126,7 @@ function state_style_condense(jssk) {
126126
// TODO add a lotta docblock here
127127
class Machine {
128128
// whargarbl this badly needs to be broken up, monolith master
129-
constructor({ start_states, end_states = [], complete = [], transitions, machine_author, machine_comment, machine_contributor, machine_definition, machine_language, machine_license, machine_name, machine_version, state_declaration, property_definition, state_property, fsl_version, dot_preamble = undefined, arrange_declaration = [], arrange_start_declaration = [], arrange_end_declaration = [], theme = ['default'], flow = 'down', graph_layout = 'dot', instance_name, history, data, default_state_config, default_active_state_config, default_hooked_state_config, default_terminal_state_config, default_start_state_config, default_end_state_config, allows_override, config_allows_override }) {
129+
constructor({ start_states, end_states = [], complete = [], transitions, machine_author, machine_comment, machine_contributor, machine_definition, machine_language, machine_license, machine_name, machine_version, state_declaration, property_definition, state_property, fsl_version, dot_preamble = undefined, arrange_declaration = [], arrange_start_declaration = [], arrange_end_declaration = [], theme = ['default'], flow = 'down', graph_layout = 'dot', instance_name, history, data, default_state_config, default_active_state_config, default_hooked_state_config, default_terminal_state_config, default_start_state_config, default_end_state_config, allows_override, config_allows_override, rng_seed }) {
130130
this._instance_name = instance_name;
131131
this._state = start_states[0];
132132
this._states = new Map();
@@ -212,6 +212,8 @@ class Machine {
212212
this._history_length = history || 0;
213213
this._history = new circular_buffer(this._history_length);
214214
this._state_labels = new Map();
215+
this._rng_seed = rng_seed !== null && rng_seed !== void 0 ? rng_seed : new Date().getTime();
216+
this._rng = gen_splitmix32(this._rng_seed);
215217
// consolidate the state declarations
216218
if (state_declaration) {
217219
state_declaration.map((state_decl) => {
@@ -1076,7 +1078,7 @@ class Machine {
10761078
return wtf;
10771079
}
10781080
probabilistic_transition() {
1079-
const selected = weighted_rand_select(this.probable_exits_for(this.state()));
1081+
const selected = weighted_rand_select(this.probable_exits_for(this.state()), undefined, this._rng);
10801082
return this.transition(selected.to);
10811083
}
10821084
probabilistic_walk(n) {
@@ -1419,6 +1421,17 @@ class Machine {
14191421
this.set_hook({ kind: 'post exit', from, handler });
14201422
return this;
14211423
}
1424+
get rng_seed() {
1425+
return this._rng_seed;
1426+
}
1427+
set rng_seed(to) {
1428+
if (typeof to === 'undefined') {
1429+
this._rng_seed = new Date().getTime();
1430+
}
1431+
else {
1432+
this._rng_seed = to;
1433+
}
1434+
}
14221435
// remove_hook(HookDesc: HookDescription) {
14231436
// throw new JssmError(this, 'TODO: Should remove hook here');
14241437
// }

dist/es6/jssm_types.d.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ declare type JssmGenericConfig<StateType, DataType> = {
219219
default_hooked_state_config?: JssmStateStyleKeyList;
220220
default_terminal_state_config?: JssmStateStyleKeyList;
221221
default_active_state_config?: JssmStateStyleKeyList;
222+
rng_seed?: number | undefined;
222223
};
223224
declare type JssmCompileRule<StateType> = {
224225
agg_as: string;
@@ -359,4 +360,5 @@ declare type JssmErrorExtendedInfo = {
359360
requested_state?: StateType | undefined;
360361
};
361362
declare type JssmHistory<mDT> = circular_buffer<[StateType, mDT]>;
362-
export { JssmColor, JssmShape, JssmTransition, JssmTransitions, JssmTransitionList, JssmTransitionRule, JssmArrow, JssmArrowKind, JssmArrowDirection, JssmGenericConfig, JssmGenericState, JssmGenericMachine, JssmParseTree, JssmCompileSe, JssmCompileSeStart, JssmCompileRule, JssmPermitted, JssmPermittedOpt, JssmResult, JssmStateDeclaration, JssmStateDeclarationRule, JssmStateConfig, JssmStateStyleKey, JssmStateStyleKeyList, JssmBaseTheme, JssmTheme, JssmLayout, JssmHistory, JssmSerialization, JssmPropertyDefinition, JssmAllowsOverride, JssmParseFunctionType, JssmMachineInternalState, JssmErrorExtendedInfo, FslDirections, FslDirection, FslThemes, FslTheme, HookDescription, HookHandler, HookContext, HookResult, HookComplexResult };
363+
declare type JssmRng = () => number;
364+
export { JssmColor, JssmShape, JssmTransition, JssmTransitions, JssmTransitionList, JssmTransitionRule, JssmArrow, JssmArrowKind, JssmArrowDirection, JssmGenericConfig, JssmGenericState, JssmGenericMachine, JssmParseTree, JssmCompileSe, JssmCompileSeStart, JssmCompileRule, JssmPermitted, JssmPermittedOpt, JssmResult, JssmStateDeclaration, JssmStateDeclarationRule, JssmStateConfig, JssmStateStyleKey, JssmStateStyleKeyList, JssmBaseTheme, JssmTheme, JssmLayout, JssmHistory, JssmSerialization, JssmPropertyDefinition, JssmAllowsOverride, JssmParseFunctionType, JssmMachineInternalState, JssmErrorExtendedInfo, FslDirections, FslDirection, FslThemes, FslTheme, HookDescription, HookHandler, HookContext, HookResult, HookComplexResult, JssmRng };

dist/es6/jssm_util.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ function arr_uniq_p(el, i, source) {
1111
const array_box_if_string = n => typeof n === 'string' ? [n] : n;
1212
// this is explicitly about other peoples' data, so it has to be weakly typed
1313
/* eslint-disable flowtype/no-weak-types */
14-
const weighted_rand_select = (options, probability_property = 'probability') => {
14+
const weighted_rand_select = (options, probability_property = 'probability', rng) => {
1515
if (!Array.isArray(options)) {
1616
throw new TypeError('options must be a non-empty array of objects');
1717
}

0 commit comments

Comments
 (0)