void attack(int count1)
{
        double randnum1;
        double randnum2;
	double distance;
	double tmpX1, tmpY1, tmpX2, tmpY2;
	int i;
        

	//printf("ts.tv_nsec: %d\n", ts.tv_nsec);
        /* initialize random seed: */
        srand ( time(NULL) + count1);
        randnum1 = rand() % 50;
	//printf("rand1: %lf\n", randnum1);

	//calculate if within 2 or sqrt(8) of an enemy initiate attack

		tmpX1 = soldier[count1].X;
		tmpY1 = soldier[count1].Y;

	//attack anyone that borders him

		for(i = 0; i < 18; i++) {
			//if neither soldier is dead or on the same team
			if(soldier[i].team != soldier[count1].team && soldier[i].alive != 0 && soldier[count1].alive != 0) {

				tmpX2 = soldier[i].X;
				tmpY2 = soldier[i].Y;

                		if(DIST(tmpX1, tmpY1, tmpX2, tmpY2) == 2 || DIST(tmpX1, tmpY1, tmpX2, tmpY2) == sqrt(8)) {
					srand ( time(NULL)+1.1+i );
				        randnum2 = rand() % 50;
					//printf("rand2: %lf\n", randnum2);
				        if(randnum1>=randnum2) {
                				soldier[count1].alive = 1;
						soldier[i].alive = 0;

						if(soldier[i].team == 0) {
							score1++; //increment score for red team
						}else{
							score2++; //else yellow team
						}

						//printf("soldier %d killed\n", i);
        				}else{
                				soldier[count1].alive = 0;
						soldier[i].alive = 1;

						if(soldier[count1].team == 0) {
							score1++; 
						}else{
							score2++;
						}
						//printf("soldier %d killed\n", count1); 
        				}
					
				}
			}

		}

}

