Libraryless. Click here for Pure Java version (2870L/20K/66K).
!759 !include #1003405 // LooseBot v2 static OccTree<E> tree, botTree; static O makeBot; p { L<Dialog> dialogs = loadDialogs("Color Showing Bot"); tree = dialogs2occTree(dialogs); botTree = goodDialogs2occTree(dialogs); print("Tree size: " + tree.size() + ", bot tree size: " + botTree.size()); makeBot = func { new LooseBot(botTree) }; if (!canWalkTree(tree, call(makeBot))) { print("Engine not working, abort."); ret; } print("Tree walked! " + inputFed + " -> " + outputGot); print("Engine works! Trying to shrink the tree."); while (canShrinkTree()) { print("Tree shrunk, trying it again."); } print("Done shrinking tree (new size: " + botTree.size() + ")"); } static int inputFed, outputGot; sbool canShrinkTree() { L<OccTree<E>> leaves = botTree.allLeaves(); print("Leaves found: " + l(leaves)); bool anyChange = false; for (OccTree<E> leaf : leaves) { Reattach reattach = removeLeaf(leaf); if (canWalkTree()) { print("Leaf removed successfully!"); anyChange = true; } else reattach.reattach(); } ret anyChange; } sclass Reattach { OccTree<E> node, leaf; E key; void reattach() { leaf.parent = node; node.followUp.put(key, leaf); } } static Reattach removeLeaf(OccTree<E> leaf) { new Reattach r; r.leaf = leaf; r.node = leaf.parent; r.key = reverseLookup(leaf.parent.followUp, leaf); leaf.parent.followUp.remove(r.key); leaf.parent = null; ret r; } sbool canWalkTree() { ret canWalkTree(tree, call(makeBot)); } sbool canWalkTree(OccTree<E> tree, O bot) { try { walkTree(tree, bot); true; } catch { ret false; } } svoid walkTree(OccTree<E> tree, O bot) { if (isViable(tree)) { for (E e : keys(tree.followUp)) { if (!contains(ll("good", "bad"), e.state)) { //print("Step " + structure(e)); if (isInput(e)) feed(bot, e); else checkOutput(e, getOutput(bot)); walkTree(tree.followUp(e), bot); //print("Rewind " + structure(e)); rewind(bot); } } } } svoid rewind(O bot) { call(bot, "rewind"); // rewind one step } svoid feed(O bot, E e) { call(bot, "take", e); ++inputFed; } static E getOutput(O bot) { E e = cast call(bot, "getSingleOutput"); if (e != null) ++outputGot; ret e; } svoid checkOutput(E e, E output) { assertEquals(e, output); } static bool isInput(E e) { ret e.q() //|| (e.state() && !matchStart("bot", e.state)); ; }
download show line numbers debug dex old transpilations
Travelled to 15 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, ddnzoavkxhuk, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1003401 |
Snippet name: | Dialog Optimizer (dev.) |
Eternal ID of this version: | #1003401/1 |
Text MD5: | 9eef431ac339e8bb41a8e372c0c07749 |
Transpilation MD5: | b0f7810165f45a040ea919b6c34529ae |
Author: | stefan |
Category: | javax / talking robots |
Type: | JavaX source code |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2016-06-30 20:50:30 |
Source code size: | 2605 bytes / 115 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 693 / 742 |
Referenced in: | #1003408 - Dialog Optimizer 2 (works!) |