Advertisement
Guest User

Istrolid-crusher max min mutations

a guest
Nov 19th, 2017
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.27 KB | None | 0 0
  1. modloader.loadmod("Util-PartMutator")
  2. crusher =
  3. {
  4. findlowest:function(pop){
  5. intcsafe=0;
  6. lowest=20000;
  7. lowestpos=-1;
  8. while(intcsafe<pop.length)
  9. {
  10. myunit=new types.Unit(pop[intcsafe]);
  11. if(myunit.radius<lowest)
  12. {
  13. console.log("found possible lowest radius: "+myunit.radius);
  14. lowestpos=intcsafe;
  15. lowest=myunit.radius;
  16. }
  17.  
  18. intcsafe=intcsafe+1;
  19. }
  20. console.log("lowest pos found: "+lowestpos);
  21. return lowestpos;
  22. }
  23. ,
  24. fillpop:function(ship,size){
  25. pop=[];
  26. intcsafe=0;
  27. while(intcsafe<size)
  28. {
  29.  
  30. pop.push(ship);
  31. intcsafe=intcsafe+1;
  32. }
  33. return(pop);
  34. }
  35. ,
  36. mutateship:function(ship,mutations)
  37. {
  38. var intc=0;
  39. while(intc<mutations)
  40. {
  41. ship=MOD_PartMutator.Cmoverandompart(ship);
  42. intc=intc+1;
  43. }
  44. return(ship);
  45. }
  46. ,
  47. //takes ship object outputs ship object
  48. crush:function(ship,evolutiontime,mutationmin,mutationmax,populationsize){
  49. topcreature=ship;
  50. pop=[];
  51. magic=0;
  52. while(magic<evolutiontime)
  53. {
  54. var oldtopcreature=topcreature;
  55. topcreature=crusher.mutateship(topcreature,jsstuff.randomrange(mutationmin,mutationmax));
  56. pop=crusher.fillpop(topcreature,populationsize);
  57. //console.log(pop);
  58. pop.push(oldtopcreature);
  59. topcreature=jsstuff.deepcopy(pop[crusher.findlowest(pop)]);
  60. magic=magic+1;
  61. }
  62. return(topcreature);
  63. }
  64. ,
  65. //convert temp to acctual ai
  66. specialparse:function(astringz)
  67. {
  68. if(astringz==""){return "";}
  69. if(astringz==" "){return " ";}
  70. return(JSON.parse(astringz));
  71. }
  72. ,
  73. crushspot:function(shippos,evolutiontime,mutationmin,mutationmax,populationsize)
  74. {
  75. ais.all.temp=jsstuff.deepcopy(commander.buildBar);
  76. ais.all.temp=jsstuff.applyoneach(crusher.specialparse,ais.all.temp);
  77. console.log("ships loaded to temp");
  78. ais.all.temp[shippos]=crusher.crush(ais.all.temp[shippos],evolutiontime,mutationmin,mutationmax,populationsize);
  79. ais.import("temp");
  80. }
  81. }
  82.  
  83. //ais.all.temp=jsstuff.deepcopy(commander.buildBar);
  84. //ais.all.temp=jsstuff.applyoneach(specialparse,ais.all.temp);
  85. //jkl=0;
  86. //while(jkl<10)
  87. //{
  88. // if(ais.all.temp[jkl]!="")
  89. // {
  90. // topcreature=ais.all.temp[jkl];
  91. // crusher.start();
  92. // ais.all.temp[jkl]=topcreature;
  93. // }
  94. // jkl=jkl+1;
  95. //}
  96. //ais.import("temp");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement