Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

59
LINES

< > BotCompany Repo | #1007159 // A. I. Game 3.1 - Dark/Bright [REFACTORED, WORKS]

JavaX source code [tags: use-pretranspiled] - run with: x30.jar

Uses 3874K of libraries. Click here for Pure Java version (8718L/62K/220K).

1  
!7
2  
3  
!include #1006891 // Click AI Include
4  
5  
static int spacing = 10; // space between the two images
6  
7  
p {
8  
  w = h = 150;
9  
  imageZoom = 1;
10  
  pGame();
11  
}
12  
13  
extend AI {
14  
  Rect leftRect() { ret main.leftRect(image); }
15  
  Rect rightRect() { ret main.rightRect(image); }
16  
  L<Rect> clickLeft() { ret submit(leftRect()); }
17  
  L<Rect> clickRight() { ret submit(rightRect()); }
18  
  L<Rect> clickLeftIf(bool b) { ret b ? clickLeft() : clickRight(); }
19  
  L<Rect> clickRightIf(bool b) { ret b ? clickRight() : clickLeft(); }
20  
  RGBImage leftImage() { ret image.clip(leftRect()); }
21  
  RGBImage rightImage() { ret image.clip(rightRect()); }
22  
}
23  
24  
static int singleImageWidth(RGBImage img) { ret (img.w()-spacing)/2; }
25  
26  
static Rect leftRect(RGBImage img) {
27  
  int iw = singleImageWidth(img);
28  
  ret new Rect(0, 0, iw, h);
29  
}
30  
31  
static Rect rightRect(RGBImage img) {
32  
  int iw = singleImageWidth(img);
33  
  ret new Rect(iw+spacing, 0, iw, h);
34  
}
35  
36  
//////////////////////////////////////
37  
// Test AIs. Just add your own here //
38  
//////////////////////////////////////
39  
40  
AI > ClickOnBrighterImage {
41  
  void go {
42  
    clickLeftIf(rgbAverageBrightness(leftImage()) > rgbAverageBrightness(rightImage()));
43  
  }
44  
}
45  
46  
//////////////////
47  
// PUZZLE MAKER //
48  
//////////////////
49  
50  
static Puzzle makePuzzle() {
51  
  S instruction = "Click on the brighter image";
52  
  RGBImage img = rgbImage(0xeef3e6, w*2+spacing, h);
53  
  double l = random(10)/10.0, r = random(10)/10.0;
54  
  Rect lr = leftRect(img), rr = rightRect(img);
55  
  rgbFill(img, lr, new RGB(l));
56  
  rgbFill(img, rr, new RGB(r));
57  
  L<Rect> solution = l > r ? ll(lr) : l == r ? ll(lr, rr) : ll(rr);
58  
  ret new Puzzle(instruction, img, solution);
59  
}

Author comment

Began life as a copy of #1006837

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: #1007159
Snippet name: A. I. Game 3.1 - Dark/Bright [REFACTORED, WORKS]
Eternal ID of this version: #1007159/7
Text MD5: f15733e55f0a887ba4315a27b9d04ea5
Transpilation MD5: 8d9f7636718cd120527f4143c799de15
Author: stefan
Category: javax / gui
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-03-08 17:22:58
Source code size: 1686 bytes / 59 lines
Pitched / IR pitched: No / No
Views / Downloads: 436 / 533
Version history: 6 change(s)
Referenced in: [show references]