import java.util.ArrayList;
import java.util.List;
import java.util.TreeMap;

class Vocabulary {
  static class Wac {
    String aword;
    int acode;

    Wac (String aword, int acode) {
      this.aword = aword;
      this.acode = acode;
    }
  }

  /*
    Duplicate words with different action codes:
      fee	  2025, 3001
      fie	  2025, 3002
      foe	  2025, 3003
      foo	  2025, 3004
      fum	  2025, 3005
      plant	1024, 1025
      rod	  1005, 1006
      steps	1007, 34
      troll	1033, 1034

    Action codes:
      // codes < 1000 are locations to move to (if permitted)
      2	  hill, road
      3	  enter
      4	  downstream, upstream
      6	  forest
      7	  forward, onward
      8	  back, retreat, return
      9	  valley
      10	stairs
      11	exit, leave, out, outside
      12	building, house
      13	gully
      14	stream
      15	rock
      16	bed
      17	crawl
      18	cobblestone
      19	in, inside, inward
      20	surface
      21	nowhere, null
      22	dark
      23	passage, tunnel
      24	low
      25	canyon
      26	awkward
      27	giant
      28	view
      29	above, ascend, u, up, upward
      30	d, descend, down, downward
      31	pit
      32	outdoors
      33	crack
      34	steps
      35	dome
      36	left
      37	right
      38	hall
      39	jump
      40	barren
      41	over
      42	across
      43	e, east
      44	w, west
      45	n, north
      46	s, south
      47	ne
      48	se
      49	sw
      50	nw
      51	debris
      52	hole
      53	wall
      54	broken
      55	y2
      56	climb
      57	describe, examine, look, touch
      58	floor
      59	room
      60	slit
      61	slab
      62	xyzzy
      63	depression
      64	entrance
      65	plugh
      66	secret
      67	cave
      69	cross
      70	bedquilt
      71	plover
      72	oriental
      73	cavern
      74	shell
      75	reservoir
      76	main, office
      77	fork
      // action codes >= 1000 subtract 1000 to get item code
      1001	key, keys
      1002	headlamp, lamp, lantern
      1003	grate
      1004	cage
      1005	rod
      1006	rod
      1007	steps
      1008	bird
      1009	door
      1010	pillow, velvet
      1011	snake
      1012	fissure
      1013	tablet
      1014	clam
      1015	oyster
      1016	spelunker today, issue, magazine, spelunker
      1017	dwarf, dwarves
      1018	knife, knives
      1019	food, rations
      1020	bottle, jar
      1021	h2o, water
      1022	oil
      1023	mirror
      1024	beans, plant
      1025	plant
      1026	stalactite
      1027	figure, shadow
      1028	axe
      1029	drawing
      1030	pirate
      1031	dragon
      1032	chasm
      1033	troll
      1034	troll
      1035	bear
      1036	message
      1037	geyser, volcano
      1038	machine, vending
      1039	batteries, battery
      1040	carpet, moss
      1050	gold, nugget
      1051	diamonds
      1052	bars, silver
      1053	jewel, jewelry, jewels
      1054	coins
      1055	box, chest, treasure
      1056	egg, eggs, nest
      1057	trident
      1058	ming, pottery, shard, vase
      1059	emerald
      1060	platinum, pyramid
      1061	pearl
      1062	persian, rug
      1063	spice, spices
      1064	chain
      // action codes >= 2000 subtract 2000 to get action verb code
      2001	capture, carry, catch, get, keep, steal, take, tote
      2002	discard, drop, dump, free, release
      2003	chant, mumble, say, sing, utter
      2004	open, unlock
      2005	nothing
      2006	close, lock
      2007	light, on
      2008	extinguish, off
      2009	shake, swing, wave
      2010	calm, placate, tame
      2011	continue, explore, follow, go, goto, proceed, run, travel, turn, walk
      2012	attack, fight, hit, kill, strike
      2013	pour
      2014	devour, eat
      2015	drink
      2016	rub
      2017	throw, toss
      2018	quit
      2019	find
      2020	inventory
      2021	feed
      2022	fill
      2023	blast, blowup, detonate, ignite
      2024	score
      2025	fee, fie, foe, foo, fum
      2026	brief
      2027	peruse, read
      2028	break, shatter, smash
      2029	disturb, wake
      2030	pause, save, suspend
      2031	hours
      2032	log
      // action codes >= 3000 subtract 3000 to get action codes that trigger special responses
      3001	fee
      3002	fie
      3003	foe
      3004	foo
      3005	fum
      3050	abra, abracadabra, hocus, opensesame, pocus, sesame, shazam
      3051	?, help
      3064	tree, trees
      3066	dig, excavate
      3068	lost
      3069	mist
      3079	crap, damn, damnit, fuck, shit
      3139	stop
      3142	info, information
      3147	swim
  */

  // Note: words must be in alphabetical order for binary search
  static final Wac[] wc = {
    new Wac("spelunker today", 1016),
    new Wac("?", 3051),
    new Wac("above", 29),
    new Wac("abra", 3050),
    new Wac("abracadabra", 3050),
    new Wac("across", 42),
    new Wac("ascend", 29),
    new Wac("attack", 2012),
    new Wac("awkward", 26),
    new Wac("axe", 1028),
    new Wac("back", 8),
    new Wac("barren", 40),
    new Wac("bars", 1052),
    new Wac("batteries", 1039),
    new Wac("battery", 1039),
    new Wac("beans", 1024),
    new Wac("bear", 1035),
    new Wac("bed", 16),
    new Wac("bedquilt", 70),
    new Wac("bird", 1008),
    new Wac("blast", 2023),
    new Wac("blowup", 2023),
    new Wac("bottle", 1020),
    new Wac("box", 1055),
    new Wac("break", 2028),
    new Wac("brief", 2026),
    new Wac("broken", 54),
    new Wac("building", 12),
    new Wac("cage", 1004),
    new Wac("calm", 2010),
    new Wac("canyon", 25),
    new Wac("capture", 2001),
    new Wac("carpet", 1040),
    new Wac("carry", 2001),
    new Wac("catch", 2001),
    new Wac("cave", 67),
    new Wac("cavern", 73),
    new Wac("chain", 1064),
    new Wac("chant", 2003),
    new Wac("chasm", 1032),
    new Wac("chest", 1055),
    new Wac("clam", 1014),
    new Wac("climb", 56),
    new Wac("close", 2006),
    new Wac("cobblestone", 18),
    new Wac("coins", 1054),
    new Wac("continue", 2011),
    new Wac("crack", 33),
    new Wac("crap", 3079),
    new Wac("crawl", 17),
    new Wac("cross", 69),
    new Wac("d", 30),
    new Wac("damn", 3079),
    new Wac("damnit", 3079),
    new Wac("dark", 22),
    new Wac("debris", 51),
    new Wac("depression", 63),
    new Wac("descend", 30),
    new Wac("describe", 57),
    new Wac("detonate", 2023),
    new Wac("devour", 2014),
    new Wac("diamonds", 1051),
    new Wac("dig", 3066),
    new Wac("discard", 2002),
    new Wac("disturb", 2029),
    new Wac("dome", 35),
    new Wac("door", 1009),
    new Wac("down", 30),
    new Wac("downstream", 4),
    new Wac("downward", 30),
    new Wac("dragon", 1031),
    new Wac("drawing", 1029),
    new Wac("drink", 2015),
    new Wac("drop", 2002),
    new Wac("dump", 2002),
    new Wac("dwarf", 1017),
    new Wac("dwarves", 1017),
    new Wac("e", 43),
    new Wac("east", 43),
    new Wac("eat", 2014),
    new Wac("egg", 1056),
    new Wac("eggs", 1056),
    new Wac("emerald", 1059),
    new Wac("enter", 3),
    new Wac("entrance", 64),
    new Wac("examine", 57),
    new Wac("excavate", 3066),
    new Wac("exit", 11),
    new Wac("explore", 2011),
    new Wac("extinguish", 2008),
    new Wac("fee", 2025),
    new Wac("fee", 3001),
    new Wac("feed", 2021),
    new Wac("fie", 2025),
    new Wac("fie", 3002),
    new Wac("fight", 2012),
    new Wac("figure", 1027),
    new Wac("fill", 2022),
    new Wac("find", 2019),
    new Wac("fissure", 1012),
    new Wac("floor", 58),
    new Wac("foe", 2025),
    new Wac("foe", 3003),
    new Wac("follow", 2011),
    new Wac("foo", 2025),
    new Wac("foo", 3004),
    new Wac("food", 1019),
    new Wac("forest", 6),
    new Wac("fork", 77),
    new Wac("forward", 7),
    new Wac("free", 2002),
    new Wac("fuck", 3079),
    new Wac("fum", 2025),
    new Wac("fum", 3005),
    new Wac("get", 2001),
    new Wac("geyser", 1037),
    new Wac("giant", 27),
    new Wac("go", 2011),
    new Wac("gold", 1050),
    new Wac("goto", 2011),
    new Wac("grate", 1003),
    new Wac("gully", 13),
    new Wac("h2o", 1021),
    new Wac("hall", 38),
    new Wac("headlamp", 1002),
    new Wac("help", 3051),
    new Wac("hill", 2),
    new Wac("hit", 2012),
    new Wac("hocus", 3050),
    new Wac("hole", 52),
    new Wac("hours", 2031),
    new Wac("house", 12),
    new Wac("ignite", 2023),
    new Wac("in", 19),
    new Wac("info", 3142),
    new Wac("information", 3142),
    new Wac("inside", 19),
    new Wac("inventory", 2020),
    new Wac("inward", 19),
    new Wac("issue", 1016),
    new Wac("jar", 1020),
    new Wac("jewel", 1053),
    new Wac("jewelry", 1053),
    new Wac("jewels", 1053),
    new Wac("jump", 39),
    new Wac("keep", 2001),
    new Wac("key", 1001),
    new Wac("keys", 1001),
    new Wac("kill", 2012),
    new Wac("knife", 1018),
    new Wac("knives", 1018),
    new Wac("lamp", 1002),
    new Wac("lantern", 1002),
    new Wac("leave", 11),
    new Wac("left", 36),
    new Wac("light", 2007),
    new Wac("lock", 2006),
    new Wac("log", 2032),
    new Wac("look", 57),
    new Wac("lost", 3068),
    new Wac("low", 24),
    new Wac("machine", 1038),
    new Wac("magazine", 1016),
    new Wac("main", 76),
    new Wac("message", 1036),
    new Wac("ming", 1058),
    new Wac("mirror", 1023),
    new Wac("mist", 3069),
    new Wac("moss", 1040),
    new Wac("mumble", 2003),
    new Wac("n", 45),
    new Wac("ne", 47),
    new Wac("nest", 1056),
    new Wac("north", 45),
    new Wac("nothing", 2005),
    new Wac("nowhere", 21),
    new Wac("nugget", 1050),
    new Wac("null", 21),
    new Wac("nw", 50),
    new Wac("off", 2008),
    new Wac("office", 76),
    new Wac("oil", 1022),
    new Wac("on", 2007),
    new Wac("onward", 7),
    new Wac("open", 2004),
    new Wac("opensesame", 3050),
    new Wac("oriental", 72),
    new Wac("out", 11),
    new Wac("outdoors", 32),
    new Wac("outside", 11),
    new Wac("over", 41),
    new Wac("oyster", 1015),
    new Wac("passage", 23),
    new Wac("pause", 2030),
    new Wac("pearl", 1061),
    new Wac("persian", 1062),
    new Wac("peruse", 2027),
    new Wac("pillow", 1010),
    new Wac("pirate", 1030),
    new Wac("pit", 31),
    new Wac("placate", 2010),
    new Wac("plant", 1024),
    new Wac("plant", 1025),
    new Wac("platinum", 1060),
    new Wac("plover", 71),
    new Wac("plugh", 65),
    new Wac("pocus", 3050),
    new Wac("pottery", 1058),
    new Wac("pour", 2013),
    new Wac("proceed", 2011),
    new Wac("pyramid", 1060),
    new Wac("qqq", 78),                 // test word
    new Wac("quit", 2018),
    new Wac("rations", 1019),
    new Wac("read", 2027),
    new Wac("release", 2002),
    new Wac("reservoir", 75),
    new Wac("retreat", 8),
    new Wac("return", 8),
    new Wac("right", 37),
    new Wac("road", 2),
    new Wac("rock", 15),
    new Wac("rod", 1005),
    new Wac("rod", 1006),
    new Wac("room", 59),
    new Wac("rub", 2016),
    new Wac("rug", 1062),
    new Wac("run", 2011),
    new Wac("s", 46),
    new Wac("save", 2030),
    new Wac("say", 2003),
    new Wac("score", 2024),
    new Wac("se", 48),
    new Wac("secret", 66),
    new Wac("sesame", 3050),
    new Wac("shadow", 1027),
    new Wac("shake", 2009),
    new Wac("shard", 1058),
    new Wac("shatter", 2028),
    new Wac("shazam", 3050),
    new Wac("shell", 74),
    new Wac("shit", 3079),
    new Wac("silver", 1052),
    new Wac("sing", 2003),
    new Wac("slab", 61),
    new Wac("slit", 60),
    new Wac("smash", 2028),
    new Wac("snake", 1011),
    new Wac("south", 46),
    new Wac("spelunker", 1016),
    new Wac("spice", 1063),
    new Wac("spices", 1063),
    new Wac("stairs", 10),
    new Wac("stalactite", 1026),
    new Wac("steal", 2001),
    new Wac("steps", 1007),
    new Wac("steps", 34),
    new Wac("stop", 3139),
    new Wac("stream", 14),
    new Wac("strike", 2012),
    new Wac("surface", 20),
    new Wac("suspend", 2030),
    new Wac("sw", 49),
    new Wac("swim", 3147),
    new Wac("swing", 2009),
    new Wac("tablet", 1013),
    new Wac("take", 2001),
    new Wac("tame", 2010),
    new Wac("throw", 2017),
    new Wac("toss", 2017),
    new Wac("tote", 2001),
    new Wac("touch", 57),
    new Wac("travel", 2011),
    new Wac("treasure", 1055),
    new Wac("tree", 3064),
    new Wac("trees", 3064),
    new Wac("trident", 1057),
    new Wac("troll", 1033),
    new Wac("troll", 1034),
    new Wac("tunnel", 23),
    new Wac("turn", 2011),
    new Wac("u", 29),
    new Wac("unlock", 2004),
    new Wac("up", 29),
    new Wac("upstream", 4),
    new Wac("upward", 29),
    new Wac("utter", 2003),
    new Wac("valley", 9),
    new Wac("vase", 1058),
    new Wac("velvet", 1010),
    new Wac("vending", 1038),
    new Wac("view", 28),
    new Wac("volcano", 1037),
    new Wac("w", 44),
    new Wac("wake", 2029),
    new Wac("walk", 2011),
    new Wac("wall", 53),
    new Wac("water", 1021),
    new Wac("wave", 2009),
    new Wac("west", 44),
    new Wac("xyzzy", 62),
    new Wac("y2", 55),
  };

