sclass Feeder { O sucker, origSucker; new L<S> strategyIDs; new L<Strategy> 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"); } }
Began life as a copy of #1004727
download show line numbers debug dex old transpilations
Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1004875 |
Snippet name: | class Feeder (holds strategies & sucker) |
Eternal ID of this version: | #1004875/1 |
Text MD5: | 4729b414370c95a72bcaacdef722bbb8 |
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 23:22:52 |
Source code size: | 2649 bytes / 106 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 515 / 758 |
Referenced in: | [show references] |