Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

128
LINES

< > BotCompany Repo | #1003797 // Random v6/v7 Thinker

JavaX fragment (include)

1  
!include #1003606 // GenTesting
2  
3  
sclass Thinker {
4  
  new MultiSet<S> scores;
5  
  new MultiSet<S> quickScores;
6  
  bool useQuickScores;
7  
  int quickAnalysisDepth = 100;
8  
  int listMakingTimeout = 2000;
9  
  int maxListLength = 100;
10  
  int logLengthSeen;
11  
  bool showExceptions, debug;
12  
  
13  
  void startUp(L<S> log) {
14  
    final L<S> _log = cloneList(log); // Clone to be safe
15  
    
16  
    thread "Full Scoring!" {
17  
      scores = scores(_log);
18  
    }
19  
  }
20  
  
21  
  MultiSet<S> scores(L<S> log) {
22  
    ret makeGT().scoreGenerators(log);
23  
  }
24  
  
25  
  MultiSet<S> scores(L<S> log, BitSet interestingLines) {
26  
    ret makeGT().scoreGenerators(log, interestingLines);
27  
  }
28  
  
29  
  GenTesting makeGT() {
30  
    ret new GenTesting(voidfunc(L<Gen> gens, L<S> log) { makeGenerators(gens, log); });
31  
  }
32  
  
33  
  void updateQuickScores(L<S> log) {
34  
    if (!useQuickScores) ret;
35  
    if (l(log) > logLengthSeen) {
36  
      logLengthSeen = l(log);
37  
      quickScores = makeGT().scoreGenerators((L<S>) call(mc(), "getLastFromLog", quickAnalysisDepth));
38  
    }
39  
  }
40  
41  
  // also called from outside
42  
  void recommendSolver(S solverID) {
43  
    if (!isRecommendedSolver(solverID = fsi(solverID))) {
44  
      print("Adding recommended solver: " + solverID);
45  
      logQuoted("recommendations.txt", solverID);
46  
    } else
47  
      print("Solver already recommended: " + solverID);
48  
  }
49  
  
50  
  bool isRecommendedSolver(S solverID) {
51  
    ret contains(scanLog("recommendations.txt"), fsI(solverID));
52  
  }
53  
  
54  
  // Scoring formula!
55  
  int formula(S genName) {
56  
    ret quickScores.get(genName)+scores.get(genName);
57  
  }
58  
  
59  
  L<Gen> sortGenerators(L<Gen> gens, final MultiSet<S> scores) {
60  
    ret sortedList(gens, func(Gen a, Gen b) {
61  
      formula(b.name)-formula(a.name)
62  
    });
63  
  }
64  
65  
  // log = what's in the chat
66  
  // input = what user is typing
67  
  void makeListData(L<S> thelog, S input, L l) {
68  
    try {
69  
      long timeout = now() + listMakingTimeout;
70  
      new HashSet<S> seen;
71  
      
72  
      updateQuickScores(log); // not used atm
73  
      
74  
      // extended log including what user is typing
75  
      L<S> xlog = listPlus(thelog, input);
76  
        
77  
      for (L<S> log : litlist(thelog, xlog)) {
78  
        // Make and sort generators
79  
  
80  
        new L<Gen> gens;
81  
        try {
82  
          genLog_set(log);
83  
          gCompleting_set(log == xlog);
84  
          makeGenerators(gens, log);
85  
          gens = sortGenerators(gens, scores);
86  
          if (empty(gens)) {
87  
            l.add(ll("No generators"));
88  
            ret;
89  
          }
90  
          
91  
          // Generators made. Start making list.
92  
          
93  
          int i = -1;
94  
          while (now() < timeout && l(l) < maxListLength && nempty(gens)) {
95  
            i = (i+1) % l(gens);
96  
            bool remove = false;
97  
            Gen gen = gens.get(i);
98  
            if (debug)
99  
              print("Trying generator " + gen.name);
100  
            try {
101  
              S s = callGen(gen);
102  
              if (empty(s) || seen.contains(s))
103  
                remove = true;
104  
              else {
105  
                seen.add(s);
106  
                int k = l(l)+1;
107  
                S key = k <= 12 ? "F" + k : null;
108  
                l.add(litorderedmap("Key", key, "Suggestion", s, "Suggester", gen.name));
109  
              }
110  
            } catch e {
111  
              if (showExceptions)
112  
                l.add(litorderedmap("Suggestion", "[error] " + exceptionToStringShort(e), "Suggester", gen.name));
113  
              remove = true;
114  
            }
115  
            if (remove)
116  
              gens.remove(i--);
117  
          }
118  
        } finally {
119  
          genLog_clear();
120  
          gCompleting_set(null);
121  
        }
122  
      }
123  
    } catch e {
124  
      printStackTrace(e);
125  
      l.add(e.toString());
126  
    }
127  
  }
128  
}

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: #1003797
Snippet name: Random v6/v7 Thinker
Eternal ID of this version: #1003797/1
Text MD5: 3e9b045bb3eeb673708f81c335134944
Author: stefan
Category: javax / talking robots
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2016-07-30 18:45:41
Source code size: 3728 bytes / 128 lines
Pitched / IR pitched: No / No
Views / Downloads: 574 / 1644
Referenced in: [show references]