class Tagger { int xpos; int ypos; float yv; float ya; float xv; float xa; float r; int oldx; int oldy; int frozencount; boolean isleader; boolean frozen; color col; int memorycount; int[] memoryx = new int[5000]; int[] memoryy = new int[5000]; int bestx; int besty; float bestfit; //Constructor function for the taggers Tagger(boolean lead) { float x = (lead) ? (random(0,100)):(random(200,width)); float y = (lead) ? (random(0,100)):(random(200,width)); xpos = oldx = int(x); ypos = oldy = int(y); xa = 0; ya = 0; xv = 0; yv = 0; memorycount = 0; frozencount = 0; isleader = lead; frozen = false; if (isleader) { col = color(int(random(100,200)), 0, 0, 101);} else { col = color(int(random(200,255)),59);} bestx = xpos; besty = ypos; bestfit = 0; }; void render() { stroke(col); fill (col); if (frozen) fill(0,160,255,100); ellipse(xpos,ypos,3 + (frozencount/5),3 + (frozencount/5)); line(xpos,ypos,oldx,oldy); }; void update() { oldx = xpos; oldy = ypos; float v = (isleader) ? (hunterspeed):(huntedspeed); xa = random(-v,v); ya = random(-v,v); xv += xa; yv += ya; float axd = (ax - xpos); float ayd = (ay - ypos); if (!isleader) { //AVOIDERS ------------------------------------------ //1. Find the closest tagger - the one to avoid Tagger leader = taggers[0]; float xd = (leader.xpos - xpos); float yd = (leader.ypos - ypos); float d = sqrt((xd*xd) + (yd*yd)); for (int i=0; i freezetime && fd < tagreach) { freezers[j].frozencount = 0; freezers[j].frozen = false; }; }; } else { //TAGGERS --------------------------------------------- // - point where they found the most targets // - point where the group found the most targets //1. Find the average x position of the nearby targets to determine a fitness value int c = 0; float xt = 0; float yt = 0; for (int i=0; i huntercount + 1) { float txd = taggers[i].xpos - xpos; float tyd = taggers[i].ypos - ypos; float d = sqrt((txd*txd) + (tyd*tyd)); // println(d); if (d < float(taggerscope)) { xt += taggers[i].xpos; yt += taggers[i].ypos; c ++; if (d < tagreach) { taggers[i].frozen = true; stroke(0,170,33); line(xpos,ypos, taggers[i].xpos, taggers[i].ypos); lastkill += 50; }; }; }; }; if (c > bestfit) { bestx = xpos; besty = ypos; bestfit = c; memorycount ++; memoryx[memorycount] = xpos; memoryy[memorycount] = ypos; }; if (c > gbestfit) { gbestx = xpos; gbesty = ypos; gbestfit = c;}; fill(0,100); //ellipse(gbestx, gbesty, 10,10); fill(0,200,0,100); //ellipse(bestx, besty, 6,6); bestfit *= 0.99; // ellipse(ax, ay, 10,10); float sx = gbestx + random(-200,200); float sy = gbesty + random(-200,200); float searchx = (lastkill > 0) ? (ax):((sx + ax)/2); float searchy = (lastkill > 0) ? (ay):((sy + ax)/2); float xadj = (((bestx - xpos)/10) + ((gbestx - xpos)/10) + (searchx - xpos)/3); float yadj = (((besty - ypos)/10) + ((gbesty - ypos)/10) + (searchy - ypos)/3); xv += xadj; yv += yadj; }; if (xpos < 0) xv = abs(xv); if (ypos < 0) yv = abs(yv); if (xpos > width) xv = -abs(xv); if (ypos > height) yv = -abs(yv); if (frozen) {xv = 0; yv = 0;}; float vmax = (isleader)?(huntermax):(huntedmax); float cxv = constrain(xv, -vmax, vmax); float cyv = constrain(yv, -vmax, vmax); //println(cxv); xpos += cxv; ypos += cyv; r += 0.001; xv *= 0.9; yv *= 0.9; }; };