Пример #1
0
int main(void){
	initSysTick();
	initTcb();
	//taskSwitch();
	//testFunc();

	TaskBlock tb_LED1;
	TaskBlock tb_LED2;
	TaskBlock tb_LED5;
	initLED();
	initLED2();
	initLED5();
	initPushButton1();
	initTaskBlock(&tb_LED1);
	initTaskBlock(&tb_LED2);
	initTaskBlock(&tb_LED5);

  while(1){
	SD1(&tb_LED1);
    SD2(&tb_LED2);
    SD5(&tb_LED5);
  }
}
Пример #2
0
/***********************************************************************
 *from positions 1 and 2 shortest distance to R is same
 *count1 has the number of points in the shortest path from pos1 to R 
 *count2 has the number of points in the shortest path from pos2 to R
 *returns position with maximum number of count.
 ***********************************************************************/
int best2(int pos1,int pos2,int x,int y,char** maze,int N,int l){
    int a1,a2,b1,b2,count1,count2,i,j,first1,sec1,first2,sec2;
    a1=a2=x;
    b1=b2=y;
    if(pos1==0)a1--;
    else if(pos1==1)b1++;
    else if(pos1==2)a1++;
    else if(pos1==3)b1--;
    if(pos2==0)a2--;
    else if(pos2==1)b2++;
    else if(pos2==2)a2++;
    else if(pos2==3)b2--;
    int *m = malloc(sizeof(int));// m,n store temporarily visited B coordinates
    int *n = malloc(sizeof(int));
    int** v= malloc(N*sizeof(int*));//visited matrix only for B's
    for(i=0; i<N ;i++){         
    v[i] = malloc(N*sizeof(int));
    }
    for(i=0 ; i<N ;i++){
        for(j=0 ; j<N ;j++)
            v[i][j]=0;                
    }
    if(maze[a1][b1]=='B')
    {
        count1=1;
        v[a1][b1]=1;
        *m=a1,*n=b1;
    }
    else count1=0;
    first1 = SD_2(maze,N,a1,b1,'B',m,n,v);
    while(first1!=-1 )
    {
        sec1=SD2(maze,N,*m,*n,'R');
        if(first1+sec1==l)
            count1++;
        first1 = SD_2(maze,N,a1,b1,'B',m,n,v);
    }
    for(i=0 ; i<N ;i++){
        for(j=0 ; j<N ;j++)
            v[i][j]=0;                //initially all elements are non visited
    }
    if(maze[a2][b2]=='B')
    {
        count2=1;
        v[a2][b2]=1;
        *m=a2;*n=b2;
    }
    else count2=0;
    first2 = SD_2(maze,N,a2,b2,'B',m,n,v);
    while(first2!=-1 )
    {
        sec2=SD2(maze,N,*m,*n,'R');
        if(first2+sec2==l)
            count2++;
        first2 = SD_2(maze,N,a2,b2,'B',m,n,v);
    }
        
    if(count1>=count2)
    return pos1;
    else 
    return pos2;
    
    
}    
Пример #3
0
/***************************************************************************
 *returns position to which bot should move
 *a1,a2 coordinates of our bot 
 *b1,b2 coordinates of enemy bot
 *positions 0(UP)
            1(RIGHT)
            2(DOWN)
            3(LEFT)
 ********************************************************************************/
int bot2(int** Maze,char** maze,int N,int score1,int score2,int a1,int a2,int b1,int b2)
{   int x=a1;
    int y=a2;
    int p;
    char c1,c2,c3,c0;
    c1=maze[x][y+1];
    c3=maze[x][y-1];
    c0=maze[x-1][y];
    c2=maze[x+1][y];
    int sd[4];//sd : shortest distance from each points to R    
    if(c1=='R')     
        return 1;
    else if(c2=='R')
        return 2;
    else if(c3=='R')
        return 3;
    else if(c0=='R')
        return 0;
    
    if(c1!='#')
         sd[1]=SD2(maze,N,x,y+1,'R');
    else
         sd[1]=N*N;//N*N is maximum distance possible
    if(c2!='#') 
        sd[2]=SD2(maze,N,x+1,y,'R');
    else
         sd[2]=N*N;
    if(c3!='#')
         sd[3]=SD2(maze,N,x,y-1,'R');
    else 
        sd[3]=N*N;
    if(c0!='#')
         sd[0]=SD2(maze,N,x-1,y,'R');
    else
         sd[0]=N*N;

     
     
     
    //comparing shortest distances
    if(sd[1]<sd[2])
        p=1;
    else if(sd[1]>sd[2])
        p=2;     
    else if(sd[1]==sd[2] && sd[1]<=sd[3] && sd[1]<=sd[0])
        p=best2(1,2,x,y,maze,N,sd[1]);// Call for the best of two possible positions
    else {
        p=1; 
        sd[p]=N*N;
        }
    if(sd[3]<sd[p])
        p=3;
    else if(sd[3]==sd[p] && sd[3]<=sd[0])
        p=best2(p,3,x,y,maze,N,sd[3]);
    
    if(sd[0]<sd[p])
        p=0;
    else if(sd[0]==sd[p])
        p=best2(0,p,x,y,maze,N,sd[0]);
    return p;
        
}