From c9b023a001f440b31fbbfafc1bf6f42d7db72463 Mon Sep 17 00:00:00 2001 From: bculkin2442 Date: Wed, 16 Sep 2015 20:41:23 -0400 Subject: Add lengthier example A lengthier example of random grammar usage. --- RGens/src/main/java/bjc/RGens/ZadronsPouch.java | 178 ++++++++++++++++++++++++ 1 file changed, 178 insertions(+) create mode 100644 RGens/src/main/java/bjc/RGens/ZadronsPouch.java (limited to 'RGens/src/main') diff --git a/RGens/src/main/java/bjc/RGens/ZadronsPouch.java b/RGens/src/main/java/bjc/RGens/ZadronsPouch.java new file mode 100644 index 0000000..1076599 --- /dev/null +++ b/RGens/src/main/java/bjc/RGens/ZadronsPouch.java @@ -0,0 +1,178 @@ +package bjc.RGens; + +import java.util.StringTokenizer; + +import bjc.utils.FunctionalStringTokenizer; +import bjc.utils.data.FunctionalList; +import bjc.utils.gen.RandomGrammar; + +public class ZadronsPouch { + public static void main(String[] args) { + ZadronsPouch zp = new ZadronsPouch(); + + for (int i = 0; i < 100; i++) { + FunctionalList ls = zp.wg.genList("", " "); + + StringBuilder sb = new StringBuilder(); + + ls.forEach(sp -> sb.append(sp)); + + System.out.println(sb.toString().replaceAll("\\s+", " ")); + } + } + + private RandomGrammar wg; + + public ZadronsPouch() { + wg = new RandomGrammar<>(); + + addRule("", "", "", "", "", + "", "", "", "", "", + "", "", ""); + + addEggRules(); + + addGloveRules(); + + addCrysSphereRules(); + + addRockRules(); + + addFigurineRules(); + + addVialRules(); + + addMiniWeaponRules(); + + addBagRules(); + + addCardRules(); + + addRopeRules(); + + addBoxRules(); + + addWandRules(); + } + + private void addWandRules() { + addRule("", " wand", "wand of ", + "canceling wand"); + addRule("", "magic missile", "", "", + "gusting", "life-detecting", "zadron"); + addRule("", "frost", "fire", "lightning", "fear", + "illumination", "polymorphing", "conjuration", + "paralyzing"); + addRule("", " detecting"); + addRule("", "magic", "enemy", "secret door/trap"); + } + + private void addBagRules() { + addRule("", "bag of ", " sack", + " purse"); + addRule("", "holding", "tricks", "useful items", + "devouring", "dwarf-kind", "invisible cloth", + "monster summoning"); + addRule("", "lunch", "recursive"); + addRule("", "everfull"); + } + + private void addBoxRules() { + addRule("", " box", "cube of "); + addRule("", "limited-force", "frost-resisting", + "morphing", "self-destructing", "pandora", "panicking"); + } + + private void addCardRules() { + addRule("", "card of ", " card"); + addRule("", "fate", "teleporting", "elusive treasure", + "spell-storing", "many-things", "imprisoning", "messaging", + "bounty"); + } + + private void addCrysSphereRules() { + addRule("", " spheres", + " sphere", "lens of ", + " crystal", "crystal of ", + "crystal ball", "crystal ball of "); + addRule("", "microphonic", "seeing-eye"); + addRule("", "detection"); + addRule("", "prison", "radar"); + addRule("", "jumping"); + } + + private void addEggRules() { + addRule("", " egg"); + addRule("", "copper", "stone", "golden", "white", + "white/pink", "glass"); + } + + private void addFigurineRules() { + addRule("", " "); + addRule("", "golden", "onyx", "serpentine", "ivory", + "marble", "bronze", "jade", "limestone"); + addRule("", "lion", "dog", "owl", "goat", "elephant", + "warrior", "palace", "leprechaun"); + } + + private void addGloveRules() { + addRule("", "gauntlets of ", + "gloves of ", " gloves"); + addRule("", "dexterity", "power"); + addRule("", "pushing", "choking", "bigby", "stunning"); + } + + private void addMiniWeaponRules() { + addRule("", "minature ", + "small ", "tiny ", + " sling", ""); + addRule("", "boomerang", "arrow", "net", "catapult", + "hammer", "sword", "club"); + addRule("", "seeking"); + } + + private void addRockRules() { + addRule("", " pebble", "stone of ", + " stone", "brick of ", + " geode"); + addRule("", "inscribed", "elemental control"); + addRule("", "good-luck", "weight", "blind-defense", + "metal-clinging"); + addRule("", "flying"); + addRule("", "ioun"); + } + + private void addRopeRules() { + addRule("", " rope", "rope of ", + "ball of "); + addRule("", "trick", "entangling", "climbing", + "dancing", "tripping", "snaring", "levitating", + "self-entangling"); + addRule("", "endless"); + addRule("", "string", "yarn"); + } + + private void addRule(String rule, String... cases) { + FunctionalList> cses = new FunctionalList<>(); + + for (String string : cases) { + cses.add( + FunctionalList.fromString( + new FunctionalStringTokenizer( + new StringTokenizer(string, " ")), + s -> s)); + } + + wg.makeRule(rule, cses); + } + + private void addVialRules() { + addRule("", "vial of ", " vial", + " bottle", " flask"); + addRule("", "holding", "trapping", "experience", + "unnatural regeneration"); + addRule("", "ever-smoking", "wheezing", + "blank potion"); + addRule("", "iron"); + } +} -- cgit v1.2.3