Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- modloader.loadmod("Util-PartMutator")
- crusher =
- {
- findlowest:function(pop){
- intcsafe=0;
- lowest=20000;
- lowestpos=-1;
- while(intcsafe<pop.length)
- {
- myunit=new types.Unit(pop[intcsafe]);
- if(myunit.radius<lowest)
- {
- console.log("found possible lowest radius: "+myunit.radius);
- lowestpos=intcsafe;
- lowest=myunit.radius;
- }
- intcsafe=intcsafe+1;
- }
- console.log("lowest pos found: "+lowestpos);
- return lowestpos;
- }
- ,
- fillpop:function(ship,size){
- pop=[];
- intcsafe=0;
- while(intcsafe<size)
- {
- pop.push(ship);
- intcsafe=intcsafe+1;
- }
- return(pop);
- }
- ,
- mutateship:function(ship,mutations)
- {
- var intc=0;
- while(intc<mutations)
- {
- ship=MOD_PartMutator.Cmoverandompart(ship);
- intc=intc+1;
- }
- return(ship);
- }
- ,
- //takes ship object outputs ship object
- crush:function(ship,evolutiontime,mutationmin,mutationmax,populationsize){
- topcreature=ship;
- pop=[];
- magic=0;
- while(magic<evolutiontime)
- {
- var oldtopcreature=topcreature;
- topcreature=crusher.mutateship(topcreature,jsstuff.randomrange(mutationmin,mutationmax));
- pop=crusher.fillpop(topcreature,populationsize);
- //console.log(pop);
- pop.push(oldtopcreature);
- topcreature=jsstuff.deepcopy(pop[crusher.findlowest(pop)]);
- magic=magic+1;
- }
- return(topcreature);
- }
- ,
- //convert temp to acctual ai
- specialparse:function(astringz)
- {
- if(astringz==""){return "";}
- if(astringz==" "){return " ";}
- return(JSON.parse(astringz));
- }
- ,
- crushspot:function(shippos,evolutiontime,mutationmin,mutationmax,populationsize)
- {
- ais.all.temp=jsstuff.deepcopy(commander.buildBar);
- ais.all.temp=jsstuff.applyoneach(crusher.specialparse,ais.all.temp);
- console.log("ships loaded to temp");
- ais.all.temp[shippos]=crusher.crush(ais.all.temp[shippos],evolutiontime,mutationmin,mutationmax,populationsize);
- ais.import("temp");
- }
- }
- //ais.all.temp=jsstuff.deepcopy(commander.buildBar);
- //ais.all.temp=jsstuff.applyoneach(specialparse,ais.all.temp);
- //jkl=0;
- //while(jkl<10)
- //{
- // if(ais.all.temp[jkl]!="")
- // {
- // topcreature=ais.all.temp[jkl];
- // crusher.start();
- // ais.all.temp[jkl]=topcreature;
- // }
- // jkl=jkl+1;
- //}
- //ais.import("temp");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement