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

78
LINES

< > BotCompany Repo | #1004727 // feedSucker

JavaX fragment (include)

1  
static bool feedSucker_aggressiveKeepalive;
2  
3  
static void feedSucker(O sucker, S... strategyIDs) {
4  
  feedSucker(sucker, asList(strategyIDs));
5  
}
6  
7  
// sucker is an object implement a "suck" method, or a snippet ID
8  
static void feedSucker(O sucker, L<S> strategyIDs) {
9  
  ping();
10  
  
11  
  printFormat("feedSucker * *", str(sucker), strategyIDs);
12  
  
13  
  class Strategy {
14  
    S id;
15  
    O f;
16  
    S lastCode;
17  
    
18  
    *() {}
19  
    *(S *id, O *f) {}
20  
  }
21  
  
22  
  new L<Strategy> strategies;
23  
  
24  
  O _sucker = sucker;
25  
  if (sucker instanceof S) {
26  
    print("Waking...");
27  
    sucker = run((S) sucker);
28  
  }
29  
30  
  print("Loading strategies...");
31  
  for i over strategyIDs: pcall {
32  
    print((i+1) + "/" + l(strategyIDs));
33  
    S id = strategyIDs.get(i);
34  
    strategies.add(new Strategy(id, loadStrategy(id)));
35  
    print("OK");
36  
  }
37  
  
38  
  print("Got " + n(l(strategies), "strategy") + ".");
39  
  if (empty(strategies)) { print("Exiting!"); ret; }
40  
  
41  
  print("Feeding...");
42  
  S text = (S) callOpt(sucker, "getText");
43  
  assertNotNull(text);
44  
45  
  int round = 0;
46  
  
47  
  while licensed {
48  
    if (empty(strategies)) { print("Exiting!"); ret; }
49  
    ++round;
50  
    for i over strategies: pcall {
51  
      Strategy strategy = strategies.get(i);
52  
      
53  
      ping();
54  
      
55  
      // call strategy
56  
      
57  
      print("Round " + round + ", target " + _sucker + ", strategy " + strategy.id);
58  
      S lua = callStrategy(strategy.f, text);
59  
      //print("CODE:\n" + indentx(lua));
60  
      bool done = eq(lua, "done");
61  
      if (done ||
62  
        (!feedSucker_aggressiveKeepalive && eq(lua, strategy.lastCode))) {
63  
        print(done ? "Strategy done - dropping" : "Same code twice in a row - dropping strategy");
64  
        strategies.remove(i--);
65  
        continue;
66  
      }
67  
      strategy.lastCode = lua;
68  
  
69  
      S desc = "L " + lua;
70  
      O algo = makeLuaTextPredictAlgoFor(desc, sucker);
71  
      
72  
      O newBest = callOpt(sucker, "suck", desc, algo);
73  
      double score = cast get(sucker, "lastScore");
74  
      if (isTrue(newBest))
75  
        print("NEW BEST!!!!!");
76  
    }
77  
  }
78  
}

Author comment

Began life as a copy of #1004707

download  show line numbers  debug dex  old transpilations   

Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, ddnzoavkxhuk, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1004727
Snippet name: feedSucker
Eternal ID of this version: #1004727/1
Text MD5: 1cb53b55b472ef5bbbfb4ffa0173bda8
Author: stefan
Category: javax / a.i.
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2016-09-11 19:43:32
Source code size: 2082 bytes / 78 lines
Pitched / IR pitched: No / No
Views / Downloads: 582 / 539
Referenced in: [show references]