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 strategyIDs) { ping(); printFormat("feedSucker * *", str(sucker), strategyIDs); class Strategy { S id; O f; S lastCode; *() {} *(S *id, O *f) {} } new L 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!!!!!"); } } }