Implemented card array sorting

This commit is contained in:
2021-06-15 07:14:26 -07:00
parent 77389ffd15
commit baa79fc646
3 changed files with 39 additions and 2 deletions

View File

@ -14,6 +14,16 @@ bool gameInit(game_t *game) {
// Init the engine and the rendering pipeline
engineInit(&game->engine, game);
// Shufflemuh
card_t hand[CARD_DECK_SIZE];
for(uint8_t i = 0; i < CARD_DECK_SIZE; i++) {
hand[i] = i;
}
arrayShuffle(sizeof(card_t), hand, CARD_DECK_SIZE);
cardHandSort(hand, CARD_DECK_SIZE);
printf("Bruh moment\n");
// Hand off to the poker logic.
pokerInit(&game->poker, &game->engine);

View File

@ -24,5 +24,30 @@ void cardDeal(card_t *source, uint8_t *sourceSize, card_t *dest,
}
void cardHandSort(card_t *cards, uint8_t length) {
arraySortUint8(cards, length);
// arraySortUint8(cards, length);
arraySort(sizeof(card_t), cards, (int32_t)length, &_cardSorter);
}
int32_t _cardSorter(void *left, void *right) {
card_t cardL = *((card_t *)left);
card_t cardR = *((card_t *)right);
uint8_t suitL = cardGetSuit(cardL);
uint8_t suitR = cardGetSuit(cardR);
if(suitL != suitR) return suitL - suitR;
uint8_t numberL = cardGetNumber(cardL);
uint8_t numberR = cardGetNumber(cardR);
// Make Aces have higher weight (reversed)
if(numberL == CARD_ACE) {
return numberR == CARD_ACE ? 0 : -1;
} else if(numberR == CARD_ACE) {
return 1;
}
// Get the suit and the value of the card (reversed)
return numberR - numberL;
}

View File

@ -42,3 +42,5 @@ void cardDeal(card_t *source, uint8_t *sourceSize, card_t *dest,
* @param length Length of the array of cards.
*/
void cardHandSort(card_t *cards, uint8_t length);
int32_t _cardSorter(void *left, void *right);