Implemented card array sorting
This commit is contained in:
@ -13,6 +13,16 @@ bool gameInit(game_t *game) {
|
|||||||
|
|
||||||
// Init the engine and the rendering pipeline
|
// Init the engine and the rendering pipeline
|
||||||
engineInit(&game->engine, game);
|
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.
|
// Hand off to the poker logic.
|
||||||
pokerInit(&game->poker, &game->engine);
|
pokerInit(&game->poker, &game->engine);
|
||||||
|
@ -24,5 +24,30 @@ void cardDeal(card_t *source, uint8_t *sourceSize, card_t *dest,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void cardHandSort(card_t *cards, uint8_t length) {
|
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;
|
||||||
}
|
}
|
@ -41,4 +41,6 @@ void cardDeal(card_t *source, uint8_t *sourceSize, card_t *dest,
|
|||||||
* @param cards Hand of cards to sort.
|
* @param cards Hand of cards to sort.
|
||||||
* @param length Length of the array of cards.
|
* @param length Length of the array of cards.
|
||||||
*/
|
*/
|
||||||
void cardHandSort(card_t *cards, uint8_t length);
|
void cardHandSort(card_t *cards, uint8_t length);
|
||||||
|
|
||||||
|
int32_t _cardSorter(void *left, void *right);
|
Reference in New Issue
Block a user