  // Test code to list vocabulary action codes in numerical order and check for duplicate words with different codes

  public static void main (String[] args) {
    TreeMap<Integer, List<String>> codeMap = new TreeMap<>();
    TreeMap<String, List<Integer>> dupsMap = new TreeMap<>();
    for (Wac item : wc) {
      List<String> words = codeMap.computeIfAbsent(item.acode, k -> new ArrayList<>());
      words.add(item.aword);
      List<Integer> dups = dupsMap.computeIfAbsent(item.aword, k -> new ArrayList<>());
      dups.add(item.acode);
    }
    System.out.println("Duplicate words with different action codes:");
    for (String word : dupsMap.keySet()) {
      List<Integer> codes = dupsMap.get(word);
      if (codes.size() > 1) {
        System.out.print("\t" + word + "\t");
        boolean first = true;
        for (int code : codes) {
          System.out.print((first ? "" : ", ") + code);
          first = false;
        }
        System.out.println();
      }
    }
    System.out.println("Action codes:");
    for (int code : codeMap.keySet()) {
      List<String> words = codeMap.get(code);
      System.out.print("\t" + code + "\t");
      boolean first = true;
      for (String word : words) {
        System.out.print((first ? "" : ", ") + word);
        first = false;
      }
      System.out.println();
    }
  }

  static int compare (String word, int mid) {
    return word.compareTo(wc[mid].aword.toLowerCase());
  }
}