void gp_sort(card_t* cards, int len) { cards_sort(cards, len); }
int gp_play(gp_t* gp, int player_no, card_t* cards, int len) { int i,valid_num; hand_type htype; card_t* card; if (!cards || len <= 0) return -1; if (gp->game_state != GP_GAME_PLAY) { if (gp->debug) printf("play cards but game state not play.\n"); return -2; } if (player_no != gp->curr_player_no) { if (gp->debug) printf("play cards but not this no.\n"); return -3; } valid_num = cards_num(cards, len); if (valid_num == 0) { if (gp->debug) printf("play zero cards.\n"); return -4; } if (gp->mode == GP_MODE_SERVER) { for (i = 0; i < valid_num; ++i){ card = cards + i; if (!cards_have(gp->players[player_no].cards, GP_MAX_CARDS, card)) { if (gp->debug) { printf("play cards but player hasn't this card(%s).\n", card_to_string(card)); } return -5; } } } gp_handtype(gp, cards, len, &htype); if (gp->mode == GP_MODE_SERVER) { /* can play out these cards */ if (gp->largest_player_no != player_no) { if (!gp_canplay(gp, cards, len)){ if (gp->debug) printf("cann't play these cards(smaller).\n"); return -6; } } } /* player play these cards */ memset(gp->last_hand, 0, sizeof(card_t) * GP_MAX_CARDS); for (i = 0; i < valid_num; ++i) { card = cards + i; cards_del(gp->players[player_no].cards, GP_MAX_CARDS, card); cards_add(gp->last_hand, GP_MAX_CARDS, card); } memcpy(&gp->last_hand_type, &htype, sizeof(hand_type)); memcpy(gp->players[player_no].cards_played, gp->last_hand, sizeof(card_t) * GP_MAX_CARDS); cards_sort(gp->players[player_no].cards_played, GP_MAX_CARDS); gp->largest_player_no = player_no; cards_trim(gp->players[player_no].cards, GP_MAX_CARDS); if (cards_num(gp->players[player_no].cards, GP_MAX_CARDS)) gp_next_player(gp); else { if (gp->mode == GP_MODE_SERVER) gp->game_state = GP_GAME_END; } return 1; }
void texas_sort(hand_t* hand) { cards_sort(hand); }