1 | AI > AI_Racer {
|
2 | bool verbose; |
3 | AI_RandomWithVariation leader, overtaker; |
4 | new Best<Submission> leadersBest; |
5 | int discardEvery = 5000; |
6 | int roundsSinceChange; |
7 | |
8 | AI_RandomWithVariation newAI() { ret new AI_RandomWithVariation; }
|
9 | |
10 | void go {
|
11 | if (round() == 1 && leadersBest.has()) // TODO: automate this |
12 | submit(leadersBest.get()); |
13 | else if (tossACoin()) {
|
14 | if (leader == null) leader = newAI(); |
15 | initSubAI(leader); |
16 | Submission guess = leader.guess(); |
17 | double score = submit(guess); |
18 | leader.updateBest(guess, score); |
19 | leadersBest.put(guess, score); |
20 | } else {
|
21 | if (overtaker == null) overtaker = newAI(); |
22 | initSubAI(overtaker); |
23 | Submission guess = overtaker.guess(); |
24 | double score = submit(guess); |
25 | overtaker.updateBest(guess, score); |
26 | if (score > leadersBest.score()) {
|
27 | // displace leader! |
28 | if (verbose) |
29 | print("Overtake at " + formatScore(overtaker.best.score()) + " vs " + formatScore(leadersBest.score()));
|
30 | leader = overtaker; |
31 | overtaker = null; |
32 | roundsSinceChange = 0; |
33 | } else if (roundsSinceChange++ >= discardEvery) {
|
34 | // make new overtaker |
35 | if (verbose) |
36 | print("Discarding overtaker at " + formatScore(overtaker.best.score()) + " vs " + formatScore(leadersBest.score()));
|
37 | overtaker = null; |
38 | roundsSinceChange = 0; |
39 | } |
40 | } |
41 | } |
42 | } |
download show line numbers debug dex old transpilations
Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
| Snippet ID: | #1014957 |
| Snippet name: | AI_Racer |
| Eternal ID of this version: | #1014957/2 |
| Text MD5: | 8ceaf98209eb91301cc6f936b6ddd8f6 |
| Author: | stefan |
| Category: | javax / a.i. |
| Type: | JavaX fragment (include) |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2018-05-07 14:27:23 |
| Source code size: | 1454 bytes / 42 lines |
| Pitched / IR pitched: | No / No |
| Views / Downloads: | 667 / 2284 |
| Version history: | 1 change(s) |
| Referenced in: | [show references] |