gpt4 book ai didi

c - Black Jack - 将一张牌添加到手上

转载 作者:行者123 更新时间:2023-11-30 16:32:57 25 4
gpt4 key购买 nike

我不太确定如何解决。所以我正在编程 blackJack 并且我有我的函数声明(如图所示),对于我的 add_card_to_hand 函数,我不知道该怎么做。我有 2 个参数,一手牌是我通过引用传递的,因为我要更改其内部值,另一手牌是一张牌;我要添加到手上的牌。那么我该如何将这张卡添加到手上呢?我也不知道类型,我只是输入了 hand_t,它可能是空的。

typedef enum { HEARTS, DIAMONDS, SPADES, CLUBS } suit_t;
typedef enum { ACE = 1, TWO, THREE, FOUR, FIVE, SIX, SEVEN, EIGHT, NINE, TEN, JACK, QUEEN, KING } value_t;

typedef struct {
suit_t suit;
value_t value;
} card_t;

typedef struct {
card_t* deck;
int num_decks;
int nextcard;
} shoe_t;

typedef struct {
card_t playercards[21];
int num_cards_in_array;
} hand_t;


hand_t add_card_to_hand(hand_t* hand, card_t card) {



}

最佳答案

#define MAX_HAND_CARDS 21

typedef struct {
card_t playercards[MAX_HAND_CARDS];
int num_cards_in_array;
} hand_t;


int add_card_to_hand(hand_t* hand, const card_t card) {

if (hand->num_cards_in_array >= MAX_HAND_CARDS) {
return -1;
}

hand->playercards[hand->num_cards_in_array] = card;
hand->num_cards_in_array++;

return 0;
}


int main(int argc, char *argv[]) {

hand_t *hand = calloc(1, sizeof(hand_t));
card_t *card = malloc(sizeof(card_t));
card->suit = HEARTS;
card->value = ACE;

if (add_card_to_hand(hand, *card)) {
printf("failed to add Card\n");
} else {
printf("card added\n");
}
return 0;
}

不太了解黑 jack ,但这应该有用。

关于c - Black Jack - 将一张牌添加到手上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49910750/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com