Advertisement
Guest User

Type Coverage parser

a guest
Jun 22nd, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var eff = [[0,-1,0,0,0,0,0,2,0,0,0,0,0,0,0,0,0,0],
  2. [0,0,-1,0,0,1,1,0,0,0,0,0,0,-1,0,0,1,-1],
  3. [0,1,0,0,2,-1,1,0,0,0,0,1,-1,0,-1,0,0,0],
  4. [0,1,0,1,-1,0,1,0,0,0,0,1,0,-1,0,0,0,1],
  5. [0,0,0,1,0,1,0,0,0,0,-1,-1,2,0,-1,0,0,0],
  6. [1,-1,1,1,-1,0,0,0,-1,1,-1,-1,0,0,0,0,0,0],
  7. [0,1,-1,0,1,-1,0,0,0,-1,0,1,0,0,0,0,0,0],
  8. [0,2,0,1,0,0,1,-1,0,0,0,0,0,0,0,0,-1,0],
  9. [1,-1,1,2,-1,1,1,0,1,-1,0,1,0,1,1,1,0,1],
  10. [0,0,0,0,-1,-1,1,0,1,1,-1,1,0,0,1,0,0,1],
  11. [0,0,0,0,0,0,0,0,1,1,1,-1,-1,0,1,0,0,0],
  12. [0,0,-1,-1,1,0,-1,0,0,-1,1,1,1,0,-1,0,0,0],
  13. [0,0,1,0,-1,0,0,0,1,0,0,0,1,0,0,0,0,0],
  14. [0,1,0,0,0,0,-1,-1,0,0,0,0,0,1,0,0,-1,0],
  15. [0,-1,0,0,0,-1,0,0,-1,-1,0,0,0,0,1,0,0,0],
  16. [0,0,0,0,0,0,0,0,0,1,1,1,1,0,-1,-1,0,-1],
  17. [0,-1,0,0,0,0,-1,1,0,0,0,0,0,2,0,0,1,-1],
  18. [0,1,0,-1,0,0,1,0,-1,0,0,0,0,0,0,2,1,0]];
  19.  
  20. var aeff = [[0,0,0,0,0,-1,0,-2,-1,0,0,0,0,0,0,0,0,0],
  21. [1,0,-1,-1,0,1,-1,-2,1,0,0,0,0,-1,1,0,1,-1],
  22. [0,1,0,0,0,-1,1,0,-1,0,0,1,-1,0,0,0,0,0],
  23. [0,0,0,-1,-1,-1,0,-1,-2,0,0,1,0,0,0,0,0,1],
  24. [0,0,-2,1,0,1,-1,0,1,1,0,-1,1,0,0,0,0,0],
  25. [0,-1,1,0,-1,0,1,0,-1,1,0,0,0,0,1,0,0,0],
  26. [0,-1,-1,-1,0,0,0,-1,-1,-1,0,1,0,1,0,0,1,-1],
  27. [-2,0,0,0,0,0,0,1,0,0,0,0,0,1,0,0,-1,0],
  28. [0,0,0,0,0,1,0,0,-1,-1,-1,0,-1,0,1,0,0,1],
  29. [0,0,0,0,0,-1,1,0,1,-1,-1,1,0,0,1,-1,0,0],
  30. [0,0,0,0,1,1,0,0,0,1,-1,-1,0,0,0,-1,0,0],
  31. [0,0,-1,-1,1,1,-1,0,-1,-1,1,-1,0,0,0,-1,0,0],
  32. [0,0,1,0,-2,0,0,0,0,0,1,-1,-1,0,0,-1,0,0],
  33. [0,1,0,1,0,0,0,0,-1,0,0,0,0,-1,0,0,-2,0],
  34. [0,0,1,0,1,0,0,0,-1,-1,-1,1,0,0,-1,1,0,0],
  35. [0,0,0,0,0,0,0,0,-1,0,0,0,0,0,0,1,0,-2],
  36. [0,-1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,-1,-1],
  37. [0,1,0,-1,0,0,0,0,-1,-1,0,0,0,0,0,1,1,0]];
  38.  
  39. var types = ['normal','fighting','flying','poison','ground','rock','bug','ghost','steel','fire','water','grass','electric','psychic','ice','dragon','dark','fairy'];
  40.  
  41.  
  42.  
  43. var hiscore = 0;
  44. var hiteam = [[]];
  45. var hieff = [[[],[]]];
  46. var start = new Date().getTime();
  47.  
  48. types.slice().forEach(function(type,index) {
  49.     //type = 'normal';
  50.     //index = 0;
  51.     var team = [type];
  52.     var score = 0;
  53.     var def = [[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]];
  54.     types.forEach(function(type2,index2){
  55.         index2 += 18-types.length;
  56.         if (team.indexOf(type2) === -1) {
  57.             team.push(type2);
  58.             types.forEach(function(type3,index3){
  59.                 index3 += 18-types.length;
  60.                 if (team.indexOf(type3) === -1) {
  61.                     team.push(type3);
  62.                     types.forEach(function(type4,index4){
  63.                         index4 += 18-types.length;
  64.                         if (team.indexOf(type4) === -1) {
  65.                             team.push(type4);
  66.                             types.forEach(function(type5,index5){
  67.                                 index5 += 18-types.length;
  68.                                 if (team.indexOf(type5) === -1) {
  69.                                     team.push(type5);
  70.                                     types.forEach(function(type6,index6){
  71.                                         index6 += 18-types.length;
  72.                                         if (team.indexOf(type6) === -1) {
  73.                                             team.push(type6);
  74.                                             // Evaluate Team
  75.                                             def[1] = selectHighestValues(eff[index], eff[index2], eff[index3], eff[index4], eff[index5], eff[index6]);
  76.                                             def[0] = selectHighestValues(aeff[index], aeff[index2], aeff[index3], aeff[index4], aeff[index5], aeff[index6]);
  77.                                             score = def[1].reduce(getSum) + (5 * def[0].reduce(getSum));
  78.                                             if (score > hiscore) {
  79.                                                 hiscore = score;
  80.                                                 hiteam = [team.slice().sort()];
  81.                                                 hieff = [def.slice()];
  82.                                             } else if (score === hiscore) {
  83.                                                 hiteam.push(team.slice().sort());
  84.                                                 hieff.push(def.slice());
  85.                                             }
  86.                                             team.pop();
  87.                                         }
  88.                                     });
  89.                                     team.pop();
  90.                                 }
  91.                             });
  92.                             team.pop();
  93.                         }
  94.                     });
  95.                     team.pop();
  96.                 }
  97.             });
  98.             team.pop();
  99.         }
  100.     });
  101.     types.shift();
  102. });
  103.  
  104. hiteam.forEach(function(val){console.log(val);});
  105. console.log(hieff[0]);
  106. console.log(hiteam.length);
  107. console.log(hiscore);
  108. console.log(new Date().getTime() - start);
  109.  
  110.  
  111.  
  112. function selectHighestValues (arr1, arr2, arr3, arr4, arr5, arr6) {
  113.     var length = arr1.length;
  114.     var arr = [];
  115.     for (var i = 0; i < length; i++) {
  116.         arr[i] = Math.max(arr1[i], arr2[i], arr3[i], arr4[i], arr5[i], arr6[i], 0);
  117.     }
  118.     return arr;
  119. }
  120.  
  121. function getSum(total, num) {
  122.     return total + num;
  123. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement