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

78
LINES

< > BotCompany Repo | #1004727 // feedSucker

JavaX fragment (include)

static bool feedSucker_aggressiveKeepalive;

static void feedSucker(O sucker, S... strategyIDs) {
  feedSucker(sucker, asList(strategyIDs));
}

// sucker is an object implement a "suck" method, or a snippet ID
static void feedSucker(O sucker, L<S> strategyIDs) {
  ping();
  
  printFormat("feedSucker * *", str(sucker), strategyIDs);
  
  class Strategy {
    S id;
    O f;
    S lastCode;
    
    *() {}
    *(S *id, O *f) {}
  }
  
  new L<Strategy> strategies;
  
  O _sucker = sucker;
  if (sucker instanceof S) {
    print("Waking...");
    sucker = run((S) sucker);
  }

  print("Loading strategies...");
  for i over strategyIDs: pcall {
    print((i+1) + "/" + l(strategyIDs));
    S id = strategyIDs.get(i);
    strategies.add(new Strategy(id, loadStrategy(id)));
    print("OK");
  }
  
  print("Got " + n(l(strategies), "strategy") + ".");
  if (empty(strategies)) { print("Exiting!"); ret; }
  
  print("Feeding...");
  S text = (S) callOpt(sucker, "getText");
  assertNotNull(text);

  int round = 0;
  
  while licensed {
    if (empty(strategies)) { print("Exiting!"); ret; }
    ++round;
    for i over strategies: pcall {
      Strategy strategy = strategies.get(i);
      
      ping();
      
      // call strategy
      
      print("Round " + round + ", target " + _sucker + ", strategy " + strategy.id);
      S lua = callStrategy(strategy.f, text);
      //print("CODE:\n" + indentx(lua));
      bool done = eq(lua, "done");
      if (done ||
        (!feedSucker_aggressiveKeepalive && eq(lua, strategy.lastCode))) {
        print(done ? "Strategy done - dropping" : "Same code twice in a row - dropping strategy");
        strategies.remove(i--);
        continue;
      }
      strategy.lastCode = lua;
  
      S desc = "L " + lua;
      O algo = makeLuaTextPredictAlgoFor(desc, sucker);
      
      O newBest = callOpt(sucker, "suck", desc, algo);
      double score = cast get(sucker, "lastScore");
      if (isTrue(newBest))
        print("NEW BEST!!!!!");
    }
  }
}

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: 581 / 538
Referenced in: #1004875 - class Feeder (holds strategies & sucker)
#1006654 - Standard functions list 2 (LIVE, continuation of #761)