struct move_dirs
{
	//0 closed 1 open
	int open;
	int X;
	int Y;
};

struct move_dirs possible[9];


void move(int i) {

	double tmpX1;
	double tmpY1;
	double tmpX2;
	double tmpY2;
	double dist1;
	double dist2;
	double coords[3]={44.14, 720.52, 96.08};
	int randmove = 0;
	int randnum1;
	//int open[10];
	int count1;
	int count2;

	//coords[0]=1;
	//coords[1]=1;
	//coords[2]=0;

	//soldier[count1].closest
	
	//8 possible movement directions
	

	//coordinates of closest enemy
	//int test1 =soldier[i].closest
	int test1 = soldier[i].closest;	

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

	//coordinates of self
	tmpX1 = soldier[i].X;
	tmpY1 = soldier[i].Y;

	//find block that makes solider closest to enemy
	//verify that not already bordering closest

/*
	if(DIST(tmpX1, tmpY1, tmpX2, tmpY2) > 20) {
		randmove = 1;
		for(count1=0; count1<9; count1++){
			possible[count1].open=0;
		}
		
		//generate a random number 1 thru 9 (9th for no move)
		//srand ( time(NULL) + i);
		//randnum1 = rand() % 9 + 1;
		//this determines move, must check for != off grid < 49

		//find out which of the 8 spaces is not occupied
		

	} 
*/

		//	if(DIST(tmpX1, tmpY1, tmpX2, tmpY2) == 2) {
		//		printf("DIST %lf\n", DIST(tmpX1, tmpY1, tmpX2, tmpY2));
		//		return;  //or attack
		//	}


		//do check for block being occupied

		dist1=10000;

		if(ocupied(tmpX1-2, tmpY1-2) != 1) {
			dist1 = DIST(tmpX1-2, tmpY1-2, tmpX2, tmpY2);
			coords[1] = tmpX1-2;
			coords[2] = tmpY1-2;
			possible[0].X = coords[1];
			possible[0].Y = coords[2];
			if(abs(possible[0].X) < 49 && abs(possible[0].Y) < 49) {
				possible[0].open=1;
			}
		}	

		if(ocupied(tmpX1-2, tmpY1) != 1) {
			dist2 = DIST(tmpX1-2, tmpY1, tmpX2, tmpY2);
                        possible[1].X = tmpX1-2;
                        possible[1].Y = tmpY1;
                        if(abs(possible[1].X) < 49 && abs(possible[1].Y) < 49) {
                                possible[1].open=1;
                        }

			if (dist2 < dist1) { 
				dist1=dist2; 
				coords[1] = tmpX1-2;
				coords[2] = tmpY1;
				//printf("old X: %lf new X: %lf\n", tmpX1, coords[1]);
	
			}
		}

		if(ocupied(tmpX1-2, tmpY1+2) != 1) {
                        possible[2].X = tmpX1-2;
                        possible[2].Y = tmpY1+2;
                        if(abs(possible[2].X) < 49 && abs(possible[2].Y) < 49) {
                                possible[2].open=1;
                        }

			dist2 = DIST(tmpX1-2, tmpY1+2, tmpX2, tmpY2);	
			if (dist2 < dist1) { 
				dist1=dist2; 
				coords[1] = tmpX1-2;
				coords[2] = tmpY1+2;
			}
		}	

		if(ocupied(tmpX1+2, tmpY1+2) != 1) {
                        possible[3].X = tmpX1+2;
                        possible[3].Y = tmpY1+2;
                        if(abs(possible[3].X) < 49 && abs(possible[3].Y) < 49) {
                                possible[3].open=1;
                        }

			dist2 = DIST(tmpX1+2, tmpY1+2, tmpX2, tmpY2);
			if (dist2 < dist1) { 
				dist1=dist2; 
				coords[1] = tmpX1+2;
				coords[2] = tmpY1+2;
			}
		}

		if(ocupied(tmpX1+2, tmpY1) != 1) {
                        possible[4].X = tmpX1+2;
                        possible[4].Y = tmpY1;
                        if(abs(possible[4].X) < 49 && abs(possible[4].Y) < 49) {
                                possible[4].open=1;
                        }
			dist2 = DIST(tmpX1+2, tmpY1, tmpX2, tmpY2);
			if (dist2 < dist1) { 
				dist1=dist2; 
				coords[1] = tmpX1+2;
				coords[2] = tmpY1;
			}
		}


		if(ocupied(tmpX1+2, tmpY1-2) != 1) {
                        possible[5].X = tmpX1+2;
                        possible[5].Y = tmpY1-2;
                        if(abs(possible[5].X) < 49 && abs(possible[5].Y) < 49) {
                                possible[5].open=1;
                        }

			dist2 = DIST(tmpX1+2, tmpY1-2, tmpX2, tmpY2);
			if (dist2 < dist1) { 
				dist1=dist2; 
				coords[1] = tmpX1+2;
				coords[2] = tmpY1-2;
			}
		}

		if(ocupied(tmpX1, tmpY1-2) != 1) {
                        possible[6].X = tmpX1;
                        possible[6].Y = tmpY1-2;
                        if(abs(possible[6].X) < 49 && abs(possible[6].Y) < 49) {
                                possible[6].open=1;
                        }

			dist2 = DIST(tmpX1, tmpY1-2, tmpX2, tmpY2);
			if (dist2 < dist1) { 
				dist1=dist2; 
				coords[1] = tmpX1;
				coords[2] = tmpY1-2;
			}
		}

		if(ocupied(tmpX1, tmpY1+2) != 1) {
                        possible[7].X = tmpX1;
                        possible[7].Y = tmpY1+2;
                        if(abs(possible[7].X) < 49 && abs(possible[7].Y) < 49) {
                                possible[7].open=1;
                        }

			dist2 = DIST(tmpX1, tmpY1+2, tmpX2, tmpY2);
			if (dist2 < dist1) { 
				dist1=dist2; 
				coords[1] = tmpX1;
				coords[2] = tmpY1+2;
			}
		}

		/*
		(-2,-2)
		(-2,0)
		(-2,2)
		(2,2)
		(2,0)
		(2,-2)
		(0,-2)
		(0,2)
		*/

		//if occupied by team then take next closest
		//if occupied by enemy then make no move
		//soldier[19];
		//soldier[count1].Y=count3;

		//if distance of closest enemy is greater than 20, then do random movement


	if(randmove == 1) {
		count2=0;
                for(count1=0; count1<8; count1++){
                        if(possible[count1].open==1){count2++;}
                }

		srand ( time(NULL) - i - count2 );
		randnum1 = rand() % count2 + 1;
		printf("rand1: %d\n", randnum1);
		if(randnum1 == 0) {
			coords[1]=tmpX1;
			coords[2]=tmpY1;
		} else {
			count2=0;
	                for(count1=0; count1<8; count1++){
	                        if(possible[count1].open==1 && randnum1-1 == count2){
					coords[1]=possible[count1].X;
					coords[2]=possible[count1].Y;
				}
				count2++;
	                }
		}
		
		


	}

	soldier[i].X=coords[1]+num1;
	soldier[i].Y=coords[2];

	return;
}
