SHARE
TWEET

Untitled

a guest Jul 17th, 2019 70 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /// @description main loop
  2.  
  3. switch(ministep) {
  4.     case 0:
  5.         //first population
  6.         for(var i = 0; i < population_size; i++) {
  7.             ai_directions[i, 0] = degtorad(random_range(-180, 180))
  8.         }
  9.         alarm[0] = max_time
  10.         ministep++
  11.     break;
  12.     case 1:
  13.         //running first population
  14.         if (step > 0) population_size = 500
  15.         draw_step = true
  16.         for(var i = 0; i < population_size; i++) {                                
  17.             if(sqrt(power(ai_x[i]-finishing_circle_x, 2)+power(ai_y[i]-finishing_circle_y, 2)) < 20 ) {
  18.                 if(minimum_index == -1) {
  19.                     minimum_index = i
  20.                     minimum_steps = final_step[i]
  21.                     times[step] = max_time - alarm[0]
  22.                     ministep++
  23.                 }
  24.                 if(!counted[i]) amount_hit++
  25.                 counted[i] = true;
  26.                 ai_moving[i] = false
  27.             }
  28.         }
  29.        
  30.         for(var i = 0; i < population_size; i++) {
  31.              if (ai_x[i] > 0 and ai_x[i] < 612 and ai_y[i] > 300 and ai_y[i] < 310) {
  32.                  ai_moving[i] = false
  33.                  //Added these lines
  34.                  //These make sure that the system increments the steps for that
  35.                  //index of the "population", these also make sure that the
  36.                  //"genes" of the "fittest" is passed over properly and completely
  37.                  current_step[i]++
  38.                  final_step[i]++;
  39.  
  40.              }
  41.              if (ai_x[i] > 712 and ai_x[i] < 1023 and ai_y[i] > 300 and ai_y[i] < 310) {
  42.                  ai_moving[i] = false
  43.                  //Added these lines
  44.                  //These make sure that the system increments the steps for that
  45.                  //index of the "population", these also make sure that the
  46.                  //"genes" of the "fittest" is passed over properly and completely
  47.                  current_step[i]++
  48.                  final_step[i]++;
  49.  
  50.              }
  51.          }
  52.         if(alarm[0] == 0 and amount_hit>0) {
  53.             //This line here wasn't indented properly
  54.             draw_step = false
  55.             ministep++
  56.         }
  57.        
  58.         check = true
  59.         for(var i = 0; i < population_size; i++) {
  60.             if(ai_moving[i] == true ){
  61.                 check = false
  62.             }
  63.         }
  64.        
  65.         //Not sure these lines are essential, but act as a nice little
  66.         //catch if everything goes badly
  67.        
  68.         /*var check2 = true
  69.         if(check) {
  70.             check2 = false
  71.             for(var i = 0; i < population_size; i++) {
  72.                 if(counted[i]) check2 = true;
  73.             }
  74.         }
  75.        
  76.         if(!check2) {
  77.             room_restart()
  78.         }*/
  79.            
  80.  
  81.        
  82.         if (check) ministep++
  83.     break;
  84.     case 2:
  85.         // another little check
  86.         /*for(var i = 0; i < population_size; i++) {
  87.             if(final_step[i] <= minimum_steps) {
  88.                 minimum_steps = final_step[i]
  89.                 minimum_index = i;
  90.             }
  91.         }*/
  92.        
  93.         //add fittest
  94.         for (var h = 0; h <minimum_steps; h++) {
  95.             if(minimum_index !=-1) {
  96.                 ai_directions[0, h] = ai_directions[minimum_index, h]
  97.             }
  98.         }
  99.        
  100.  
  101.         //reset
  102.         for(var i = 1; i < population_size; i++) {
  103.             for (var h = 0; h <minimum_steps; h++) {
  104.                 ai_directions[i, h] = 0;
  105.             }
  106.         }
  107.        
  108.         for(var i = 0; i < population_size; i++) {
  109.             ai_x[i] = x_start;
  110.             ai_y[i] = y_start;
  111.             ai_moving[i] = true;
  112.             current_step[i] = 0;
  113.             final_step[i] = 0;
  114.             counted[i] = false;
  115.         }
  116.         ministep++
  117.     break;
  118.     case 3:
  119.         //make child population
  120.         for(var i = 1; i< population_size; i++) {
  121.             //Removed the +50 here as I don't think it's important
  122.             for (var h = 0; h < minimum_steps; h++) {
  123.                 ai_directions[i, h] = ai_directions[0, h]  + random_range(-1,1)
  124.             }
  125.         }
  126.         ministep++
  127.     break;
  128.     case 4:
  129.         //reset
  130.         minimum_index = -1;
  131.         amount_hit = 0;
  132.        
  133.         step++
  134.         alarm[0] = max_time
  135.         ministep = 1;
  136.     break;
  137. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top