SHARE
TWEET

Untitled

a guest Jul 17th, 2019 66 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.         draw_step = false
  54.             ministep++
  55.         }
  56.        
  57.         check = true
  58.         for(var i = 0; i < population_size; i++) {
  59.             if(ai_moving[i] == true ){
  60.                 check = false
  61.             }
  62.         }
  63.        
  64.         //Not sure these lines are essential, but act as a nice little
  65.         //catch if everything goes badly
  66.        
  67.         /*var check2 = true
  68.         if(check) {
  69.             check2 = false
  70.             for(var i = 0; i < population_size; i++) {
  71.                 if(counted[i]) check2 = true;
  72.             }
  73.         }
  74.        
  75.         if(!check2) {
  76.             room_restart()
  77.         }*/
  78.            
  79.  
  80.        
  81.         if (check) ministep++
  82.     break;
  83.     case 2:
  84.         // another little check
  85.         for(var i = 0; i < population_size; i++) {
  86.             if(final_step[i] <= minimum_steps) {
  87.                 minimum_steps = final_step[i]
  88.                 minimum_index = i;
  89.             }
  90.         }
  91.        
  92.         //add fittest
  93.         for (var h = 0; h <minimum_steps; h++) {
  94.             if(minimum_index !=-1) {
  95.                 ai_directions[0, h] = ai_directions[minimum_index, h]
  96.             }
  97.         }
  98.        
  99.  
  100.         //reset
  101.         for(var i = 1; i < population_size; i++) {
  102.             for (var h = 0; h <minimum_steps; h++) {
  103.                 ai_directions[i, h] = 0;
  104.             }
  105.         }
  106.        
  107.         for(var i = 0; i < population_size; i++) {
  108.             ai_x[i] = x_start;
  109.             ai_y[i] = y_start;
  110.             ai_moving[i] = true;
  111.             current_step[i] = 0;
  112.             final_step[i] = 0;
  113.             counted[i] = false;
  114.         }
  115.         ministep++
  116.     break;
  117.     case 3:
  118.         //make child population
  119.         for(var i = 1; i< population_size; i++) {
  120.             for (var h = 0; h < minimum_steps+50; h++) {
  121.                 ai_directions[i, h] = ai_directions[0, h]  + random_range(-1,1)
  122.             }
  123.         }
  124.         ministep++
  125.     break;
  126.     case 4:
  127.         //reset
  128.         minimum_index = -1;
  129.         amount_hit = 0;
  130.        
  131.         step++
  132.         alarm[0] = max_time
  133.         ministep = 1;
  134.     break;
  135. }
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
 
Top