Advertisement
Guest User

Cover every Pokemon type

a guest
Oct 13th, 2018
579
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.36 KB | None | 0 0
  1. package notDefault;
  2.  
  3. import java.util.ArrayList;
  4.  
  5. public class Main {
  6. public static boolean[] taken = new boolean[Coverage.attackNames.length];
  7. public static String[] types = new String[10];
  8. public static ArrayList<Coverage> potentialCombos = new ArrayList<Coverage>();
  9.  
  10. public static void main(String[] args) {
  11. // TODO Auto-generated method stub
  12. Coverage.fillChart();
  13. //Coverage.chart = Coverage.chart2;
  14. cur(0, -1);
  15. ArrayList<ArrayList<Coverage>> combos = Coverage.bestCombos(potentialCombos, 1);
  16.  
  17. for(int i = 0; i < Coverage.attackNames.length; i ++) {
  18. types[0] = Coverage.attackNames[i];
  19. //System.out.println(Coverage.attackNames[i] + '\n' + new Coverage(types).bestAddition(2));
  20. }
  21.  
  22. for(int x = 0; x < combos.size(); x ++) {
  23. for(int y = 0; y < combos.get(x).size(); y ++) {
  24. System.out.print(combos.get(x).get(y).toString(true, true, false));
  25. }
  26.  
  27. System.out.print('\n');
  28. }
  29. }
  30.  
  31. public static void cur(int layer, int previousI) {
  32. if(types[types.length - 1] == null) {
  33. for(int i = previousI + 1; i < Coverage.attackNames.length; i ++) {
  34. if(taken[i]) {
  35. continue;
  36. }
  37.  
  38. types[layer] = Coverage.attackNames[i];
  39. taken[i] = true;
  40. cur(layer + 1, i);
  41. taken[i] = false;
  42. types[layer] = null;
  43. }
  44. }else {
  45. /*String input = "";
  46.  
  47. for(int i = 0; i < types.length - 1; i ++) {
  48. input = input + types[i] + ',';
  49. }
  50.  
  51. //System.out.println(input + current[people.size() - 1].name);*/
  52. potentialCombos.add(new Coverage(types));
  53.  
  54. if((int)Math.log(potentialCombos.size()) > (int)Math.log(potentialCombos.size() - 1)) {
  55. System.out.println(potentialCombos.size());
  56. }
  57. }
  58. }
  59. }
  60.  
  61. package notDefault;
  62.  
  63. import java.util.ArrayList;
  64.  
  65. public class Coverage implements Comparable<Coverage>{
  66. public static String[] defenseNames = {"normal", "fire", "water", "electric", "grass", "ice", "fighting", "poison", "ground",
  67. "flying", "psychic", "bug", "rock", "ghost", "dragon", "dark", "steel", "fairy"};
  68. public static String[] attackNames = {"normal", "fire", "water", "electric", "grass", "ice", "fighting", "poison", "ground",
  69. "flying", "psychic", "bug", "rock", "ghost", "dragon", "dark", "steel", "fairy", "freeze-dry"};
  70. public static double[][] chart2 = new double[17][17];
  71. public static double[][] chart6 = new double[19][18];
  72. public static double[][] chart = chart6;
  73. private String[] types;
  74. private int[] stats = new int[3];
  75. private ArrayList<String> notVery = new ArrayList<String>();
  76. private ArrayList<String> regular = new ArrayList<String>();
  77. private ArrayList<String> supe = new ArrayList<String>();
  78.  
  79. public Coverage(String[] input) {
  80. /*for(int i = 0; i < input.length; i ++) {
  81. System.out.println(input[i]);
  82. }*/
  83.  
  84. types = copyArray(input);
  85. //System.out.println(chart6[0].length + " " + chart6.length);
  86.  
  87. for(int i = 0; i < chart[0].length; i ++) {
  88. for(int j = 0; j < chart[0].length; j ++) {
  89. if(i > j) {
  90. continue;
  91. }
  92.  
  93. double maxEffectiveness = 0.0;
  94. String comboName = defenseNames[i] + " " + defenseNames[j];
  95.  
  96. if(i == j){
  97. comboName = defenseNames[i];
  98.  
  99. for(String type : types) {
  100. //System.out.println(type);
  101. if(indexOf(attackNames, type) < chart.length) {
  102. //System.out.println(type);
  103. maxEffectiveness = Math.max(maxEffectiveness, chart[indexOf(attackNames, type)][i]);
  104.  
  105. /*if("freeze-dry".equals(type)) {
  106. System.out.println(" " + chart[indexOf(attackNames, type)][i]);
  107. }*/
  108. }
  109. }
  110. }else {
  111. for(String type : types) {
  112. //System.out.println(getIndex(attackNames, type) + " " + chart[0].length);
  113. if(indexOf(attackNames, type) < chart.length) {
  114. maxEffectiveness = Math.max(maxEffectiveness,
  115. chart[indexOf(attackNames, type)][i] * chart[indexOf(attackNames, type)][j]);
  116. }
  117. }
  118. }
  119.  
  120. if(maxEffectiveness < 1.0) {
  121. notVery.add(comboName);
  122. }else if(maxEffectiveness == 1.0) {
  123. regular.add(comboName);
  124. }else{
  125. supe.add(comboName);
  126. }
  127. }
  128. }
  129.  
  130. stats[0] = notVery.size();
  131. stats[1] = regular.size();
  132. stats[2] = supe.size();
  133. }
  134.  
  135. public String bestAddition(int additions) {
  136. ArrayList<Coverage> potentialCombos = new ArrayList<Coverage>();
  137. String[] potentialTypes = new String[types.length + 1];
  138.  
  139. for(int i = 0; i < types.length; i ++) {
  140. potentialTypes[i] = types[i];
  141. }
  142.  
  143. for(int x = 0; x < attackNames.length; x ++) {
  144. potentialTypes = copyArray(potentialTypes);
  145. potentialTypes[types.length] = attackNames[x];
  146. potentialCombos.add(new Coverage(potentialTypes));
  147.  
  148. /*for(int y = 0; y < additions; y ++) {
  149. if(potentialCombo.compareTo(bestAdditions[y]) > 0) {
  150. shift(bestAdditions, potentialCombo, y);
  151. break;
  152. }
  153. }*/
  154. }
  155.  
  156. ArrayList<ArrayList<Coverage>> bestAdditions = bestCombos(potentialCombos, additions);
  157. String out = "Best Additions \n";
  158.  
  159. for(int x = 0; x < additions; x ++) {
  160. for(int y = 0; y < bestAdditions.get(x).size(); y ++) {
  161. out = out + differTypes(bestAdditions.get(x).get(y));
  162. }
  163.  
  164. out = out + '\n';
  165. }
  166.  
  167. return(out);
  168. }
  169.  
  170. public static void shift(Object[] array, Object insert, int index) {
  171. for(int i = array.length - 1; i > index; i --) {
  172. array[i] = array[i - 1];
  173. }
  174.  
  175. array[index] = insert;
  176. }
  177.  
  178. public static void shift(int[] array, int insert, int index) {
  179. for(int i = array.length - 1; i > index; i --) {
  180. array[i] = array[i - 1];
  181. }
  182.  
  183. array[index] = insert;
  184. }
  185.  
  186. /*public String bestAddition2() {
  187. int minNotVery = 170;
  188. int minNotVery2 = 171;
  189. int maxSuper = 1;
  190. int maxSuper2 = 0;
  191. String bestType = "normal";
  192. String bestType2 = "fire";
  193. String[] potentialTypes = new String[types.length + 1];
  194.  
  195. for(int i = 0; i < types.length; i ++) {
  196. potentialTypes[i] = types[i];
  197. }
  198.  
  199. for(String type : attackNames) {
  200. potentialTypes[types.length] = type;
  201. Coverage potentialCombo = new Coverage(potentialTypes);
  202.  
  203. if(potentialCombo.effectivenesses[0] < minNotVery) {
  204. bestType2 = bestType;
  205. minNotVery2 = minNotVery;
  206. maxSuper2 = maxSuper;
  207. bestType = type;
  208. minNotVery = potentialCombo.effectivenesses[0];
  209. maxSuper = potentialCombo.effectivenesses[2];
  210. }else if(potentialCombo.effectivenesses[0] == minNotVery && (potentialCombo.effectivenesses[2] > maxSuper)) {
  211. bestType2 = bestType;
  212. minNotVery2 = minNotVery;
  213. maxSuper2 = maxSuper;
  214. bestType = type;
  215. minNotVery = potentialCombo.effectivenesses[0];
  216. maxSuper = potentialCombo.effectivenesses[2];
  217. }else if(potentialCombo.effectivenesses[0] < minNotVery2) {
  218. bestType2 = type;
  219. minNotVery2 = potentialCombo.effectivenesses[0];
  220. maxSuper2 = potentialCombo.effectivenesses[2];
  221. }else if(potentialCombo.effectivenesses[0] == minNotVery2 && (potentialCombo.effectivenesses[2] > maxSuper2)) {
  222. bestType2 = type;
  223. minNotVery2 = potentialCombo.effectivenesses[0];
  224. maxSuper2 = potentialCombo.effectivenesses[2];
  225. }
  226. }
  227.  
  228. return(bestType + " " + bestType2);
  229. }*/
  230.  
  231. public static void setGeneration(int generation) {
  232. if((generation > 1) && (generation < 6)) {
  233. chart = chart2;
  234. }else {
  235. chart = chart6;
  236. }
  237. }
  238.  
  239. @Override
  240. public String toString() {
  241. return(toString(false, true, false));
  242. }
  243.  
  244. public String toString(boolean getTypes, boolean getStats, boolean getEffectivenesses) {
  245. String out = "";
  246.  
  247. if(getTypes) {
  248. out = out + getTypes() + '\n';
  249. }
  250.  
  251. if(getStats) {
  252. out = out + getStats() + '\n';
  253. }
  254.  
  255. if(getEffectivenesses) {
  256. out = out + getEffectivenesses() + '\n';
  257. }
  258.  
  259. return(out);
  260. }
  261.  
  262. public String getTypes() {
  263. String out = "";
  264.  
  265. for(int i = 0; i < types.length; i ++) {
  266. out = out + types[i] + " ";
  267. }
  268.  
  269. return(out);
  270. }
  271.  
  272. public String getStats() {
  273. return("Not very effective: " + stats[0] + " Regular effectiveness: " + stats[1] + " Super effective: " + stats[2]);
  274. }
  275.  
  276. public String getEffectivenesses() {
  277. return("Not very effective: " + notVery + " \nRegular effectiveness: " + regular + " \nSuper effective: " + supe);
  278. }
  279.  
  280. /*public String toStringWithTypes() {
  281. return(getTypes() + '\n' + toString());
  282. }*/
  283.  
  284. public String differTypes(Coverage other) {
  285. String[] typesCopy = new String[other.types.length];
  286. String out = "";
  287.  
  288. for(int i = 0; i < typesCopy.length; i ++) {
  289. //System.out.println(typesCopy.length + " " + other.types.length + " " + i);
  290. typesCopy[i] = other.types[i];
  291. }
  292.  
  293. for(int x = 0; x < types.length; x ++) {
  294. for(int y = 0; y < typesCopy.length; y ++) {
  295. if(types[x].equals(typesCopy[y])) {
  296. typesCopy[y] = "";
  297. }
  298. }
  299. }
  300.  
  301. for(int i = 0; i < typesCopy.length; i ++) {
  302. if(!typesCopy[i].isEmpty()) {
  303. out = out + typesCopy[i] + " ";
  304. }
  305. }
  306.  
  307. return(out);
  308. }
  309.  
  310. public static int indexOf(String[] array, String string) {
  311. for(int i = 0; i < array.length; i ++) {
  312. String maybeSubstring = string;
  313. String maybeSubarray = array[i];
  314.  
  315. if((array.length > 14) && (array.length < 20)) {
  316. maybeSubstring = string.substring(0, 3);
  317. maybeSubarray = array[i].substring(0, 3);
  318. }
  319.  
  320. if(maybeSubstring.equals(maybeSubarray)) {
  321. return(i);
  322. }
  323. }
  324.  
  325. System.out.println(string + " is making me return -1!");
  326. return(-1);
  327. }
  328.  
  329. public static void fillChart() {
  330. for(int i = 0; i < chart6.length; i ++) {
  331. for(int j = 0; j < chart6[i].length; j++) {
  332. chart6[i][j] = 1.0;
  333. }
  334. }
  335.  
  336. for(int i = 0; i < chart2.length; i ++) {
  337. for(int j = 0; j < chart2[i].length; j++) {
  338. chart2[i][j] = 1.0;
  339. }
  340. }
  341.  
  342. chart = chart2;
  343.  
  344. a("nor", "gho");
  345. a("ele", "gro");
  346. a("fig", "gho");
  347. a("poi", "ste");
  348. a("gro", "fly");
  349. a("psy", "dar");
  350. a("gho", "nor");
  351.  
  352. b("nor", "roc");
  353. b("nor", "ste");
  354. b("fir", "fir");
  355. b("fir", "wat");
  356. b("fir", "roc");
  357. b("fir", "dra");
  358. b("wat", "wat");
  359. b("wat", "gra");
  360. b("wat", "dra");
  361. b("ele", "ele");
  362. b("ele", "gra");
  363. b("ele", "dra");
  364. b("gra", "fir");
  365. b("gra", "gra");
  366. b("gra", "poi");
  367. b("gra", "fly");
  368. b("gra", "bug");
  369. b("gra", "dra");
  370. b("gra", "ste");
  371. b("ice", "fir");
  372. b("ice", "wat");
  373. b("ice", "ice");
  374. b("ice", "ste");
  375. b("fig", "poi");
  376. b("fig", "fly");
  377. b("fig", "psy");
  378. b("fig", "bug");
  379. b("poi", "poi");
  380. b("poi", "gro");
  381. b("poi", "roc");
  382. b("poi", "gho");
  383. b("gro", "gra");
  384. b("gro", "bug");
  385. b("fly", "ele");
  386. b("fly", "roc");
  387. b("fly", "ste");
  388. b("psy", "psy");
  389. b("psy", "ste");
  390. b("bug", "fir");
  391. b("bug", "fig");
  392. b("bug", "poi");
  393. b("bug", "fly");
  394. b("bug", "gho");
  395. b("bug", "ste");
  396. b("roc", "fig");
  397. b("roc", "gro");
  398. b("roc", "ste");
  399. b("gho", "dar");
  400. b("gho", "ste");
  401. b("dra", "ste");
  402. b("dar", "fig");
  403. b("dar", "dar");
  404. b("dar", "ste");
  405. b("ste", "fir");
  406. b("ste", "wat");
  407. b("ste", "ele");
  408. b("ste", "ste");
  409.  
  410. c("fir", "gra");
  411. c("fir", "ice");
  412. c("fir", "bug");
  413. c("fir", "ste");
  414. c("wat", "fir");
  415. c("wat", "gro");
  416. c("wat", "roc");
  417. c("ele", "wat");
  418. c("ele", "fly");
  419. c("gra", "wat");
  420. c("gra", "gro");
  421. c("gra", "roc");
  422. c("ice", "gra");
  423. c("ice", "gro");
  424. c("ice", "fly");
  425. c("ice", "dra");
  426. c("fig", "nor");
  427. c("fig", "ice");
  428. c("fig", "roc");
  429. c("fig", "dar");
  430. c("fig", "ste");
  431. c("poi", "gra");
  432. c("gro", "fir");
  433. c("gro", "ele");
  434. c("gro", "poi");
  435. c("gro", "roc");
  436. c("gro", "ste");
  437. c("fly", "gra");
  438. c("fly", "fig");
  439. c("fly", "bug");
  440. c("psy", "fig");
  441. c("psy", "poi");
  442. c("bug", "gra");
  443. c("bug", "psy");
  444. c("bug", "roc");
  445. c("roc", "fir");
  446. c("roc", "ice");
  447. c("roc", "fly");
  448. c("roc", "bug");
  449. c("gho", "psy");
  450. c("gho", "gho");
  451. c("dra", "dra");
  452. c("dar", "psy");
  453. c("dar", "gho");
  454. c("ste", "ice");
  455. c("ste", "roc");
  456.  
  457. chart = chart6;
  458. //System.out.println(chart[1][1]);
  459.  
  460. for(int i = 0; i < chart2.length; i ++) {
  461. for(int j = 0; j < chart2[i].length; j++) {
  462. chart6[i][j] = chart2[i][j];
  463. }
  464. }
  465.  
  466. n("gho", "ste");
  467. n("dar", "ste");
  468. a("dra", "fai");
  469. b("fig", "fai");
  470. b("bug", "fai");
  471. b("dar", "fai");
  472. c("poi", "fai");
  473. c("ste", "fai");
  474. b("fai", "fir");
  475. b("fai", "poi");
  476. b("fai", "ste");
  477. c("fai", "fig");
  478. c("fai", "dra");
  479. c("fai", "dar");
  480. b("fre", "fir");
  481. b("fre", "ice");
  482. b("fre", "ste");
  483. c("fre", "wat");
  484. c("fre", "gra");
  485. c("fre", "gro");
  486. c("fre", "fly");
  487. c("fre", "dra");
  488. }
  489.  
  490. public static void a(String attack, String defense) {
  491. chart[indexOf(attackNames, attack)][indexOf(defenseNames, defense)] = 0.0;
  492. }
  493.  
  494. public static void b(String attack, String defense) {
  495. chart[indexOf(attackNames, attack)][indexOf(defenseNames, defense)] = 0.5;
  496. }
  497.  
  498. public static void c(String attack, String defense) {
  499. chart[indexOf(attackNames, attack)][indexOf(defenseNames, defense)] = 2.0;
  500. }
  501.  
  502. public static void n(String attack, String defense) {
  503. chart[indexOf(attackNames, attack)][indexOf(defenseNames, defense)] = 1.0;
  504. }
  505.  
  506. public static ArrayList<ArrayList<Coverage>> bestCombos(ArrayList<Coverage> combos, int outputSize){
  507. ArrayList<ArrayList<Coverage>> out = new ArrayList<ArrayList<Coverage>>();
  508. out.add(combos);
  509.  
  510. while(out.size() < outputSize) {
  511. out.add(new ArrayList<Coverage>());
  512. }
  513.  
  514. for(int x = 0; x < outputSize; x ++) {
  515. boolean different = true;
  516. ArrayList<Coverage> nextList = new ArrayList<Coverage>();
  517.  
  518. try {
  519. nextList = out.get(x + 1);
  520. }catch(IndexOutOfBoundsException exception) {}
  521.  
  522. while(different) {
  523. different = false;
  524. int ties = 1;
  525. //System.out.println("reached0");
  526.  
  527. while(ties < out.get(x).size()) {
  528. if(out.get(x).get(0).compareTo(out.get(x).get(ties)) > 0){
  529. nextList.add(out.get(x).remove(ties));
  530. different = true;
  531. }else if(out.get(x).get(0).compareTo(out.get(x).get(ties)) < 0) {
  532. for(int y = 0; y < ties; y ++) {
  533. nextList.add(out.get(x).remove(0));
  534. }
  535.  
  536. ties = 1;
  537. different = true;
  538. }else if(out.get(x).get(0).compareTo(out.get(x).get(ties)) == 0){
  539. ties ++;
  540. }else {
  541. System.out.println(out.get(x).get(0).toString(true, true, true) + " and " + out.get(x).get(ties).toString(true, true, true) + " were not better, worse, or equal!");
  542. }
  543. }
  544. }
  545. }
  546.  
  547. return(out);
  548. }
  549.  
  550. public static String[] copyArray(String[] in) {
  551. String[] out = new String[in.length];
  552.  
  553. for(int i = 0; i < in.length; i ++) {
  554. out[i] = in[i];
  555. }
  556.  
  557. return(out);
  558. }
  559.  
  560. public int compareTo(Coverage other) {
  561. if(other == null) {
  562. return(1);
  563. }
  564.  
  565. if(stats[0] == other.stats[0]) {
  566. return(stats[2] - other.stats[2]);
  567. }
  568.  
  569. return(other.stats[0] - stats[0]);
  570. }
  571.  
  572. public boolean equals(Coverage other) {
  573. return(compareTo(other) == 0);
  574. }
  575. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement