From 89ff0c45f60d0ed38e6bcd67b8925b0dee7cecc0 Mon Sep 17 00:00:00 2001 From: Aaron Taylor Date: Thu, 10 Jun 2021 15:24:18 -0700 Subject: [PATCH] Updated WolframAutomata's rule related CLI flags to match README. --- hacks/WolframAutomata/README.md | 7 +------ hacks/WolframAutomata/WolframAutomata.c | 26 ++++++++++++------------- 2 files changed, 13 insertions(+), 20 deletions(-) diff --git a/hacks/WolframAutomata/README.md b/hacks/WolframAutomata/README.md index 751108f..6bbd56a 100644 --- a/hacks/WolframAutomata/README.md +++ b/hacks/WolframAutomata/README.md @@ -111,12 +111,7 @@ from `curated_ruleset_list[]` in `WolframAutomata.c`. from a curated list. Note that many rules are visually uninteresting. - **`-rule N`**: Select a specific rule where `N` is a Wolfram number. Values - from 1-255 inclusive are valid. - -Note that, although Rule 0 is a valid set of rules, it is reused as a null -value by the program and thus is ignored if passed as `-rule 0`. If you want to -see Rule 0, choose any starting conditions you desire, then turn off your -monitor and enjoy the resulting simulation. + from 0-255 inclusive are valid. CLI: Simulation Speed diff --git a/hacks/WolframAutomata/WolframAutomata.c b/hacks/WolframAutomata/WolframAutomata.c index fe3ab1f..01246f2 100644 --- a/hacks/WolframAutomata/WolframAutomata.c +++ b/hacks/WolframAutomata/WolframAutomata.c @@ -51,8 +51,8 @@ struct state { size_t admiration_delay; /* ...in seconds. */ /* The following values correspond directly to independent CLI options. */ - Bool rule_random; - uint8_t rule_requested; /* Note: Repurposing Rule 0 as null value. */ + Bool random_rule; + int requested_rule; int cell_size; /* If cell_size=N then draw NxN pixels per cell. */ int delay_microsec; /* ...between calls to WolframAutomata_draw(). */ int num_generations; /* Reset simulation after this many generations. */ @@ -387,21 +387,19 @@ WolframAutomata_init(Display * dpy, Window win) } /* Time to figure out which rule to use for this simulation. */ - /* We ignore any weirdness resulting from the following cast since every */ + /* We ignore any weirdness resulting from the following casts since every */ /* bit pattern is also a valid rule; if the user provides weird input, */ /* then we'll return weird (but well-defined!) output. */ - state->rule_requested = (uint8_t) get_integer_resource(state->dpy, "rule-requested", "Integer"); - state->rule_random = get_boolean_resource(state->dpy, "rule-random", "Boolean"); + state->requested_rule = get_integer_resource(state->dpy, "rule", "Integer"); + state->random_rule = get_boolean_resource(state->dpy, "random-rule", "Boolean"); /* Through the following set of branches, we enforce CLI flag precedence. */ - if (state->rule_random) { + if (state->random_rule) { /* If this flag is set, the user wants truly random rules rather than */ /* random rules from a curated list. */ state->rule_number = (uint8_t) random(); - } else if (state->rule_requested != 0) { - /* Rule 0 is terribly uninteresting, so we are reusing it as a 'null' */ - /* value and hoping nobody notices. Finding a non-zero value means */ - /* the user requested a specific rule. Use it. */ - state->rule_number = state->rule_requested; + } else if (state->requested_rule != -1) { + /* The user requested a specific rule. Use it. */ + state->rule_number = (uint8_t) state->requested_rule; } else { /* No command-line options were specified, so select rules randomly */ /* from a curated list. */ @@ -513,7 +511,7 @@ static const char * WolframAutomata_defaults[] = { "*random-delay: False", "*random-length: False", "*random-rule: False", - "*rule-requested: 0", + "*rule: -1", 0 }; @@ -528,8 +526,8 @@ static XrmOptionDescRec WolframAutomata_options[] = { { "-random-cell-size", ".random-cell-size", XrmoptionNoArg, "True" }, { "-random-delay", ".random-delay", XrmoptionNoArg, "True" }, { "-random-length", ".random-length", XrmoptionNoArg, "True" }, - { "-random-rule", ".rule-random", XrmoptionNoArg, "True" }, - { "-rule", ".rule-requested", XrmoptionSepArg, 0 }, + { "-random-rule", ".random-rule", XrmoptionNoArg, "True" }, + { "-rule", ".rule", XrmoptionSepArg, 0 }, { 0, 0, 0, 0 } }; -- 2.20.1