// This is where students enter their AI code, replacing the naive one provided below // please explain what the code does in comments and on your project page or report boolean blueInCenter = false; vec AIred(int r, int g, int b) { // Computes acceleration of red ball (index r) given an opponent green ball (g) and a partner ball (b) /* if(B[g].r + B[r].r +5 > n(V(B[g].C,B[r].C))){ //radius touching fill(red); stroke(red); arrow(P(100,100),P(100,200)); noStroke(); } if( n(V(B[g].C,screenCenter())) < n(V(B[r].C,screenCenter()))){ //green is closer then red fill(green); stroke(green); arrow(P(100,100),P(200,100)); noStroke(); } if((dot(U((V(screenCenter(),B[g].C))),U(V(B[r].C,B[g].C))))<= 0){ //red and green are on the same side fill(blue); stroke(blue); arrow(P(100,100),P(200,200)); noStroke(); }*/ if(B[g].r + B[r].r +5 > n(V(B[g].C,B[r].C)) && n(V(B[g].C,screenCenter())) < n(V(B[r].C,screenCenter())) && (dot(U((V(screenCenter(),B[g].C))),U(V(B[r].C,B[g].C))))<= 0 ){ return R(S(200000,V(B[r].C,B[g].C))); //tries to get around the player }else if (abs(dot(U(R(V(B[g].C,screenCenter()))),U(V(B[r].C,screenCenter())))) <= .1 && n(V(B[g].C,screenCenter())) > n(V(B[r].C,screenCenter()))){ return S(200000,U(V(B[r].C,B[g].C))); //tries to push the palyer }else{ return S(200000,V(B[r].C,M(screenCenter(),B[g].C))); // wants to be between the green ball and the center } } vec AIblue(int b, int g, int r) { // Computes acceleration of blue ball (index b) given an opponent (g) and a partner (r) if (blueInCenter){ if(n( V(B[b].C,B[g].C)) <= (B[b].r + B[g].r)+2 && n(V(B[b].C,screenCenter()))>50 || n(V(B[b].C,screenCenter()))>220 || n(V(B[g].C,screenCenter())) < n(V(B[b].C,screenCenter())) ){//|| n(V(B[b].C,B[r].C)) < (B[b].r+B[r].r)+5){ blueInCenter = false; } }else{ if(n(V(B[b].C,screenCenter()))<5){ blueInCenter = true; } } /*if(blueInCenter){ //red and green are on the same side fill(blue); stroke(blue); arrow(P(00,400),P(100,400)); noStroke(); }else{ fill(red); stroke(red); arrow(P(00,400),P(100,400)); noStroke(); }*/ if(B[g].r + B[b].r +5 > n(V(B[g].C,B[b].C)) && n(V(B[g].C,screenCenter())) < n(V(B[b].C,screenCenter())) && (dot(U((V(screenCenter(),B[g].C))),U(V(B[b].C,B[g].C))))<= 0){ return R(S(200000,V(B[b].C,B[g].C))); } if (!blueInCenter){ return S(200000,V(B[b].C,screenCenter())); }else{ return S(200000,U(V(B[b].C,B[g].C))); // wants to be where the green ball is } }