Skip to content

Commit

Permalink
Proper stochastics. Seedable RNG. Fixes StoneCypher/fsl#990, StoneCyp…
Browse files Browse the repository at this point in the history
  • Loading branch information
StoneCypher committed Oct 25, 2023
1 parent 966c142 commit e88d784
Show file tree
Hide file tree
Showing 38 changed files with 427 additions and 187 deletions.
34 changes: 33 additions & 1 deletion CHANGELOG.long.md
Expand Up @@ -2,7 +2,7 @@

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

1100 merges; 187 releases
1102 merges; 187 releases



Expand All @@ -18,6 +18,38 @@ Published tags:



 

 

## [Untagged] - 10/25/2023 11:31:11 AM

Commit [966c142a44db8c5f890b2cc4edadca9faee2d625](https://github.com/StoneCypher/jssm/commit/966c142a44db8c5f890b2cc4edadca9faee2d625)

Author: `John Haugeland <stonecypher@gmail.com>`

Merges [9944585, bba1f0a]

* Merge branch 'main' into NewGraphicAssets




&nbsp;

&nbsp;

## [Untagged] - 10/25/2023 11:29:11 AM

Commit [bba1f0a273ca73ffe105eed27619fc6b31247568](https://github.com/StoneCypher/jssm/commit/bba1f0a273ca73ffe105eed27619fc6b31247568)

Author: `John Haugeland <stonecypher@gmail.com>`

* update github action to cover more modern node versions to cover 20 and 21




&nbsp;

&nbsp;
Expand Down
71 changes: 34 additions & 37 deletions CHANGELOG.md
Expand Up @@ -2,7 +2,7 @@

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

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



Expand All @@ -18,6 +18,38 @@ Published tags:



&nbsp;

&nbsp;

## [Untagged] - 10/25/2023 11:31:11 AM

Commit [966c142a44db8c5f890b2cc4edadca9faee2d625](https://github.com/StoneCypher/jssm/commit/966c142a44db8c5f890b2cc4edadca9faee2d625)

Author: `John Haugeland <stonecypher@gmail.com>`

Merges [9944585, bba1f0a]

* Merge branch 'main' into NewGraphicAssets




&nbsp;

&nbsp;

## [Untagged] - 10/25/2023 11:29:11 AM

Commit [bba1f0a273ca73ffe105eed27619fc6b31247568](https://github.com/StoneCypher/jssm/commit/bba1f0a273ca73ffe105eed27619fc6b31247568)

Author: `John Haugeland <stonecypher@gmail.com>`

* update github action to cover more modern node versions to cover 20 and 21




&nbsp;

&nbsp;
Expand Down Expand Up @@ -149,39 +181,4 @@ Author: `John Haugeland <stonecypher@gmail.com>`
Merges [d04a575, 6337159]

* Merge pull request #556 from StoneCypher/FinalizeDenoSupport
* Standard deno support




&nbsp;

&nbsp;

## [Untagged] - 5/13/2023 11:35:56 PM

Commit [6337159890e2a5f96af18a926096d82876660903](https://github.com/StoneCypher/jssm/commit/6337159890e2a5f96af18a926096d82876660903)

Author: `John Haugeland <stonecypher@gmail.com>`

* Standard deno support




&nbsp;

&nbsp;

<a name="5__89__0" />

## [5.89.0] - 5/7/2023 12:34:42 PM

Commit [d04a57542edb377085437d38e31d13a65fccdce8](https://github.com/StoneCypher/jssm/commit/d04a57542edb377085437d38e31d13a65fccdce8)

Author: `John Haugeland <stonecypher@gmail.com>`

Merges [ef4285a, 2a87cf1]

* Merge pull request #555 from StoneCypher/ReattemptDenoSupport
* draft support for deno
* Standard deno support
6 changes: 3 additions & 3 deletions README.md
Expand Up @@ -18,18 +18,18 @@ Please edit the file it's derived from, instead: `./src/md/readme_base.md`
* Generated for version 5.89.6 at 10/25/2023, 11:25:13 AM
* Generated for version 5.90.0 at 10/25/2023, 12:32:59 PM
-->
# jssm 5.89.6
# jssm 5.90.0

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

Readable, useful state machines as one-liner strings.

***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.
***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.

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

Expand Down
6 changes: 3 additions & 3 deletions dist/deno/README.md
Expand Up @@ -18,18 +18,18 @@ Please edit the file it's derived from, instead: `./src/md/readme_base.md`
* Generated for version 5.89.6 at 10/25/2023, 11:25:13 AM
* Generated for version 5.90.0 at 10/25/2023, 12:32:59 PM
-->
# jssm 5.89.6
# jssm 5.90.0

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

Readable, useful state machines as one-liner strings.

***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.
***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.

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

Expand Down
10 changes: 7 additions & 3 deletions dist/deno/jssm.d.ts
@@ -1,6 +1,6 @@
declare type StateType = string;
import { JssmGenericState, JssmGenericConfig, JssmStateConfig, JssmTransition, JssmTransitionList, // JssmTransitionRule,
JssmMachineInternalState, JssmAllowsOverride, JssmStateDeclaration, JssmStateStyleKeyList, JssmLayout, JssmHistory, JssmSerialization, FslDirection, FslDirections, FslTheme, HookDescription, HookHandler, HookContext, HookResult, HookComplexResult } from './jssm_types';
JssmMachineInternalState, JssmAllowsOverride, JssmStateDeclaration, JssmStateStyleKeyList, JssmLayout, JssmHistory, JssmSerialization, FslDirection, FslDirections, FslTheme, HookDescription, HookHandler, HookContext, HookResult, HookComplexResult, JssmRng } from './jssm_types';
import { arrow_direction, arrow_left_kind, arrow_right_kind } from './jssm_arrow';
import { compile, make, wrap_parse } from './jssm_compiler';
import { seq, unique, find_repeated, weighted_rand_select, weighted_sample_select, histograph, weighted_histo_key } from './jssm_util';
Expand Down Expand Up @@ -40,8 +40,10 @@ declare class Machine<mDT> {
_fsl_version?: string;
_raw_state_declaration?: Array<Object>;
_state_declarations: Map<StateType, JssmStateDeclaration>;
_instance_name: string;
_data?: mDT;
_instance_name: string;
_rng_seed: number;
_rng: JssmRng;
_graph_layout: JssmLayout;
_dot_preamble: string;
_arrange_declaration: Array<Array<StateType>>;
Expand Down Expand Up @@ -99,7 +101,7 @@ declare class Machine<mDT> {
_start_state_style: JssmStateConfig;
_end_state_style: JssmStateConfig;
_state_labels: Map<string, string>;
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>);
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>);
/********
*
* Internal method for fabricating states. Not meant for external use.
Expand Down Expand Up @@ -668,6 +670,8 @@ declare class Machine<mDT> {
post_hook_any_transition(handler: HookHandler<mDT>): Machine<mDT>;
post_hook_entry(to: string, handler: HookHandler<mDT>): Machine<mDT>;
post_hook_exit(from: string, handler: HookHandler<mDT>): Machine<mDT>;
get rng_seed(): number;
set rng_seed(to: number | undefined);
edges_between(from: string, to: string): JssmTransition<StateType, mDT>[];
/*********
*
Expand Down
2 changes: 1 addition & 1 deletion dist/deno/jssm.js

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion dist/deno/jssm_types.d.ts
Expand Up @@ -219,6 +219,7 @@ declare type JssmGenericConfig<StateType, DataType> = {
default_hooked_state_config?: JssmStateStyleKeyList;
default_terminal_state_config?: JssmStateStyleKeyList;
default_active_state_config?: JssmStateStyleKeyList;
rng_seed?: number | undefined;
};
declare type JssmCompileRule<StateType> = {
agg_as: string;
Expand Down Expand Up @@ -359,4 +360,5 @@ declare type JssmErrorExtendedInfo = {
requested_state?: StateType | undefined;
};
declare type JssmHistory<mDT> = circular_buffer<[StateType, mDT]>;
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 };
declare type JssmRng = () => number;
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 };
10 changes: 7 additions & 3 deletions dist/es6/jssm.d.ts
@@ -1,6 +1,6 @@
declare type StateType = string;
import { JssmGenericState, JssmGenericConfig, JssmStateConfig, JssmTransition, JssmTransitionList, // JssmTransitionRule,
JssmMachineInternalState, JssmAllowsOverride, JssmStateDeclaration, JssmStateStyleKeyList, JssmLayout, JssmHistory, JssmSerialization, FslDirection, FslDirections, FslTheme, HookDescription, HookHandler, HookContext, HookResult, HookComplexResult } from './jssm_types';
JssmMachineInternalState, JssmAllowsOverride, JssmStateDeclaration, JssmStateStyleKeyList, JssmLayout, JssmHistory, JssmSerialization, FslDirection, FslDirections, FslTheme, HookDescription, HookHandler, HookContext, HookResult, HookComplexResult, JssmRng } from './jssm_types';
import { arrow_direction, arrow_left_kind, arrow_right_kind } from './jssm_arrow';
import { compile, make, wrap_parse } from './jssm_compiler';
import { seq, unique, find_repeated, weighted_rand_select, weighted_sample_select, histograph, weighted_histo_key } from './jssm_util';
Expand Down Expand Up @@ -40,8 +40,10 @@ declare class Machine<mDT> {
_fsl_version?: string;
_raw_state_declaration?: Array<Object>;
_state_declarations: Map<StateType, JssmStateDeclaration>;
_instance_name: string;
_data?: mDT;
_instance_name: string;
_rng_seed: number;
_rng: JssmRng;
_graph_layout: JssmLayout;
_dot_preamble: string;
_arrange_declaration: Array<Array<StateType>>;
Expand Down Expand Up @@ -99,7 +101,7 @@ declare class Machine<mDT> {
_start_state_style: JssmStateConfig;
_end_state_style: JssmStateConfig;
_state_labels: Map<string, string>;
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>);
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>);
/********
*
* Internal method for fabricating states. Not meant for external use.
Expand Down Expand Up @@ -668,6 +670,8 @@ declare class Machine<mDT> {
post_hook_any_transition(handler: HookHandler<mDT>): Machine<mDT>;
post_hook_entry(to: string, handler: HookHandler<mDT>): Machine<mDT>;
post_hook_exit(from: string, handler: HookHandler<mDT>): Machine<mDT>;
get rng_seed(): number;
set rng_seed(to: number | undefined);
edges_between(from: string, to: string): JssmTransition<StateType, mDT>[];
/*********
*
Expand Down
19 changes: 16 additions & 3 deletions dist/es6/jssm.js
Expand Up @@ -4,7 +4,7 @@ import { FslDirections } from './jssm_types';
import { arrow_direction, arrow_left_kind, arrow_right_kind } from './jssm_arrow';
import { compile, make, wrap_parse } from './jssm_compiler';
import { theme_mapping, base_theme } from './jssm_theme';
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';
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';
import * as constants from './jssm_constants';
const { shapes, gviz_shapes, named_colors } = constants;
import { version, build_time } from './version'; // replaced from package.js in build
Expand Down Expand Up @@ -126,7 +126,7 @@ function state_style_condense(jssk) {
// TODO add a lotta docblock here
class Machine {
// whargarbl this badly needs to be broken up, monolith master
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 }) {
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 }) {
this._instance_name = instance_name;
this._state = start_states[0];
this._states = new Map();
Expand Down Expand Up @@ -212,6 +212,8 @@ class Machine {
this._history_length = history || 0;
this._history = new circular_buffer(this._history_length);
this._state_labels = new Map();
this._rng_seed = rng_seed !== null && rng_seed !== void 0 ? rng_seed : new Date().getTime();
this._rng = gen_splitmix32(this._rng_seed);
// consolidate the state declarations
if (state_declaration) {
state_declaration.map((state_decl) => {
Expand Down Expand Up @@ -1076,7 +1078,7 @@ class Machine {
return wtf;
}
probabilistic_transition() {
const selected = weighted_rand_select(this.probable_exits_for(this.state()));
const selected = weighted_rand_select(this.probable_exits_for(this.state()), undefined, this._rng);
return this.transition(selected.to);
}
probabilistic_walk(n) {
Expand Down Expand Up @@ -1419,6 +1421,17 @@ class Machine {
this.set_hook({ kind: 'post exit', from, handler });
return this;
}
get rng_seed() {
return this._rng_seed;
}
set rng_seed(to) {
if (typeof to === 'undefined') {
this._rng_seed = new Date().getTime();
}
else {
this._rng_seed = to;
}
}
// remove_hook(HookDesc: HookDescription) {
// throw new JssmError(this, 'TODO: Should remove hook here');
// }
Expand Down
4 changes: 3 additions & 1 deletion dist/es6/jssm_types.d.ts
Expand Up @@ -219,6 +219,7 @@ declare type JssmGenericConfig<StateType, DataType> = {
default_hooked_state_config?: JssmStateStyleKeyList;
default_terminal_state_config?: JssmStateStyleKeyList;
default_active_state_config?: JssmStateStyleKeyList;
rng_seed?: number | undefined;
};
declare type JssmCompileRule<StateType> = {
agg_as: string;
Expand Down Expand Up @@ -359,4 +360,5 @@ declare type JssmErrorExtendedInfo = {
requested_state?: StateType | undefined;
};
declare type JssmHistory<mDT> = circular_buffer<[StateType, mDT]>;
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 };
declare type JssmRng = () => number;
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 };
2 changes: 1 addition & 1 deletion dist/es6/jssm_util.js
Expand Up @@ -11,7 +11,7 @@ function arr_uniq_p(el, i, source) {
const array_box_if_string = n => typeof n === 'string' ? [n] : n;
// this is explicitly about other peoples' data, so it has to be weakly typed
/* eslint-disable flowtype/no-weak-types */
const weighted_rand_select = (options, probability_property = 'probability') => {
const weighted_rand_select = (options, probability_property = 'probability', rng) => {
if (!Array.isArray(options)) {
throw new TypeError('options must be a non-empty array of objects');
}
Expand Down

0 comments on commit e88d784

Please sign in to comment.