Ejemplo n.º 1
0
	int update()
	{
		float old_time = last_time_updated;
		last_time_updated = gtime();
		dt = last_time_updated - old_time;
		for (int i = 0; i < frame_time_count-1; i++) last_frame_deltas[i+1] = last_frame_deltas[i];
		last_frame_deltas[0] = dt;
		
		for (std::vector<Ship*>::iterator it = ship_list.begin(); it != ship_list.end(); ++it)
		{
			bool* keylist = 0;
			if ((*it)->player)
			{
				keylist = getkeylistfromkeys();
			}
			else
			{
				update_brain(*it);
				keylist = (*it)->brain->readout();			
			}
			
			applykeys(*it, keylist);
			delete keylist;
		}
		
		cpSpaceStep(space, dt);
		removeshells();
		
		return 0;
	}	
Ejemplo n.º 2
0
	int update(float dt)
	{		
		last_time_updated += dt;
		
		for (std::vector<Ship*>::iterator it = ship_list.begin(); it != ship_list.end(); ++it)
		{
			bool* keylist = 0;
			update_brain(*it);
			keylist = (*it)->brain->readout();
			applykeys(*it, keylist);
			delete keylist;
		}
		
		cpSpaceStep(space, dt);
		removeshells();
		
		return 0;
	}
Ejemplo n.º 3
0
int main (int argc, char** argv)
{
    world_skeleton_t *s;
    map_t *map;
    announcer_t a;

    char* name = "mrscolumbo";

    brain_t* brain;

    if(argc>1)
    {
	    srand(argv[1][0]);
	    
    }

    a = init_announcer(stdout);
    announce_reg(a, name, PTYPE_COP_FOOT);

    s = parse_world_skeleton(stdin);

    //parser_print_world_skeleton(s);

    map = build_map(s);

    dprintf("NAME: %s\n", s->name);

    brain = create_brain(s->name, map);
    /*
    printf("dist: %d\n", get_dist(map, CHOOSE_FOOT,
				  node_index(map, "55-and-woodlawn"),
				  node_index(map, "54-and-ridgewood")));
    */


    for(;;)
    {
	world_message_t *m;
	node_line_t *my_node;
	cop_inform_msg_t* inform;
	cop_plan_msg_t* plans;
	cop_vote_msg_t* votes;
	vote_tally_t* tally;
	int bestdst;
	int* path;

	m = parse_world_message(s);
	
	announce_inform(a, NULL);

	if(!m->game_running)
		break; 

	my_node = player_node(m, map, s->name, 0); 

	update_brain(s, m, map, brain);
	
	inform = parse_inform_messages(s);
	free_inform_messages(inform);

	announce_plan(a, NULL);
	plans = parse_plan_messages(s);

	free_plan_messages(plans);
	
	votes = make_stupid_votes(s, brain);
	announce_vote(a, votes);
	free(votes);

	tally = parse_vote_tally(s);
	free_vote_tally(tally);


	bestdst = get_dest(s, m, map, brain);
	
	if(ada_kurds_here_p(s, m, map, brain))
	{
		bestdst = (rand()%(map->num_nodes));
	}


	//path = get_combined_prev(map, CHOOSE_FROM_PTYPE(brain->my_ptype), brain->my_pos);
	// ALERT
	path = get_prev(map, CHOOSE_FROM_PTYPE(brain->my_ptype), brain->my_pos);
	
	if(get_combined_switchp(map, CHOOSE_FROM_PTYPE(brain->my_ptype), brain->my_pos))
	{
		// ALERT
		//switch_transport(brain, map);
	}
	

	while(path[bestdst]!=brain->my_pos)
	{
		bestdst = path[bestdst];
	}

	announce_move(a, s, m, node_by_index(map, bestdst)->loc, brain->my_ptype);
    }
	

    return 0;
}