void surroundCheck(int x,int y){
	if(map[x-1][y-1] == 0 && (map[x-1][y]!=-1 && map[x][y-1]!=-1))	addLive(x,y,x-1,y-1,1,aka[x][y].g+Dia);
	if(map[x+1][y+1] == 0 && (map[x+1][y]!=-1 && map[x][y+1]!=-1))	addLive(x,y,x+1,y+1,8,aka[x][y].g+Dia);
	if(map[x-1][y+1] == 0 && (map[x-1][y]!=-1 && map[x][y+1]!=-1))	addLive(x,y,x-1,y+1,3,aka[x][y].g+Dia);
	if(map[x+1][y-1] == 0 && (map[x+1][y]!=-1 && map[x][y-1]!=-1))	addLive(x,y,x+1,y-1,6,aka[x][y].g+Dia);
	if(map[x-1][y] == 0)	addLive(x,y,x-1,y  ,2,aka[x][y].g+Ver);
	if(map[x+1][y] == 0)	addLive(x,y,x+1,y  ,7,aka[x][y].g+Ver);
	if(map[x][y-1] == 0)	addLive(x,y,x  ,y-1,4,aka[x][y].g+Ver);
	if(map[x][y+1] == 0)	addLive(x,y,x  ,y+1,5,aka[x][y].g+Ver);

	min = 999999;
	for(int i = 1;i<21;i++)
		for(int j = 1;j<21;j++)
			if(map[i][j] == 1 && aka[i][j].f < min) {mini = aka[i][j];min = mini.f;}
}
Exemple #2
0
/** newThread **/
tcb_t *newThread(void (*func)()) {
   unsigned int *sp;                      // Stack pointer

   numThreads++;     // Keep track of number of active threads

   /* Now create a new thread control block and thread stack */
   tcb_t *newTCB = malloc(sizeof(tcb_t)); // Allocate space for new tcb
   newTCB->stackBase = malloc(STACKSIZE); // And give thread its own stack

   /* Set stack pointer to end of stack (stack grows down) */
   sp = (unsigned int *)((void *)(newTCB->stackBase) + STACKSIZE - 4);

   /* Initialized the "saved" registers on the stack */
   *sp = (unsigned int) func;      // Set saved IP to function address
   sp--; *sp = (unsigned int) sp;  // EBP
   sp--; *sp = 0;                  // FLAGS register
   sp--; *sp = 0;                  // EDI
   sp--; *sp = 0;                  // ESI
   sp--; *sp = 0;                  // EDX
   sp--; *sp = 0;                  // ECX
   sp--; *sp = 0;                  // EBX
   sp--; *sp = 0;                  // EAX

   newTCB->stackPtr = sp;          // Save stack pointer in TCB
   newTCB->state = READY;          // Set thread's state

   /* Disable interrupts before messing with global lists */
   disable();

   /* Add thread to "live" list */
   addLive(newTCB);

   /* Link thread onto end of ready list */
   queue(readyList, newTCB);

   enable();   // Re-enable interrupts

   /* Return new thread's ID */
   return(newTCB);
}