Advertisement
Guest User

Untitled

a guest
Apr 29th, 2021
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 23.80 KB | None | 0 0
  1. int[][] tab = new int[200][200];
  2. int[][] tab2 = new int[200][200];
  3. int[][] rtab = new int[200][200];
  4. int[][] rtab2 = new int[200][200];
  5. int[][] ptab = new int[200][200];
  6. int[][] prtab = new int[200][200];
  7. int[][] ctab = new int[200][200];
  8. int[][] crtab = new int[200][200];
  9.  
  10. int[][][] ship = new int[80][20][20];
  11. int[][][] rship = new int[80][20][20];
  12.  
  13. int n = 34;
  14. int offset = -3;
  15. int j = 0;
  16. int r;
  17. String temp, slog, onscreenconsole;
  18. int stop = 0;
  19. int px1, px2, py1, py2, selection, mark, record, frames, random, oneframe, delayon, periodb, period, movemode, copied, cx1, cx2, cy1, cy2, cmode, cf, cf2, cframes, tmp2, diff;
  20.  
  21. float sf = 1;
  22. float sx = 0;
  23. float sy = 0;
  24.  
  25. //String[] readinglist = {"37020_27290_p120gg.txt", "47834_60569_p60.txt", "28621_27721_p120gg_monodirectional.txt",
  26. //"71195_16368_glidersideways.txt", "57758_85936_p128_gun.txt", "57758_76359_p180_gun.txt", "57758_66730_p32_gun.txt",
  27. //"39469_318789_p16_gun_tiny.txt", "41605_70452_p32_gun_tiny_v2.txt", "41605_292692_latch_prototype3.txt", "29256_67675.txt"}; //importable files
  28.  
  29. String[] readinglist = {"53644_830_knightship.txt", "51943_1138_rake_p24_makes_4p2b.txt", "11932_3499_backrake_p4_makes_4p2b.txt", "95440_19926_p16_wide_factory.txt", "60553_35248_p16_shipfactory_with_p32.txt", "64335_28312_p4_shipfactory_v2_p32.txt", "4023_26238_coolshipfarm_prototype.txt", "44894_49376_p14_factory_with_p64.txt",
  30. "41605_70452_p32_gun_tiny_v2.txt", "9170_14818_squidfarm.txt", "4023_2959_p32_squidfarm.txt", "47822_123223_shipfactory_almost.txt", "81030_49112_p8_shipfactory.txt"};
  31.  
  32. //String[] readinglist = {"73923_29625_squidcollisions.txt", "73923_46452_squidcollisions2.txt", "73923_50185_squidcollisions3.txt",
  33. //"73923_52734_squidcollisions4.txt", "73923_58820_squidcollisions5.txt", "73923_62781_squidcollisions6.txt"};
  34.  
  35. String[] shippinglist = {"shiplist.txt"};
  36.  
  37. int imported = 0;
  38.  
  39. void setup() {
  40. size(1000, 1000);
  41. background(0);
  42. noStroke();
  43. selection = 0;
  44. mark = 0;
  45. record = 0;
  46. frames = 0;
  47. oneframe = 0;
  48. random = int(random(0,100000));
  49. delayon = 0;
  50. periodb = 0;
  51. period = 0;
  52. movemode = 0;
  53. copied = 0;
  54. cmode = 0;
  55. cf = 0;
  56. cf2 = 0;
  57. tmp2 = 0;
  58. slog = "";
  59. px1 = 0;
  60. py1 = 0;
  61. onscreenconsole = "";
  62.  
  63. cframes = 70;
  64.  
  65. cx1 = 0; cx2 = 0; cy1 = 0; cy2 = 0;
  66.  
  67. /*for (int j = 0; j < ship[0][0].length; j++) {
  68. for (int i = 0; i < ship[0].length; i++) {
  69. for (int k = 0; k < ship.length; k++) {
  70. ship[k][i][j] = 0;
  71. rship[k][i][j] = 0;
  72. }
  73. }
  74. } */
  75.  
  76. //print(convertRules(148269) + " " + convertRules(92209) + " " + convertRules(207644));
  77. //delay(10000);
  78.  
  79. scale(sf);
  80. translate(sx, sy);
  81. resetfield();
  82.  
  83. //r = replacerule();
  84. //r = 91491;
  85. r = 0;
  86.  
  87. }
  88.  
  89. void draw() {
  90. background(0);
  91. scale(sf);
  92. translate(sx, sy);
  93. noFill();
  94. stroke(255);
  95. rect(-1, -1, 1002, 1002);
  96. noStroke();
  97.  
  98. if (delayon == 1) {delay(100);}
  99. j++;
  100. if (stop == 0) {
  101. make();
  102. frames++;
  103. if (record == 1) {
  104. save(random + "_" + frames + ".png");
  105. }
  106. if (periodb == 1) {
  107. int diff = 0;
  108. for (int i1 = 0; i1 < 200; i1++) {
  109. for (int i2 = 0; i2 < 200; i2++) {
  110. if (ptab[i1][i2] != tab[i1][i2] || prtab[i1][i2] != rtab[i1][i2]) {
  111. diff = 1;
  112. }
  113. }
  114. }
  115. period++;
  116. if (diff == 0) {
  117. print("period found: " + period + "\n");
  118. periodb = 0;
  119. }
  120. }
  121. if (cmode == 1) {
  122. cf++;
  123. if (cf%cframes == 1) {
  124.  
  125. //Hier muss die neue Anordnung generiert werden
  126.  
  127. for (int i1 = 0; i1 < 200; i1++) {
  128. for (int i2 = 0; i2 < 200; i2++) {
  129. tab[i1][i2] = 0;
  130. rtab[i1][i2] = 0;
  131. }
  132. }
  133. slog += " " + str(tmp2) + " " + diff + "\n";
  134. println(slog.split("\n")[slog.split("\n").length - 1]);
  135.  
  136. /*if (diff > 0) {
  137. println(slog.split("\n")[slog.split("\n").length - 1]);
  138. }*/
  139.  
  140. //int[][] tmp = {{0, 80+1, 80+0, 0, 0}, {1, 80+1+cf2%6, 80+4+cf2/6, 2, 0}};
  141. //int[][] tmp = {{22, 80+cf2%10, 80-cf2/10%6, 0, 0}, {22+cf2/360%2, 80, 80+3, 2, 0}, {22+cf2/720%2, 80+4+cf2/60%6, 80, 1, 0}};
  142. //int[][] tmp = {{24, 87, 76, 0, 0}, {24, 80, 83, 2, 0}};
  143. //int[][] tmp = {{1, 80, 77, 0, 0}, {24, 78, 82, 3, 0}};
  144. //int[][] tmp = {{0, 85+0, 85+0, 3, 0}, {0, 85+2+cf2%7, 85-2-cf2/7%7, 0, 0}, {0, 85+2+cf2/49, 85+2, 2, 0}};
  145. int[][] tmp = {{24, 80+cf2%10, 80-cf2/10%6, 0, 0}, {24+cf2/60, 80-4, 80+4, 3, 0}};
  146.  
  147. //slist [zeile schiffnummer], dann [0] art/phase, [1] dx, [2] dy, [3] drehung, [4] gespiegelt
  148.  
  149. slog += "{{";
  150. for (int i = 0; i < tmp.length; i++) {
  151. for (int j = 0; j < tmp[0].length; j++) {
  152. slog += tmp[i][j] + ", ";
  153. }
  154. slog = slog.substring(0, slog.length() - 2) + "}, {";
  155. }
  156. slog = slog.substring(0, slog.length() - 3) + "}";
  157. gcol(tmp);
  158. tmp2 = 1;
  159. cf2++;
  160. }
  161. diff = 0;
  162. for (int i1 = 0; i1 < 200; i1++) { //(int i1 = 0; i1 < 200; i1++)
  163. for (int i2 = 0; i2 < 200; i2++) { //(int i2 = 0; i2 < 200; i2++)
  164. diff += tab[i1][i2];
  165. }
  166. }
  167. if (diff == 0) {
  168. cf += cframes - cf%cframes;
  169. tmp2 = 0;
  170. }
  171. }
  172. } else {
  173. //n = rtab[max(0, min(mouseX/5, 199))][max(0, min(mouseY/5, 199))];
  174. for (int y = 0; y < 200; y++){
  175. for (int x = 0; x < 200; x++){
  176. noStroke();
  177. fill(color(255*tab[x][y]));
  178. rect(x*5, y*5, 5, 5);
  179. if (rtab[x][y] == 0 && mark == 1) {
  180. fill(255, 255, 0);
  181. rect(x*5+1, y*5+1, 3, 3);
  182. }
  183. }
  184. }
  185. stroke(255, 0, 0);
  186. strokeWeight(1/sf);
  187. line(mouseX/sf-sx,-sy,mouseX/sf-sx, height/sf-sy);
  188. line(-sx,mouseY/sf-sy,width/sf-sx,mouseY/sf-sy);
  189. noStroke();
  190. textAlign(LEFT);
  191. textSize(20/sf);
  192. fill(255);
  193. fill(255);
  194. text("(" + px1 + ", " + py1 + ") " + str(ceil(px2/5-px1/5)+1) + "x" + str(ceil(py2/5-py1/5)+1), (-sx+10/sf), (-sy+30/sf));
  195. noStroke();
  196.  
  197. if (selection == 1) {
  198. noFill();
  199. stroke(255);
  200. rect(5*(px1/5), 5*(py1/5), 5*(px2/5-px1/5)+5, 5*(py2/5-py1/5)+5);
  201. noStroke();
  202. }
  203. }
  204. if (oneframe == 1) {
  205. stop = 1;
  206. oneframe = 0;
  207. }
  208. //print(j + "\n");
  209. //if(j%150==0){r = replacerule(); print(r + "\n"); resetfield();}//save("k2_" + str(j) + ".png");}
  210. }
  211.  
  212. void make() {
  213. for (int y = 0; y < 200; y++){
  214. for (int x = 0; x < 200; x++){
  215. rtab2[x][y] = r;
  216. for (int i = -1; i <= 1; i++) {
  217. for (int j = -1; j <= 1; j++) {
  218. if(tab[(x+i+200)%200][(y+j+200)%200] == 1){
  219. rtab2[x][y] = rtab2[x][y]^rtab[(x+i+200)%200][(y+j+200)%200];
  220. }
  221. }
  222. }
  223. //rtab2[x][y] = rtab2[x][y]&~unbinary("000000011000001100"); //the best xoxo
  224. //rtab2[x][y] = rtab2[x][y]&~unbinary("000000011000001010");
  225. //rtab2[x][y] = rtab2[x][y]&~unbinary("000000011000010101");
  226. //rtab2[x][y] = rtab2[x][y]&~4108;
  227. }
  228. }
  229. for (int y = 0; y < 200; y++){
  230. for (int x = 0; x < 200; x++){
  231. n = 0;
  232. for (int i = -1; i <= 1; i++) {
  233. for (int j = -1; j <= 1; j++) {
  234. n += tab[(x+i+200)%200][(y+j+200)%200];
  235. }
  236. }
  237. n -= tab[x][y];
  238. rtab[x][y] = rtab2[x][y];
  239.  
  240. //rtab[x][y] = 4108;
  241.  
  242. if (tab[x][y] == 0) {
  243. tab2[x][y] = rule(n, rtab[x][y]>>9);
  244. } else {
  245. tab2[x][y] = rule(n, rtab[x][y]&1023);
  246. }
  247.  
  248. //print(r + "\n");
  249. }
  250. }
  251. for (int y = 0; y < 200; y++){
  252. for (int x = 0; x < 200; x++){
  253. tab[x][y] = tab2[x][y];
  254. fill(color(255*tab[x][y]));
  255.  
  256. //fill(255*((rtab[x][y]>>13)%2), 0, 0);
  257.  
  258. //fill(color(31*((rtab[x][y]>>9)%8), 31*((rtab[x][y]>>12)%8), 31*((rtab[x][y]>>15)%8)));
  259. //fill(color(31*((rtab[x][y]>>0)%8), 31*((rtab[x][y]>>3)%8), 31*((rtab[x][y]>>15)%6)));
  260. //if (rtab[x][y] != "00000000000000000000000000000000") {print(rtab[x][y] + "\n");}
  261. rect(x*5, y*5, 5, 5);
  262.  
  263. //fill(color(31*((rtab[x][y]>>0)%8), 31*((rtab[x][y]>>3)%8), 31*((rtab[x][y]>>15)%6)));
  264. //rect(x*5, y*5, 5, 5);
  265. //fill(color(31*((rtab[x][y]>>9)%8), 31*((rtab[x][y]>>12)%8), 31*((rtab[x][y]>>15)%8)));
  266. //rect(x*5+1, y*5+1, 3, 3);
  267. //fill(color(255*tab[x][y]));
  268. //rect(x*5+2, y*5+2, 1, 1);
  269. }
  270. }
  271. }
  272.  
  273. int rule(int a, int rule) {
  274. return(rule >> a)%2;
  275. }
  276.  
  277. int replacerule() {
  278. return int(random(0,262144))%262144;
  279. }
  280.  
  281.  
  282. void resetfield() {
  283. //randomSeed(226);
  284. print("Seed: " + j + "\n");
  285. //n = replacerule();
  286. for (int y = 0; y < 200; y++){
  287. for (int x = 0; x < 200; x++){
  288. tab[x][y] = 0;
  289. rtab[x][y] = replacerule();
  290. fill(color(255*tab[x][y]));
  291. rect(x*5, y*5, 5, 5);
  292. //print(tab[i][0]);
  293.  
  294. rtab[x][y] = rtab[x][y]&~unbinary("000000011001001100");
  295. //rtab[x][y] = rtab[x][y]&~unbinary("000000011000001010");
  296. //rtab[x][y] = rtab[x][y]&~unbinary("000000011000010101");
  297. //rtab[x][y] = rtab[x][y]&~unbinary("000000011000010110");
  298. //rtab[x][y] = rtab[x][y]&~unbinary("001011011111000010"); //B01346S1678
  299.  
  300. //rtab[x][y] = rtab[x][y]&~n;
  301. //rtab[x][y] = rtab[x][y]&~38018;
  302.  
  303. }
  304. }
  305. for (int y = 70; y < 130; y++){
  306. for (int x = 70; x < 130; x++){
  307. tab[x][y] = int(random(0,2))%2;
  308. fill(color(255*tab[x][y]));
  309. rect(x*5, y*5, 5, 5);
  310. //print(tab[i][0]);
  311. }
  312. }
  313. }
  314.  
  315. void mousePressed() {
  316. if (mouseButton == LEFT) {
  317. px1 = int(mouseX/sf-sx);
  318. py1 = int(mouseY/sf-sy);
  319. selection = 0;
  320. } else {
  321. resetfield();
  322. }
  323. }
  324.  
  325. void keyPressed() {
  326. if (movemode == 0) {
  327. if (key == 'p') {
  328. stop = (stop + 1)%2;
  329. if (stop == 0) {
  330. print("Unpaused\n");
  331. } else {
  332. print("Paused\n");
  333. }
  334. }
  335. if (key == 'n') {
  336. mark = (mark + 1)%2;
  337. if (mark == 0) {
  338. print("nullrules hidden\n");
  339. } else {
  340. print("nullrules shown\n");
  341. }
  342. }
  343. if (key == 'd') {
  344. delayon = (delayon + 1)%2;
  345. if (delayon == 0) {
  346. print("Delay off\n");
  347. } else {
  348. print("Delay on\n");
  349. }
  350. }
  351. if (key == 'r') {
  352. record = (record + 1)%2;
  353. if (record == 0) {
  354. print("recording stopped\n");
  355. } else {
  356. print("recording started\n");
  357. }
  358. }
  359. if (key == 's') {
  360. PrintWriter output;
  361.  
  362. output = createWriter(random + "_" + j + ".txt");
  363.  
  364. //output.print("Test");
  365. int temp3 = 0;
  366. String bb = " rulespace \n{";
  367. for (int i = py1/5; i <= py2/5; i++) {
  368. bb += "\n{";
  369. for (int j = px1/5; j <= px2/5; j++) {
  370. bb += " ".substring(0, 6-str(rtab[j][i]).length()) + rtab[j][i] + ", ";
  371. temp3 = temp3|rtab[j][i];
  372. }
  373. bb = bb.substring(0, bb.length() - 2) + "},";
  374. }
  375. bb = bb.substring(0, bb.length() - 1) + "\n};\n\n statespace \n{";
  376. for (int i = py1/5; i <= py2/5; i++) {
  377. bb += "\n{";
  378. for (int j = px1/5; j <= px2/5; j++) {
  379. bb += tab[j][i] + ", ";
  380. }
  381. bb = bb.substring(0, bb.length() - 2) + "},";
  382. }
  383. bb = bb.substring(0, bb.length() - 1) + "\n};";
  384. temp3 = 524287-temp3;
  385. bb = "maximum restriction NAND " + convertRules(temp3) + "\n\n" + bb;
  386. //print("NAND " + convertRules(temp3) + "\n");
  387. output.print(bb);
  388. //print(bb);
  389. print("selection saved!\n");
  390.  
  391. output.flush();
  392. output.close();
  393. }
  394. if (keyCode == BACKSPACE) {
  395. for (int i = py1/5; i <= py2/5; i++) {
  396. for (int j = px1/5; j <= px2/5; j++) {
  397. //print(j + " " + i + "\n");
  398. if (i < 200 && j < 200) {
  399. tab[j][i] = 0;
  400. rtab[j][i] = 0;
  401. }
  402. }
  403. }
  404. }
  405. if (keyCode == ENTER) {
  406. for (int i = 0; i < 200; i++) {
  407. for (int j = 0; j < 200; j++) {
  408. //print(j + " " + i + "\n");
  409. if (i > py2/5 || i < py1/5 || j > px2/5 || j < px1/5) {
  410. tab[j][i] = 0;
  411. rtab[j][i] = 0;
  412. }
  413. }
  414. }
  415. }
  416. if (keyCode == RIGHT) {
  417. oneframe = 1;
  418. stop = 0;
  419. }
  420. if (key == 'z') { //period
  421. periodb = (periodb + 1)%2;
  422. if (periodb == 0) {
  423. print("period measurement stopped\n");
  424. } else {
  425. print("period measurement started\n");
  426. period = 0;
  427. for (int i = 0; i < 200; i++) {
  428. for (int j = 0; j < 200; j++) {
  429. ptab[i][j] = tab[i][j];
  430. prtab[i][j] = rtab[i][j];
  431. }
  432. }
  433. }
  434. }
  435. if (key == 'c') { //copy
  436. copied = 1;
  437. print("copied\n");
  438. for (int i = py1/5; i <= py2/5; i++) {
  439. for (int j = px1/5; j <= px2/5; j++) {
  440. //print(j + " " + i + "\n");
  441. if (j < 200 && i < 200) {
  442. ctab[j][i] = tab[j][i];
  443. crtab[j][i] = rtab[j][i];
  444. }
  445. }
  446. }
  447. cx1 = px1; cx2 = px2; cy1 = py1; cy2 = py2;
  448. }
  449. if (key == 'v') { //paste
  450. if (copied == 1) {
  451. print("pasted\n");
  452. for (int i = cy1/5; i <= cy2/5; i++) {
  453. for (int j = cx1/5; j <= cx2/5; j++) {
  454. //print(j + " " + i + "\n");
  455. if (j < 200 && i < 200 && j-cx1/5+px1/5 < 200 && i-cy1/5+py1/5 < 200 && j-cx1/5+px1/5 >= 0 && i-cy1/5+py1/5 >=0) {
  456. tab[j-cx1/5+px1/5][i-cy1/5+py1/5] = ctab[j][i];
  457. rtab[j-cx1/5+px1/5][i-cy1/5+py1/5] = crtab[j][i];
  458. }
  459. }
  460. }
  461. }
  462. }
  463. if (key == '5') {
  464. int tmp4 = 0;
  465. for (int i = 0; i < 200; i++) {
  466. for (int j = 0; j < 200; j++) {
  467. tmp4 += tab[i][j];
  468. }
  469. }
  470. println("cell count: " + tmp4);
  471. }
  472. if (key == ' ') { //rotate 90 CW
  473. println("Clipboard rotated");
  474. ctab = rotatecw(ctab);
  475. crtab = rotatecw(crtab);
  476. int tmp = cx1;
  477. cx1 = 1000 - cy1;
  478. cy1 = tmp;
  479. tmp = cx2;
  480. cx2 = 1000 - cy2;
  481. cy2 = tmp;
  482. tmp = cx1;
  483. cx1 = cx2;
  484. cx2 = tmp;
  485. }
  486. if (key == 'm') { //mirror left/right
  487. println("Clipboard mirrored");
  488. ctab = mirrorlr(ctab);
  489. crtab = mirrorlr(crtab);
  490. int tmp = cx1;
  491. cx1 = 1000 - cx2;
  492. cx2 = 1000 - tmp;
  493. }
  494. if (key == 'i') {
  495. String[] lines = loadStrings(readinglist[imported%readinglist.length]);
  496. println("loaded file " + readinglist[imported%readinglist.length] + " (" + str(imported%readinglist.length+1) + "/" + readinglist.length + ")");
  497. imported++;
  498. boolean read = false;
  499. String a = "";
  500. String b = "";
  501. int temp1, temp2;
  502. for (int i = 0 ; i < lines.length; i++) {
  503. if (read) {
  504. a += lines[i];
  505. }
  506. if (lines[i].contains("rulespace")) {
  507. read = true;
  508. } else if (lines[i].contains(";")) {
  509. read = false;
  510. }
  511. }
  512. for (int i = 0 ; i < lines.length; i++) {
  513. if (read) {
  514. b += lines[i];
  515. }
  516. if (lines[i].contains("statespace")) {
  517. read = true;
  518. } else if (lines[i].contains(";")) {
  519. read = false;
  520. }
  521. }
  522. a = a.replace(";", "").replace(" ", "").replace("},{", "s").replace(",", "c").replace("}", "").replace("{", "");
  523. b = b.replace(";", "").replace(" ", "").replace("},{", "s").replace(",", "c").replace("}", "").replace("{", "");
  524. temp1 = 0;
  525. temp2 = 0;
  526. //int[][] tab1 = new int[20][20];
  527. //int[][] tab2 = new int[20][20];
  528. for (String i : a.split("s")) {
  529. for (String j : i.split("c")) {
  530. crtab[temp1][temp2] = int(j);
  531. temp1++;
  532. }
  533. temp2++;
  534. temp1 = 0;
  535. }
  536. temp2 = 0;
  537. for (String i : b.split("s")) {
  538. for (String j : i.split("c")) {
  539. ctab[temp1][temp2] = int(j);
  540. temp1++;
  541. }
  542. temp2++;
  543. temp1 = 0;
  544. }
  545. cx1 = 0;
  546. cx2 = 5*a.split("s")[0].split("c").length;
  547. cy1 = 0;
  548. cy2 = 5*a.split("s").length;
  549. copied = 1;
  550. }
  551. if (key == 'q') { ///collision mode
  552. cmode = (cmode+1)%2;
  553. if (cmode == 1) {
  554. cf = 0;
  555. cf2 = 0;
  556. print("collision mode started\n");
  557. } else {
  558. print("collision mode stopped\n");
  559. //save slog
  560. /*cmode = 0;
  561. PrintWriter output;
  562. output = createWriter("collision_log_" + random + "_" + j + ".txt");
  563. output.print(slog.substring(3, slog.length()));
  564. output.flush();
  565. output.close();
  566. print("collision log saved!\n");*/
  567. }
  568. }
  569. if (key == 'w') { //save ship
  570. print("saved ship\n");
  571. for (int i = py1/5; i <= py2/5; i++) {
  572. for (int j = px1/5; j <= px2/5; j++) {
  573. //print(j + " " + i + "\n");
  574. if (j < 200 && i < 200) {
  575. ship[0][j-px1/5][i-py1/5] = tab[j][i];
  576. rship[0][j-px1/5][i-py1/5] = rtab[j][i];
  577. }
  578. }
  579. }
  580. ship[0][int(mouseX/sf-sx)/5 - px1/5][int(mouseY/sf-sy)/5 - py1/5] += 2;
  581. }
  582.  
  583. if (key == 'e') { //import ships
  584. String[] lines = loadStrings(shippinglist[0]);
  585. println("loaded shipping list " + shippinglist[0]);
  586.  
  587. boolean read;
  588. String a;
  589. String b;
  590. int temp1, temp2;
  591. int c = 0;
  592. int d = 0;
  593.  
  594. while (c < lines.length) {
  595. read = false;
  596. a = "";
  597. b = "";
  598. for (int i = c ; i < lines.length; i++) {
  599. if (read) {
  600. a += lines[i];
  601. }
  602. if (lines[i].contains("rulespace")) {
  603. read = true;
  604. } else if (lines[i].contains(";") && read) {
  605. read = false;
  606. break;
  607. }
  608. }
  609. for (int i = c ; i < lines.length; i++) {
  610. if (read) {
  611. b += lines[i];
  612. }
  613. if (lines[i].contains("statespace")) {
  614. read = true;
  615. } else if (lines[i].contains(";") && read) {
  616. read = false;
  617. c = i + 1;
  618. break;
  619. }
  620. }
  621. a = a.replace(";", "").replace(" ", "").replace("},{", "s").replace(",", "c").replace("}", "").replace("{", "");
  622. b = b.replace(";", "").replace(" ", "").replace("},{", "s").replace(",", "c").replace("}", "").replace("{", "");
  623. temp1 = 0;
  624. temp2 = 0;
  625. //int[][] tab1 = new int[20][20];
  626. //int[][] tab2 = new int[20][20];
  627. //println(d + " " + b);
  628. for (String i : a.split("s")) {
  629. for (String j : i.split("c")) {
  630. rship[d][temp1][temp2] = int(j);
  631. temp1++;
  632. //rship[0][0][0] = 1;
  633. }
  634. temp2++;
  635. temp1 = 0;
  636. }
  637. temp2 = 0;
  638. for (String i : b.split("s")) {
  639. for (String j : i.split("c")) {
  640. ship[d][temp1][temp2] = int(j);
  641. temp1++;
  642. }
  643. temp2++;
  644. temp1 = 0;
  645. }
  646. d++;
  647. }
  648.  
  649. for (int j = 0; j < ship[0][0].length; j++) {
  650. for (int i = 0; i < ship[0].length; i++) {
  651. for (int k = 0; k < 1; k++) {
  652. //print(ship[k][i][j]);
  653. //print(rship[k][i][j]);
  654. }
  655. }
  656. }
  657. }
  658.  
  659. } else { //movemode
  660. if (keyCode == RIGHT) {
  661. for (int i = py1/5; i <= py2/5; i++) {
  662. for (int j = px2/5; j >= px1/5; j--) {
  663. //print(j + " " + i + "\n");
  664. tab[(j+1+200)%200][(i+200)%200] = tab[(j+200)%200][(i+200)%200];
  665. rtab[(j+1+200)%200][(i+200)%200] = rtab[(j+200)%200][(i+200)%200];
  666. }
  667. }
  668. px1 += 5;
  669. px2 += 5;
  670. if (px1 >= 1000 && px2 >= 1000) {
  671. px1 = px1%1000;
  672. px2 = px2%1000;
  673. }
  674. }
  675. if (keyCode == LEFT) {
  676. for (int i = py1/5; i <= py2/5; i++) {
  677. for (int j = px1/5; j <= px2/5; j++) {
  678. //print(j + " " + i + "\n");
  679. tab[(j-1+200)%200][(i+200)%200] = tab[(j+200)%200][(i+200)%200];
  680. rtab[(j-1+200)%200][(i+200)%200] = rtab[(j+200)%200][(i+200)%200];
  681. }
  682. }
  683. px1 -= 5;
  684. px2 -= 5;
  685. if (px1 < 0 && px2 < 0) {
  686. px1 += 1000;
  687. px2 += 1000;
  688. }
  689. }
  690. if (keyCode == DOWN) {
  691. for (int i = py2/5; i >= py1/5; i--) {
  692. for (int j = px1/5; j <= px2/5; j++) {
  693. //print(j + " " + i + "\n");
  694. tab[(j+200)%200][(i+1+200)%200] = tab[(j+200)%200][(i+200)%200];
  695. rtab[(j+200)%200][(i+1+200)%200] = rtab[(j+200)%200][(i+200)%200];
  696. }
  697. }
  698. py1 += 5;
  699. py2 += 5;
  700. if (py1 >= 1000 && py2 >= 1000) {
  701. py1 = py1%1000;
  702. py2 = py2%1000;
  703. }
  704. }
  705. if (keyCode == UP) {
  706. for (int i = py1/5; i <= py2/5; i++) {
  707. for (int j = px1/5; j <= px2/5; j++) {
  708. //print(j + " " + i + "\n");
  709. tab[(j+200)%200][(i-1+200)%200] = tab[(j+200)%200][(i+200)%200];
  710. rtab[(j+200)%200][(i-1+200)%200] = rtab[(j+200)%200][(i+200)%200];
  711. }
  712. }
  713. py1 -= 5;
  714. py2 -= 5;
  715. if (py1 < 0 && py2 < 0) {
  716. py1 += 1000;
  717. py2 += 1000;
  718. }
  719. }
  720. }
  721. if (key == 'x' && selection == 1) {
  722. movemode = (movemode + 1)%2;
  723. if (movemode == 0) {
  724. print("move mode deactivated\n");
  725. } else {
  726. print("move mode activated\n");
  727. }
  728. }
  729. if (key == '+') {
  730. sf *= 1.2;
  731. sx = -px1 + mouseX/sf;
  732. sy = -py1 + mouseY/sf;
  733. }
  734. if (key == '-') {
  735. sf /= 1.2;
  736. sx = -px1 + mouseX/sf;
  737. sy = -py1 + mouseY/sf;
  738. }
  739. if (key == '*') {
  740. sf = 1;
  741. sx = 0;
  742. sy = 0;
  743. }
  744. if (key == '0') {
  745. sx = -px1 + mouseX/sf;
  746. sy = -py1 + mouseY/sf;
  747. }
  748. }
  749.  
  750. void mouseReleased() {
  751. if (mouseButton == LEFT) {
  752. px2 = int(mouseX/sf-sx);
  753. py2 = int(mouseY/sf-sy);
  754. int tmp3;
  755. tmp3 = px1;
  756. px1 = min(px1, px2);
  757. px2 = max(tmp3, px2);
  758. tmp3 = py1;
  759. py1 = min(py1, py2);
  760. py2 = max(tmp3, py2);
  761. selection = 1;
  762. }
  763. }
  764.  
  765. String convertRules(int a) {
  766. String temp2;
  767. temp2 = "B";
  768. for (int i = 0; i < 9; i++) {
  769. if(((a>>9)>>i)%2 == 1){
  770. temp2 += i;
  771. }
  772. }
  773. temp2 += "S";
  774. for (int i = 0; i < 9; i++) {
  775. if((a>>i)%2 == 1){
  776. temp2 += i;
  777. }
  778. }
  779. return temp2;
  780. }
  781.  
  782. int[][] rotatecw(int[][] matrix) {
  783. int n = matrix.length;
  784. int res[][] = new int[n][n];
  785. for (int i = 0; i < n; i++) {
  786. for (int j = 0; j < n; j++) {
  787. res[i][j] = matrix[j][n - i - 1];//matrix[n - j - 1][i];
  788. }
  789. }
  790. return res;
  791. }
  792.  
  793. int[][] mirrorlr(int[][] matrix) {
  794. int n = matrix.length;
  795. int res[][] = new int[n][n];
  796. for (int i = 0; i < n; i++) {
  797. for (int j = 0; j < n; j++) {
  798. res[i][j] = matrix[n-i-1][j];//matrix[n - j - 1][i];
  799. }
  800. }
  801. return res;
  802. }
  803.  
  804. void gcol(int[][] slist) {
  805. //slist [zeile schiffnummer], dann [0] art/phase, [1] dx, [2] dy, [3] drehung, [4] gespiegelt
  806.  
  807. int pcx, pcy;
  808. int[][] tship;
  809. int[][] trship;
  810.  
  811. for (int line = 0; line < slist.length; line++) {
  812. //slist[line]
  813. tship = ship[slist[line][0]];
  814. trship = rship[slist[line][0]];
  815. if (slist[line][4] == 1) {
  816. tship = mirrorlr(tship);
  817. trship = mirrorlr(trship);
  818. }
  819. for (int i = 0; i < slist[line][3]; i++) {
  820. tship = rotatecw(tship);
  821. trship = rotatecw(trship);
  822. }
  823. pcx = 0; pcy = 0;
  824. for (int j = 0; j < tship[0].length; j++) {
  825. for (int i = 0; i < tship.length; i++) {
  826. if (tship[i][j]>>1 == 1) {
  827. pcx = i; pcy = j;
  828. }
  829. }
  830. }
  831. for (int j = 0; j < tship[0].length; j++) {
  832. for (int i = 0; i < tship.length; i++) {
  833. if (tship[i][j]>>1 == 1) {
  834. pcx = i; pcy = j;
  835. }
  836. }
  837. }
  838. int tx, ty;
  839. for (int j = 0; j < tship[0].length; j++) {
  840. for (int i = 0; i < tship.length; i++) {
  841. tx = i-pcx+slist[line][1];
  842. ty = j-pcy+slist[line][2];
  843. if (tx >= 0 && tx < 200 && ty >= 0 && ty < 200 && (tship[i][j]%2 == 1 || trship[i][j] != 0)) {
  844. tab[tx][ty] = tship[i][j]%2;
  845. rtab[tx][ty] = trship[i][j];
  846. }
  847. }
  848. }
  849. }
  850.  
  851. return;
  852. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement