!7 abstract sclass GameViewForAI { abstract int w(); abstract int h(); abstract int getPixel(int x, int y); } abstract sclass AI { GameViewForAI game; int w, h; int getPixel(int x, int y) { ret game.getPixel(x, y); } abstract Pt nextClick(); } sclass Game extends GameViewForAI { long points; int w = 500, h = 500; int rw = 50, rh = 50, border = 10; int x1, y1; int w() { ret w; } int h() { ret h; } int getPixel(int x, int y) { ret new Rect(x1, y1, rw, rh).contains(x, y) ? 0xFF0000 : 0xFFFFFF; } void nextImage() { x1 = random(border, w-rw-border); y1 = random(border, h-rh-border); } void click(Pt p) { if (rectContains(x1, y1, rw, rh, p)) { ++points; //print("Points: " + points); nextImage(); } } } sclass MyAI extends AI { Pt nextClick() { getPixel..... ret new Pt(0, 0); } } sclass RandomAI extends AI { Pt nextClick() { ret new Pt(random(w), random(h)); } } sclass SearchingAI extends AI { Pt nextClick() { for (int y = 0; y < h; y += 10) for (int x = 0; x < w; x += 10) if (getPixel(x, y) != 0xFFFFFF) ret new Pt(x, y); null; } } static long pointsAfterNRounds(AI ai, long rounds) { new Game game; setOpt(ai, +game); setOpt(ai, "w", game.w()); setOpt(ai, "h", game.h()); long step = 0; pcall { while (step < rounds) { ++step; Pt p = ai.nextClick(); if (p == null) { print("AI resigned"); break; } game.click(p); //print("Step " + step + ", move: " + p + ", points: " + game.points); } } print("AI " + shortClassName(ai) + " points after " + rounds + " rounds: " + game.points); ret game.points; } p { logOutputPlain(); pointsAfterNRounds(new MyAI, 10000); pointsAfterNRounds(new RandomAI, 10000); pointsAfterNRounds(new SearchingAI, 10000); }
Began life as a copy of #1006663
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
ID | Author/Program | Comment | Date |
---|---|---|---|
1311 | stefan | See https://www.youtube.com/watch?v=PJC4ej5-PDo | 2017-02-01 16:23:30 |
Snippet ID: | #1006667 |
Snippet name: | A.I. Game [headless] [non-working draft copy made in video] |
Eternal ID of this version: | #1006667/4 |
Text MD5: | 12e8067a2da2777e19c04be8c411564d |
Author: | stefan |
Category: | javax / gui |
Type: | JavaX source code |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2017-02-01 16:23:03 |
Source code size: | 1979 bytes / 95 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 634 / 634 |
Version history: | 3 change(s) |
Referenced in: | -