Esempio n. 1
0
  /* Computes all possible robber moves. This advances the internal
     move counter, so call this exactly once by turn.
     Returns # of possible positions. */
int cl_compute_robber_moves (cop_knowledge_t *c) 
{
	int index, other;
	int i;

	assert (c);
        if (!new_turn (c)) {
		assert (0);
        }
	for (i=0; i<c->prpsize; i++) {
		c->prp[c->turn-1][i] = c->prp[c->turn-2][i];
	}
	c->prp_cnt[c->turn-1] = c->prp_cnt[c->turn-2];
	
	for (index = cl_first_prp_history (c, c->turn-2); 
	     index!=-1; 
	     index = cl_next_prp_after_history (c, index, c->turn-2)) {
		for (other = 0; other < c->map->num_nodes; other++) {
			if (c->map->foot_adj[index][other] ||
                            c->map->foot_adj[other][index]) {
				if (!set_prp (c, other)) {
					c->prp_cnt[c->turn-1]++;
				}
			}
		} 
	}

	return c->prp_cnt[c->turn-1];
}
Esempio n. 2
0
  /* Parses world and inits possible positions. */
cop_knowledge_t *cl_init (FILE *file)
{
	cop_knowledge_t *c;
	node_line_t *startnode;

	c = malloc (sizeof (*c));
	if (!c) return NULL;

	bzero (c, sizeof (*c));

	c->world = parse_world_skeleton (file);
	
	c->map = build_map (c->world);
	if (!c->map) { 
		cl_free (c);
		return NULL;
	}

	c->prpsize = (c->map->num_nodes - 1) / (sizeof (int)*8) + 1;
	if (!new_turn (c)) {
		cl_free (c);
		return NULL;
	}

	startnode = node_by_loc (c->map, ROBBER_START_POS);
	if (!startnode) {
		dprintf ("ALERT: Start pos is not on map!!\n");
		exit (1);
	} 
	set_prp (c, startnode->index);
	c->prp_cnt[c->turn-1] = 1;
	
	return c; 
}
Esempio n. 3
0
int		main()
{
  int		first;
  t_ipc		my_ipc;

  first = 0;
  my_ipc.shm_id = shmget(KEY, 100, SHM_R | SHM_W);
  my_ipc.sem_id = semget(KEY, 100, SHM_R | SHM_W);
  printf("%d, %d\n", my_ipc.shm_id, my_ipc.sem_id);
  if (my_ipc.shm_id == -1 && my_ipc.sem_id == -1)
    {
      init_ipc(&my_ipc);
      first = 1;
      wait_for_player(&my_ipc);
    }
  if (first)
    {
      while (!finish(&my_ipc))
	new_turn(&my_ipc);
      shmctl(my_ipc.shm_id, IPC_RMID, NULL);
      semctl(my_ipc.sem_id, IPC_RMID, 1);
    }
  else
    {
      my_ipc.addr = shmat(my_ipc.shm_id, NULL, SHM_R | SHM_W);
      player_func(&my_ipc);
    }
  return (0);
}
Unit::Unit(int _unit_id, UnitType _type, int _player_id, int _x, int _y)
{
    unit_id = _unit_id;
    type = _type;
    player_id = _player_id;
    remaining_health = 100;
    max_health = 100;
    x = _x;
    y = _y;
    new_turn();

    // Set the move_distance based on type.
    switch(type)
    {
        case FIGHTER:
            move_distance = 4;
            break;
        case MAGE:
            move_distance = 5;
            break;
        case ARCHER:
        case HEALER:
            move_distance = 6;
            break;
    }
}
void main(void)
{
    PWM_motor_setup();
    ADC_setup();
    setupSerial();
    IR_Setup();
    TMR2_INT_setup();
    while(1)
    {
        while(GLOBAL_MODE == MANUAL)
        {
          //turn(GLOBAL_VELOCITY,GLOBAL_OMEGA);
          noob_turn(GLOBAL_VELOCITY,GLOBAL_OMEGA);
            
        }
        
        while(GLOBAL_MODE == ASSIST)
        {
            IR_Calculate();                  

            if(dist_count == 2)
            {
                 new_turn(5, Get_dist_diff());
                newdistance = 0;
            }                       
                
        }
        
        while(GLOBAL_MODE == AUTO)
        {
            IR_Calculate();          
          
            if(newstate == 1)
            {
                    if(Get_S_IR_state() == IR_TOO_CLOSE)
                    {
//                        turn(AUTO_VEL, AUTO_OMEGA);
                        CCPR1L =  40;
                        CCPR2L =  50;
              
                    }
                    else if(Get_S_IR_state() == IR_TOO_FAR)
                    {
//                        turn(AUTO_VEL,255 -AUTO_OMEGA);
                        CCPR1L =  50;
                        CCPR2L =  40;
              
                    }
                    else if(Get_S_IR_state() == IR_ERROR)
                    {
                        turn(128,128);
              
                    }
                    newstate = 0;
            }
          
       }                   
        
        
    }
}