示例#1
0
int main(int argc, char* argv[]) {
    char *mapPath, *agentPath; //The location of the files
    int rows, cols, maxSteps; //Dimensions of the map and the max steps
    char** map; //Character map
    //Check the command line args
    if (argc != 4) {
        handler_exit(1);
    }

    mapPath = argv[1];
    agentPath = argv[3];

    long tempL;
    char** tempP = NULL;
    tempL = strtol(argv[2], tempP, 10);
        
    if (tempL < 1 || tempL > INT_MAX) {
        handler_exit(2);
    }
    
    //Set variables needed later in the program - max steps, map and agents
    maxSteps = (int)tempL;
    map = open_map_file(mapPath, &rows, &cols);
    get_num_agents(agentPath);
    agents = (AgentData *)malloc(sizeof(AgentData)*numAgents);
    get_agents(agentPath, rows, cols);

    //Set up signal handling
    signal(SIGINT, sig_handler);
    signal(SIGCHLD, sig_handler);

    //Start agents
    start_agents(rows, cols, map);

    //Start the game
    for (int i = 0; i < maxSteps; i++) {
        //Let each agent take turns, process their move and print the map
        for(int j = 0; j < numAgents; j++) {
            agent_move(j);
            check_move(map, j, rows, cols);
            print_map(map, rows, cols);
        }
    }
    //No agent succeeded with given steps
    handler_exit(10);
}
示例#2
0
		// drawLine(screen, x1-y, y1-x, x1+y, y1-x, 0);
		// bottom-middle segment
		// drawLine(screen, x1-y, y1+x, x1+y, y1+x, 0);
		// bottommost segment
		// drawLine(screen, x1-x, y1+y, x1+x, y1+y, 0);
	}
}

/* The pac man game agent state machine. */
BEGIN_STATE_MACHINE(agent_pman_state_machine)
	GameAgent *pman = (GameAgent *) s->parent;
	STATE_MACHINE_HEADER
	ON_UPDATE
		int move_result;
		Uint32 time = *(Uint32 *) sm->data;

		move_result = agent_move(pman, time);
		agent_pman_frame_advance(pman, time);
		if (!move_result)
			if (!agent_next_move(pman))
				agent_set_move(pman, &fixed_vector_zero);
			else if (pman->pman_ai_flag)
				agent_determine_next_random_move(pman);
	ON_MSG(GAME_AGENT_MSG_BLOCK_CHANGE)
		if (pman->pman_ai_flag)
			agent_determine_next_random_move(pman);
		else
			agent_next_move(pman);
		state_send_message(BOARD_MSG_PMAN_ON_BLOCK, sm->to, STATE_ID_BOARD, 0, &pman->loc);
END_STATE_MACHINE