Libraryless. Click here for Pure Java version (984L/7K/24K).
!759 static final int gridSize = 10; static int steps = 10; // steps limit sinterface Make { X make(); } asclass X { abstract Move get(); } asclass SelfMade extends X implements Make { public X make() { start(); ret this; } void start() {} // override me } asclass Move { } sclass ClearFixed extends Move { int i; *() {} *(int *i) {} } sclass Grid { int val = (1 << gridSize)-1; bool cleared() { ret val == 0; } void clear(int i) { if (i >= 0 && i < gridSize) val &= ~(1 << i); } int remaining() { ret countBits(val); } } static L<Make> pool; p { pool = new L; new Best<Make> best; while (licensed()) { ping(); updatePool(); new HashMap<Make, Number> scores; for (Make maker : pool) { ping(); int score = play(maker.make()); scores.put(maker, score); best.put(maker, score); } Make winner = lowest(scores); print("Best score: " + scores.get(winner) + " - " + structure(winner) + ", all time: " + best.score); } } // collects LOWEST score sclass Best<A> { A best; int score; void put(A a, int score) { if (best == null || score < this.score) { best = a; this.score = score; } } A get() { ret best; } } static int play(X x) { new Grid g; int i = 0; while (i++ < steps && move(x, g) && !g.cleared()) {} ret /*i +*/ g.remaining(); } // false = x exited static bool move(X x, Grid g) { Move m = x.get(); if (m == null) ret false; ClearFixed cf = cast m; g.clear(cf.i); ret true; } //// CONTESTANTS //// sclass C1 extends SelfMade { L<Integer> positions; int i; *() {} *(L<Integer> *positions) {} *(int... l) { positions = asList(l); } void start() { i = 0; } Move get() { if (i >= l(positions)) ret null; ret new ClearFixed(positions.get(i++)); } } // updatePool static void updatePool() { pool.clear(); if (random(2) == 0) pool.add(new C1(random(gridSize), random(gridSize))); else pool.add(new C1(random(gridSize), random(gridSize), random(gridSize))); }
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: | #1003133 |
Snippet name: | GenOpt pre 1 |
Eternal ID of this version: | #1003133/1 |
Text MD5: | 2528815b5b3bc573e96b9e71a25dba7e |
Transpilation MD5: | fcc4a8da247fe0822648f2f3224e3a0c |
Author: | stefan |
Category: | javax |
Type: | JavaX source code |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2016-05-14 00:23:16 |
Source code size: | 2195 bytes / 119 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 603 / 679 |
Referenced in: | #1003138 - GenOpt 1 (Sorting) |