sclass Feeder { O sucker, origSucker; new L strategyIDs; new L strategies; S text; bool aggressiveKeepalive; // keep strategies int round; sclass Strategy { S id; O f; S lastCode; *() {} *(S *id, O *f) {} } *() {} *(O sucker, S... strategyIDs) { setSucker(sucker); addAll(this.strategyIDs, strategyIDs); loadStrategies(); } void setSucker(O sucker) { origSucker = sucker; if (sucker instanceof S) { print("Waking..."); sucker = run((S) sucker); } this.sucker = sucker; text = (S) callOpt(sucker, "getText"); } void loadStrategies() { 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"); } } bool oneRound() { if (empty(strategies)) cleanExit("No more strategies"); ++round; bool change = false; for i over strategies: pcall { Strategy strategy = strategies.get(i); ping(); // call strategy print("Round " + round + ", target " + origSucker + ", strategy " + strategy.id); S lua = callStrategy(strategy.f, text); //print("CODE:\n" + indentx(lua)); bool done = eq(lua, "done"); if (done || (!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!!!!!"); change = true; } } ret change; } // call reset function on each strategy void resetStrategies() { for (Strategy s : strategies) callOpt(s.f, "reset"); } double highestScore() { ret (double) call(sucker, "highestScore"); } S highestDesc() { ret (S) call(sucker, "highestDesc"); } int pivotLength() { ret (int) get(sucker, "pivotLength"); } void nextPivotLength() { int pivotLength = l(highestDesc())-1; if (pivotLength <= 0) fail("Too short"); set(sucker, "pivotLength", pivotLength); print("Pivot length now: " + pivotLength); call(sucker, "reset"); } }