Beispiel #1
0
int				print_sol(t_env *env, t_sol *sol)
{
	t_grp	*grp;
	int		nb_pth;
	t_ant	*ant;

	print_cmd(E_CMD);
	ant = NULL;
	S_TURN = S_GRP->P_LEN;
	if (E_ANTS)
		ft_putchar('\n');
	while (E_ANTS > 0)
	{
		grp = S_GRP;
		nb_pth = 1;
		while (grp && E_ANTS >= (G_PTH->len - S_GRP->P_LEN + 1) / nb_pth++)
		{
			if (send_ant(env, &ant, grp) != EXIT_SUCCESS)
				return (EXIT_FAILURE);
			grp = G_NXT;
		}
		E_ANTS -= nb_pth - 1;
		print_turn(env);
	}
	while (print_turn(env))
		(void)ant;
	return (EXIT_SUCCESS);
}
Beispiel #2
0
int main(void) {
	struct hwa_too init[48]={{1,"광",NULL},{1,"오",NULL},{1,"피1",NULL},{1,"피2", NULL},{2,"십",NULL},{2,"오",NULL},{2,"피1",NULL},{2,"피2",NULL},{3,"광",NULL},{3,"오",NULL},{3,"피1",NULL},{3,"피2",NULL},{4,"십",NULL},{4,"오",NULL},{4,"피1",NULL},{4,"피2",NULL},{5,"십",NULL},{5,"오",NULL},{5,"피1",NULL},{5,"피2",NULL},{6,"십",NULL},{6,"오",NULL},{6,"피1",NULL},{6,"피2",NULL},{7,"십",NULL},{7,"오",NULL},{7,"피1",NULL},{7,"피2",NULL},{8,"광",NULL},{8,"십",NULL},{8,"피1",NULL},{8,"피2",NULL},{9,"쌍피",NULL},{9,"오",NULL},{9,"피1",NULL},{9,"피2",NULL},{10,"십",NULL},{10,"오",NULL},{10,"피1",NULL},{10,"피2",NULL},{11,"광",NULL},{11,"쌍피",NULL},{11,"피1",NULL},{11,"피2",NULL},{12,"광",NULL},{12,"십",NULL},{12,"오",NULL},{12,"쌍피",NULL}};
	int check[48]={0};
	int wow,i=0,j=0,command,turn=0,tot=0,compare=0;
	char status[20]=" ";
	char system_command[7]=" ";
	struct hwa_too *player[3][7]={{NULL}};
	struct hwa_too *eat_player[3]={NULL};
	struct hwa_too *eat[10]={NULL};
	struct hwa_too *dummy[21]={NULL};
	srand(time(NULL));
#if DEBUG
	printf("작동\n");
#endif
	while (1) {
		wow=(rand()%48);
		if(check[wow]!=-1){
			player[i][j]=(struct hwa_too *)malloc(sizeof(struct hwa_too));			//player[0]=A, player[1]=B, player[2]=C
			*player[i][j]=init[wow];
			check[wow]=-1;
			j++;
		}
		if(j==7)
		{
			i++;
			j=0;
		}
		if(i==3 && j==0)
			break;
	}																				//임의의 패를 줌
	i=0;
#if DEBUG
	printf("작동\n");
#endif
	while (1)
	{
		wow=(rand()%48);
		if(check[wow]!=-1)
		{
			eat[i]=(struct hwa_too *)malloc(sizeof(struct hwa_too));
			*eat[i]=init[wow];
			check[wow]=-1;
			i++;
		}
		if (i==6)
			break;
	}																				//깔리는 패들
	i=0;
#if DEBUG
	printf("작동\n");
#endif
	while (1)
	{
		wow=(rand()%48);
		if(check[wow]!=-1)
		{
			dummy[i]=(struct hwa_too *)malloc(sizeof(struct hwa_too));
			*dummy[i]=init[wow];
			check[wow]=-1;
			i++;
		}
		if(i==21)
			break;
	}																				//21개의 화투 더미
#if DEBUG
	printf("작동\n");
#endif
	while (1) {
		system("clear");
		for (i=0;i<3;i++) {
			sorting_hwa_too(player[i],sizeof(player[i])/sizeof(*player[i]));
#if DEBUG
	printf("작동1\n");
#endif
			sorting_hwa_too(eat,sizeof(eat)/sizeof(*eat));
#if DEBUG
	printf("작동2\n");
#endif
			sorting_hwa_too(eat_player,sizeof(eat_player)/sizeof(*eat_player));
#if DEBUG
	printf("작동3\n");
#endif
			hwa_too_link(player[i]);						//여기에는 다른 함수가 들어갈것
#if DEBUG
	printf("작동4\n");
#endif
			hwa_too_link(eat);
#if DEBUG
	printf("작동5\n");
#endif
			hwa_too_link(eat_player);
#if DEBUG
	printf("작동6\n");
#endif
		}
		for (i=0; i<3; i++) {
			print_turn(turn,i);
			if (i==0)
				printf("A%10s : 패)",status);
			if (i==1)
				printf("B%10s : 패)",status);
			if (i==2)
				printf("C%10s : 패)",status);
			print_hwa_too(player[i],sizeof(player[i])/sizeof(*player[i]));
			printf("\n(점수 : /**/) 딴 화투) \n");
			print_have_hwa_too(eat_player[i]);
			printf("\n");
		}
		hwa_too_link(eat);
		printf("깔린 패) ");
		print_hwa_too(eat,sizeof(eat)/sizeof(*eat));
		printf("\n\n");
		printf("명령 ? ");
		scanf("%s",system_command);
		if(strcmp(system_command,"g")==0);
			//hwa_too_go()
		else if(strcmp(system_command,"s")==0);
		else if(strcmp(system_command,"e")==0)
		{
			printf("고스톱 게임을 종료합니다.");
			return 0;
		}
		else if(strcmp(system_command,"b")==0);
		else if(strcmp(system_command,"h")==0);
		else if(strcmp(system_command,"save")==0);
		else if(strcmp(system_command,"load")==0);
		else if(0<(compare=atoi(system_command)) && compare<8);
			//play_hwa_too(compare,player[turn],eat,eat_player[turn],dummy[tot],status);
		else
		{
			printf("잘못된 명령입니다.\n");
			sleep(3);
		}
		tot++;
		turn++;
		if(turn==3)
			turn=0;
	}
	return 0;
}
Beispiel #3
0
void navigate() {

    //check the route starts where we
    if(route.node[0] != status.current_node) {
        cout << "Route was planned incorrectly\n";
        cout << "Route starts at node " << route.node[0] << endl;
        cout << "But we are currently at node " << status.current_node << endl;
        throw(INVALID_ROUTE);
        return;
    }

    //Check the route for continuity
    for(unsigned int i=0; i<route.length; i++) {
        if(idp_map[route.node[i]][route.node[i+1]] == NC) {
            cout << "node " << route.node[i] << " is not connected to node " << route.node[i+1] << endl;
            throw(INVALID_ROUTE);
        }
    }



    turning turn;
    if(route.length!=0) {
        for(unsigned int i=1; i<=route.length; i++) {

            status.last_node = status.current_node;
            status.next_node = route.node[i];
            status.travel = IN_TRANSIT;

            //navigate from route.node[i] to route.node[i+1]

            //direction logic
            directions current = status.direction;
            directions desired = idp_map[status.current_node][status.next_node];

            try {
                turn = calculate_turn(current, desired);
            }
            catch(...) {
                throw;
            }

            cout << "Turning ";
            print_turn(turn);
            cout << " to reach node " << status.next_node << endl;


            DEBUG("Calling lf_turn()");
            lf_turn(turn); //turn to face the desired node;

            cout << "Finished turn, starting transit" << endl;
            DEBUG("Calling lf_until_junction()");
            lf_until_junction();

            status.travel = AT_NODE;
            status.current_node = route.node[i];
            status.direction = inverse_direction[(idp_map[status.current_node][status.last_node])];

            cout << "Reached node " << status.current_node << endl << endl;
        }
    }

    if(route.end_direction) {
        try {
            turn = calculate_turn(status.direction, route.end_direction);
            cout << "Making final ";
            print_turn(turn);
            cout << " turn to face ";
            print_direction(route.end_direction);
            cout << endl;
            lf_turn(turn);
            status.direction = route.end_direction;
        }
        catch(...) {
            throw;
        }
    }
    cout << "\nnavigate() has finished following the route\n";
}