Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /// @description main loop
- switch(ministep) {
- case 0:
- //first population
- for(var i = 0; i < population_size; i++) {
- ai_directions[i, 0] = degtorad(random_range(-180, 180))
- }
- alarm[0] = max_time
- ministep++
- break;
- case 1:
- //running first population
- if (step > 0) population_size = 500
- draw_step = true
- for(var i = 0; i < population_size; i++) {
- if(sqrt(power(ai_x[i]-finishing_circle_x, 2)+power(ai_y[i]-finishing_circle_y, 2)) < 20 ) {
- if(minimum_index == -1) {
- minimum_index = i
- minimum_steps = final_step[i]
- times[step] = max_time - alarm[0]
- ministep++
- }
- if(!counted[i]) amount_hit++
- counted[i] = true;
- ai_moving[i] = false
- }
- }
- for(var i = 0; i < population_size; i++) {
- if (ai_x[i] > 0 and ai_x[i] < 612 and ai_y[i] > 300 and ai_y[i] < 310) {
- ai_moving[i] = false
- //Added these lines
- //These make sure that the system increments the steps for that
- //index of the "population", these also make sure that the
- //"genes" of the "fittest" is passed over properly and completely
- current_step[i]++
- final_step[i]++;
- }
- if (ai_x[i] > 712 and ai_x[i] < 1023 and ai_y[i] > 300 and ai_y[i] < 310) {
- ai_moving[i] = false
- //Added these lines
- //These make sure that the system increments the steps for that
- //index of the "population", these also make sure that the
- //"genes" of the "fittest" is passed over properly and completely
- current_step[i]++
- final_step[i]++;
- }
- }
- if(alarm[0] == 0 and amount_hit>0) {
- draw_step = false
- ministep++
- }
- check = true
- for(var i = 0; i < population_size; i++) {
- if(ai_moving[i] == true ){
- check = false
- }
- }
- //Not sure these lines are essential, but act as a nice little
- //catch if everything goes badly
- /*var check2 = true
- if(check) {
- check2 = false
- for(var i = 0; i < population_size; i++) {
- if(counted[i]) check2 = true;
- }
- }
- if(!check2) {
- room_restart()
- }*/
- if (check) ministep++
- break;
- case 2:
- // another little check
- for(var i = 0; i < population_size; i++) {
- if(final_step[i] <= minimum_steps) {
- minimum_steps = final_step[i]
- minimum_index = i;
- }
- }
- //add fittest
- for (var h = 0; h <minimum_steps; h++) {
- if(minimum_index !=-1) {
- ai_directions[0, h] = ai_directions[minimum_index, h]
- }
- }
- //reset
- for(var i = 1; i < population_size; i++) {
- for (var h = 0; h <minimum_steps; h++) {
- ai_directions[i, h] = 0;
- }
- }
- for(var i = 0; i < population_size; i++) {
- ai_x[i] = x_start;
- ai_y[i] = y_start;
- ai_moving[i] = true;
- current_step[i] = 0;
- final_step[i] = 0;
- counted[i] = false;
- }
- ministep++
- break;
- case 3:
- //make child population
- for(var i = 1; i< population_size; i++) {
- for (var h = 0; h < minimum_steps+50; h++) {
- ai_directions[i, h] = ai_directions[0, h] + random_range(-1,1)
- }
- }
- ministep++
- break;
- case 4:
- //reset
- minimum_index = -1;
- amount_hit = 0;
- step++
- alarm[0] = max_time
- ministep = 1;
- break;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement