From ebe04a4223e3945264013fdc8b27b2e55fc6fb74 Mon Sep 17 00:00:00 2001 From: Ben Culkin Date: Sat, 13 Mar 2021 07:20:54 -0500 Subject: Reorganize examples a bit The random generation examples are now in a more appropriate package. Also, moved another random generation example from RGens to here, since it didn't use any RGens specific things --- .../java/bjc/utils/examples/gen/DiabloItemGen.java | 96 +++++++++ .../utils/examples/gen/RandomStringExamples.java | 67 +++++++ .../java/bjc/utils/examples/gen/ZadronsPouch.java | 220 +++++++++++++++++++++ .../bjc/utils/examples/rangen/DiabloItemGen.java | 96 --------- .../examples/rangen/RandomStringExamples.java | 67 ------- 5 files changed, 383 insertions(+), 163 deletions(-) create mode 100644 base/src/examples/java/bjc/utils/examples/gen/DiabloItemGen.java create mode 100644 base/src/examples/java/bjc/utils/examples/gen/RandomStringExamples.java create mode 100644 base/src/examples/java/bjc/utils/examples/gen/ZadronsPouch.java delete mode 100644 base/src/examples/java/bjc/utils/examples/rangen/DiabloItemGen.java delete mode 100644 base/src/examples/java/bjc/utils/examples/rangen/RandomStringExamples.java (limited to 'base/src/examples/java/bjc/utils') diff --git a/base/src/examples/java/bjc/utils/examples/gen/DiabloItemGen.java b/base/src/examples/java/bjc/utils/examples/gen/DiabloItemGen.java new file mode 100644 index 0000000..8699527 --- /dev/null +++ b/base/src/examples/java/bjc/utils/examples/gen/DiabloItemGen.java @@ -0,0 +1,96 @@ +package bjc.utils.examples.gen; + +import bjc.funcdata.FunctionalStringTokenizer; +import bjc.funcdata.ListEx; +import bjc.utils.gen.WeightedGrammar; + +/** + * Example showing how to use the weighted random number generator. + * + * @author ben + * + */ +public class DiabloItemGen { + private static WeightedGrammar rules = new WeightedGrammar<>(); + + private static void addCase(final String ruleName, final int probability, + final String ruleParts) { + final ListEx parts = FunctionalStringTokenizer.fromString(ruleParts) + .toList(strang -> strang); + + rules.addCase(ruleName, probability, parts); + } + + private static void addInfixRules() { + final String rn = ""; + + addCase(rn, 60, "sword"); + addCase(rn, 50, "armor"); + addCase(rn, 40, "rune"); + addCase(rn, 30, "scroll"); + addCase(rn, 20, "potion"); + addCase(rn, 10, "helm"); + } + + private static void addItemRules() { + final String rn = ""; + + addCase(rn, 10, ""); + addCase(rn, 20, " "); + addCase(rn, 30, " "); + addCase(rn, 40, " "); + addCase(rn, 50, " "); + addCase(rn, 60, " "); + } + + private static void addPrefixRules() { + final String rn = ""; + + addCase(rn, 60, "sturdy"); + addCase(rn, 50, "fine"); + addCase(rn, 40, "strong"); + addCase(rn, 30, "azure"); + addCase(rn, 20, "crimson"); + addCase(rn, 10, "phasing"); + } + + private static void addSuffixRules() { + final String rn = ""; + + addCase(rn, 60, "of Health"); + addCase(rn, 50, "of Wealth"); + addCase(rn, 40, "of Life"); + addCase(rn, 30, "of the Jackal"); + addCase(rn, 20, "of Vitality"); + addCase(rn, 10, "of Ability"); + } + + /** + * Main Method + * + * @param args + * Unused CLI args + */ + public static void main(final String[] args) { + rules.addRule(""); + addItemRules(); + + rules.addRule(""); + addSuffixRules(); + + rules.addRule(""); + addPrefixRules(); + + rules.addRule(""); + addInfixRules(); + + for (int i = 0; i < 100; i++) { + final ListEx ls = rules.generateListValues("", " "); + + final StringBuilder sb = new StringBuilder(); + ls.forEach(sb::append); + + System.out.println(sb.toString().replaceAll("\\s+", " ")); + } + } +} diff --git a/base/src/examples/java/bjc/utils/examples/gen/RandomStringExamples.java b/base/src/examples/java/bjc/utils/examples/gen/RandomStringExamples.java new file mode 100644 index 0000000..5e71ce0 --- /dev/null +++ b/base/src/examples/java/bjc/utils/examples/gen/RandomStringExamples.java @@ -0,0 +1,67 @@ +package bjc.utils.examples.gen; + +import bjc.funcdata.FunctionalList; +import bjc.funcdata.FunctionalStringTokenizer; +import bjc.funcdata.ListEx; +import bjc.utils.gen.RandomGrammar; + +/** + * Examples of random grammar + * + * @author ben + * + */ +public class RandomStringExamples { + private static RandomGrammar rg; + + private static void addRule(final String rule, final String... cases) { + final ListEx> cses = new FunctionalList<>(); + + for (final String strang : cases) { + final ListEx lst + = FunctionalStringTokenizer.fromString(strang).toList(s -> s); + + cses.add(lst); + } + + rg.makeRule(rule, cses); + } + + /** + * Main method + * + * @param args + * Unused CLI args + */ + public static void main(final String[] args) { + rg = new RandomGrammar<>(); + + addRule("", " ", + " thinks that I am ", "I ", + "You think that I am "); + + addRule("", "dancing", "eating", "sleeping"); + + addRule("", "", "life", "my computer", "my friends"); + + addRule("", "hate", "am jealous of", "love"); + + addRule("", "hates", "loves"); + + addRule("", "my sister", "my father", "my girlfriend", + "the man next door"); + + addRule("", "creative", "intelligent"); + + addRule("", "", " with ", ""); + + for (int i = 0; i < 10; i++) { + final ListEx ls = rg.generateListValues("", " "); + + final StringBuilder sb = new StringBuilder(); + ls.forEach(sb::append); + + System.out.println(sb.toString().replaceAll("\\s+", " ")); + } + } +} diff --git a/base/src/examples/java/bjc/utils/examples/gen/ZadronsPouch.java b/base/src/examples/java/bjc/utils/examples/gen/ZadronsPouch.java new file mode 100644 index 0000000..184d127 --- /dev/null +++ b/base/src/examples/java/bjc/utils/examples/gen/ZadronsPouch.java @@ -0,0 +1,220 @@ +package bjc.utils.examples.gen; + +import bjc.funcdata.FunctionalList; +import bjc.funcdata.FunctionalStringTokenizer; +import bjc.funcdata.ListEx; +import bjc.utils.gen.RandomGrammar; + +/** + * Example showing code manipulate of random grammars + * + * @author ben + */ +public class ZadronsPouch { + /** + * Main method for running application + * + * @param args + * Unused CLI args + */ + public static void main(String[] args) { + ZadronsPouch zp = new ZadronsPouch(); + + for (int i = 0; i < 100; i++) { + ListEx ls = zp.grammar.generateListValues("[item]", " "); + + StringBuilder sb = new StringBuilder(); + + ls.forEach(sp -> sb.append(sp)); + + System.out.println(sb.toString().replaceAll("\\s+", " ")); + } + } + + private RandomGrammar grammar; + + /** Create a new instance with a grammar */ + public ZadronsPouch() { + grammar = new RandomGrammar<>(); + + /* + * @NOTE + * Should there be some sort of builder sort of interface? + */ + addRule("[item]", + "[egg]", "[glove]", "[crys-sphere]", "[rock]", + "[figurine]", "[vial]", "[mini-weapon]", "[bag]", + "[card]", "[rope]", "[box]", "[wand]"); + + addEggRules(); + addGloveRules(); + addCrysSphereRules(); + addRockRules(); + + addFigurineRules(); + addVialRules(); + addMiniWeaponRules(); + addBagRules(); + + addCardRules(); + addRopeRules(); + addBoxRules(); + addWandRules(); + } + + private void addBagRules() { + addRule("[bag]", + "bag of [bag-type]", "[sack-type] sack", "[purse-type] purse"); + addRule("[bag-type]", + "holding", "tricks", "useful items", + "devouring", "dwarf-kind", "invisible cloth", + "monster summoning"); + addRule("[sack-type]", + "lunch", "recursive"); + addRule("[purse-type]", + "everfull"); + } + + private void addBoxRules() { + addRule("[box]", + "[box-type] box", "cube of [box-type]"); + addRule("[box-type]", + "limited-force", "frost-resisting", "morphing", + "self-destructing", "pandora", "panicking"); + } + + private void addCardRules() { + addRule("[card]", + "card of [card-type]", "[card-type] card"); + addRule("[card-type]", + "fate", "teleporting", "elusive treasure", "spell-storing", + "many-things", "imprisoning", "messaging", "bounty"); + } + + private void addCrysSphereRules() { + addRule("[crys-sphere]", + "[sphere-type] spheres", "[sphere-type] sphere", + "lens of [lens-type]", "[crystal-type] crystal", + "crystal of [crystal-type]", "crystal ball", + "crystal ball of [crys-suffix]"); + addRule("[sphere-type]", + "microphonic", "seeing-eye"); + addRule("[lens-type]", + "detection"); + addRule("[crystal-type]", + "prison", "radar"); + addRule("[crys-suffix]", + "jumping"); + } + + private void addEggRules() { + addRule("[egg]", + "[egg-type] egg"); + addRule("[egg-type]", + "copper", "stone", "golden", + "white", "white/pink", "glass"); + } + + private void addFigurineRules() { + addRule("[figurine]", + "[fig-material] [fig-animal]"); + addRule("[fig-material]", + "golden", "onyx", "serpentine", "ivory", + "marble", "bronze", "jade", "limestone"); + addRule("[fig-animal]", + "lion", "dog", "owl", "goat", + "elephant", "warrior", "palace", "leprechaun"); + } + + private void addGloveRules() { + addRule("[glove]", + "gauntlets of [gauntlet-type]", + "gloves of [glove-type]", + "[glove-type] gloves"); + addRule("[gauntlet-type]", + "dexterity", "power"); + addRule("[glove-type]", + "pushing", "choking", "bigby", "stunning"); + } + + private void addMiniWeaponRules() { + addRule("[mini-weapon]", + "minature [weapon-type]", "small [weapon-type]", + "tiny [weapon-type]", "[sling-type] sling", + "[weapon-type]"); + addRule("[weapon-type]", + "boomerang", "arrow", "net", + "catapult", "hammer", "sword", "club"); + addRule("[sling-type]", + "seeking"); + } + + private void addRockRules() { + addRule("[rock]", + "[pebble-type] pebble", "stone of [stone-type]", + "[stone-type] stone", "brick of [brick-type]", + "[geode-type] geode"); + addRule("[pebble-type]", + "inscribed", "elemental control"); + addRule("[stone-type]", + "good-luck", "weight", + "blind-defense", "metal-clinging"); + addRule("[brick-type]", + "flying"); + addRule("[geode-type]", + "ioun"); + } + + private void addRopeRules() { + addRule("[rope]", + "[rope-type] rope", "rope of [rope-type]", + "ball of [string-type] [string-kind]"); + addRule("[rope-type]", + "trick", "entangling", "climbing", "dancing", + "tripping", "snaring", "levitating", "self-entangling"); + addRule("[string-type]", + "endless"); + addRule("[string-kind]", + "string", "yarn"); + } + + private void addRule(String rule, String... cases) { + ListEx> cses = new FunctionalList<>(); + + for (String strang : cases) { + cses.add(FunctionalStringTokenizer.fromString(strang).toList(s -> s)); + } + + grammar.makeRule(rule, cses); + } + + private void addVialRules() { + addRule("[vial]", + "vial of [vial-type]", "[vial-type] vial", + "[bottle-type] bottle", "[flask-type] flask"); + addRule("[vial-type]", + "holding", "trapping", + "experience", "unnatural regeneration"); + addRule("[bottle-type]", + "ever-smoking", "wheezing", + "blank potion"); + addRule("[flask-type]", + "iron"); + } + + private void addWandRules() { + addRule("[wand]", + "[wand-type] wand", "wand of [wand-type]", + "canceling [wand-type] wand"); + addRule("[wand-type]", + "magic missile", "[spell-1]", "[spell-2]", + "gusting", "life-detecting", "zadron"); + addRule("[spell-1]", + "frost", "fire", "lightning", "fear", + "illumination", "polymorphing", "conjuration", "paralyzing"); + addRule("[spell-2]", + "[spell2-type] detecting"); + addRule("[spell2-type]", + "magic", "enemy", "secret door/trap"); + } +} diff --git a/base/src/examples/java/bjc/utils/examples/rangen/DiabloItemGen.java b/base/src/examples/java/bjc/utils/examples/rangen/DiabloItemGen.java deleted file mode 100644 index 784ff03..0000000 --- a/base/src/examples/java/bjc/utils/examples/rangen/DiabloItemGen.java +++ /dev/null @@ -1,96 +0,0 @@ -package bjc.utils.examples.rangen; - -import bjc.funcdata.FunctionalStringTokenizer; -import bjc.funcdata.ListEx; -import bjc.utils.gen.WeightedGrammar; - -/** - * Example showing how to use the weighted random number generator. - * - * @author ben - * - */ -public class DiabloItemGen { - private static WeightedGrammar rules = new WeightedGrammar<>(); - - private static void addCase(final String ruleName, final int probability, - final String ruleParts) { - final ListEx parts = FunctionalStringTokenizer.fromString(ruleParts) - .toList(strang -> strang); - - rules.addCase(ruleName, probability, parts); - } - - private static void addInfixRules() { - final String rn = ""; - - addCase(rn, 60, "sword"); - addCase(rn, 50, "armor"); - addCase(rn, 40, "rune"); - addCase(rn, 30, "scroll"); - addCase(rn, 20, "potion"); - addCase(rn, 10, "helm"); - } - - private static void addItemRules() { - final String rn = ""; - - addCase(rn, 10, ""); - addCase(rn, 20, " "); - addCase(rn, 30, " "); - addCase(rn, 40, " "); - addCase(rn, 50, " "); - addCase(rn, 60, " "); - } - - private static void addPrefixRules() { - final String rn = ""; - - addCase(rn, 60, "sturdy"); - addCase(rn, 50, "fine"); - addCase(rn, 40, "strong"); - addCase(rn, 30, "azure"); - addCase(rn, 20, "crimson"); - addCase(rn, 10, "phasing"); - } - - private static void addSuffixRules() { - final String rn = ""; - - addCase(rn, 60, "of Health"); - addCase(rn, 50, "of Wealth"); - addCase(rn, 40, "of Life"); - addCase(rn, 30, "of the Jackal"); - addCase(rn, 20, "of Vitality"); - addCase(rn, 10, "of Ability"); - } - - /** - * Main Method - * - * @param args - * Unused CLI args - */ - public static void main(final String[] args) { - rules.addRule(""); - addItemRules(); - - rules.addRule(""); - addSuffixRules(); - - rules.addRule(""); - addPrefixRules(); - - rules.addRule(""); - addInfixRules(); - - for (int i = 0; i < 100; i++) { - final ListEx ls = rules.generateListValues("", " "); - - final StringBuilder sb = new StringBuilder(); - ls.forEach(sb::append); - - System.out.println(sb.toString().replaceAll("\\s+", " ")); - } - } -} diff --git a/base/src/examples/java/bjc/utils/examples/rangen/RandomStringExamples.java b/base/src/examples/java/bjc/utils/examples/rangen/RandomStringExamples.java deleted file mode 100644 index 8458de7..0000000 --- a/base/src/examples/java/bjc/utils/examples/rangen/RandomStringExamples.java +++ /dev/null @@ -1,67 +0,0 @@ -package bjc.utils.examples.rangen; - -import bjc.funcdata.FunctionalList; -import bjc.funcdata.FunctionalStringTokenizer; -import bjc.funcdata.ListEx; -import bjc.utils.gen.RandomGrammar; - -/** - * Examples of random grammar - * - * @author ben - * - */ -public class RandomStringExamples { - private static RandomGrammar rg; - - private static void addRule(final String rule, final String... cases) { - final ListEx> cses = new FunctionalList<>(); - - for (final String strang : cases) { - final ListEx lst - = FunctionalStringTokenizer.fromString(strang).toList(s -> s); - - cses.add(lst); - } - - rg.makeRule(rule, cses); - } - - /** - * Main method - * - * @param args - * Unused CLI args - */ - public static void main(final String[] args) { - rg = new RandomGrammar<>(); - - addRule("", " ", - " thinks that I am ", "I ", - "You think that I am "); - - addRule("", "dancing", "eating", "sleeping"); - - addRule("", "", "life", "my computer", "my friends"); - - addRule("", "hate", "am jealous of", "love"); - - addRule("", "hates", "loves"); - - addRule("", "my sister", "my father", "my girlfriend", - "the man next door"); - - addRule("", "creative", "intelligent"); - - addRule("", "", " with ", ""); - - for (int i = 0; i < 10; i++) { - final ListEx ls = rg.generateListValues("", " "); - - final StringBuilder sb = new StringBuilder(); - ls.forEach(sb::append); - - System.out.println(sb.toString().replaceAll("\\s+", " ")); - } - } -} -- cgit v1.2.3