Added some array utils.
This commit is contained in:
@ -21,4 +21,8 @@ void cardDeal(card_t *source, uint8_t *sourceSize, card_t *dest,
|
||||
i = *destSize;
|
||||
dest[i] = card;
|
||||
*destSize = i+1;
|
||||
}
|
||||
|
||||
void cardHandSort(card_t *cards, uint8_t length) {
|
||||
arraySortUint8(cards, length);
|
||||
}
|
@ -6,6 +6,21 @@
|
||||
*/
|
||||
#pragma once
|
||||
#include <dawn/dawn.h>
|
||||
#include "../util/array.h"
|
||||
|
||||
/**
|
||||
* Returns the suit of a given card.
|
||||
* @param card to get the suit for.
|
||||
* @returns The suit.
|
||||
*/
|
||||
#define cardGetSuit(card) (card / CARD_COUNT_PER_SUIT)
|
||||
|
||||
/**
|
||||
* Returns the number of a given card.
|
||||
* @param card The card to get the number for.
|
||||
* @returns The card number.
|
||||
*/
|
||||
#define cardGetNumber(card) (card % CARD_COUNT_PER_SUIT)
|
||||
|
||||
/**
|
||||
* Deals a card from an array source to an array destination. Pointers to array
|
||||
@ -18,4 +33,12 @@
|
||||
*/
|
||||
void cardDeal(card_t *source, uint8_t *sourceSize, card_t *dest,
|
||||
uint8_t *destSize
|
||||
);
|
||||
);
|
||||
|
||||
/**
|
||||
* Sort a hand of cards.
|
||||
*
|
||||
* @param cards Hand of cards to sort.
|
||||
* @param length Length of the array of cards.
|
||||
*/
|
||||
void cardHandSort(card_t *cards, uint8_t length);
|
@ -19,4 +19,21 @@ bool pokerPlayerIsAlive(pokerplayer_t *player) {
|
||||
|
||||
bool pokerPlayerIsHuman(poker_t *poker, pokerplayer_t *player) {
|
||||
return (poker->players + POKER_PLAYER_HUMAN_INDEX) == player;
|
||||
}
|
||||
|
||||
void pokerPlayerDeal(poker_t *poker, pokerplayer_t *player) {
|
||||
cardDeal(poker->deck, &poker->deckSize, player->cards, &player->cardCount);
|
||||
}
|
||||
|
||||
void pokerPlayerDealAll(poker_t *poker, uint8_t count) {
|
||||
uint8_t x, y;
|
||||
pokerplayer_t *player;
|
||||
|
||||
for(y = 0; y < count; y++) {
|
||||
for(x = 0; x < POKER_PLAYER_COUNT; x++) {
|
||||
player = poker->players + x;
|
||||
if(!pokerPlayerIsAlive(player)) continue;
|
||||
pokerPlayerDeal(poker, player);
|
||||
}
|
||||
}
|
||||
}
|
@ -25,7 +25,6 @@ void pokerPlayerBet(poker_t *poker, pokerplayer_t *player, int32_t chips);
|
||||
*/
|
||||
bool pokerPlayerIsAlive(pokerplayer_t *player);
|
||||
|
||||
|
||||
/**
|
||||
* Returns true if the player provided is human or not.
|
||||
*
|
||||
@ -33,4 +32,20 @@ bool pokerPlayerIsAlive(pokerplayer_t *player);
|
||||
* @param player Player instance.
|
||||
* @returns True if the player is human.
|
||||
*/
|
||||
bool pokerPlayerIsHuman(poker_t *poker, pokerplayer_t *player);
|
||||
bool pokerPlayerIsHuman(poker_t *poker, pokerplayer_t *player);
|
||||
|
||||
/**
|
||||
* Deal a card to a player.
|
||||
*
|
||||
* @param poker Poker game instance.
|
||||
* @param player Poker player to deal to.
|
||||
*/
|
||||
void pokerPlayerDeal(poker_t *poker, pokerplayer_t *player);
|
||||
|
||||
/**
|
||||
* Deal card(s) to every active player.
|
||||
*
|
||||
* @param poker Poker game instance.
|
||||
* @param count Count of cards to deal.
|
||||
*/
|
||||
void pokerPlayerDealAll(poker_t *poker, uint8_t count);
|
@ -14,8 +14,8 @@ void pokerPlayerInit(poker_t *poker) {
|
||||
|
||||
for(i = 0; i < POKER_PLAYER_COUNT; i++) {
|
||||
player = poker->players + i;
|
||||
assetTextureLoad(&player->bodyTexture, "characters/penny/body.png");
|
||||
assetTextureLoad(&player->faceTexture, "characters/penny/face.png");
|
||||
assetTextureLoad(&player->bodyTexture, "characters/penny/textures/body.png");
|
||||
assetTextureLoad(&player->faceTexture, "characters/penny/textures/face.png");
|
||||
|
||||
w = 0.6;
|
||||
h=((float)player->faceTexture.width)/((float)player->faceTexture.height)*w;
|
||||
|
@ -7,35 +7,16 @@
|
||||
#include "deal.h"
|
||||
|
||||
void pokerDealInit(poker_t *poker) {
|
||||
uint8_t x, y;
|
||||
card_t temporary;
|
||||
pokerplayer_t *player;
|
||||
|
||||
poker->round = POKER_ROUND_DEAL;
|
||||
|
||||
// Hard look at the dealer
|
||||
pokerLookAtPlayer(&poker->cameraWorld, POKER_SEAT_DEALER);
|
||||
|
||||
// Shuffle the deck
|
||||
for(x = 0; x < CARD_DECK_SIZE - 1; x++) {
|
||||
// Select random element from remaining elements.
|
||||
y = u8randRange(x, CARD_DECK_SIZE);
|
||||
temporary = poker->deck[y];// Take out other card
|
||||
poker->deck[y] = poker->deck[x];// Move my card there
|
||||
poker->deck[x] = temporary;// Put other card here.
|
||||
}
|
||||
arrayShuffle(sizeof(card_t), poker->deck, CARD_DECK_SIZE);
|
||||
|
||||
// Deal 2 card to each player
|
||||
for(y = 0; y < POKER_DEAL_CARD_EACH; y++) {
|
||||
for(x = 0; x < POKER_PLAYER_COUNT; x++) {
|
||||
player = poker->players + x;
|
||||
if(!pokerPlayerIsAlive(player)) continue;
|
||||
cardDeal(
|
||||
poker->deck, &poker->deckSize,
|
||||
player->cards, &player->cardCount
|
||||
);
|
||||
}
|
||||
}
|
||||
pokerPlayerDealAll(poker, POKER_DEAL_CARD_EACH);
|
||||
|
||||
printf("Cards Dealt\n");
|
||||
pokerBetInit(poker);
|
||||
|
@ -7,6 +7,7 @@
|
||||
|
||||
#pragma once
|
||||
#include <dawn/dawn.h>
|
||||
#include "../../util/array.h"
|
||||
#include "../render/look.h"
|
||||
#include "../player.h"
|
||||
#include "../card.h"
|
||||
|
@ -27,25 +27,11 @@ void pokerWinnerInit(poker_t *poker) {
|
||||
poker->round = POKER_ROUND_WINNER;
|
||||
printf("Winner Winner Chicken Dinner\n");
|
||||
|
||||
// Find the player(s) who have a royal flush?
|
||||
// Kill me
|
||||
for(uint8_t i = 0; i < POKER_PLAYER_COUNT; i++) {
|
||||
pokerplayer_t *player = poker->players + i;
|
||||
if(!pokerPlayerIsAlive(player)) continue;
|
||||
|
||||
card_t fullHand[POKER_DEALER_HAND+POKER_PLAYER_HAND];
|
||||
pokerWinnerGetFullHand(poker, player, fullHand);
|
||||
uint8_t cardCount = poker->cardsFacing + player->cardCount;
|
||||
|
||||
uint8_t suit;
|
||||
|
||||
// Find the ace and get it's suit
|
||||
for(uint8_t j = 0; j < cardCount; j++) {
|
||||
card_t card = fullHand[j];
|
||||
if((card % CARD_COUNT_PER_SUIT) != CARD_ACE) continue;
|
||||
suit = card / CARD_COUNT_PER_SUIT;
|
||||
break;
|
||||
}
|
||||
|
||||
// Now we have a suit, check we have each of that
|
||||
|
||||
// Create a fll ahnd
|
||||
}
|
||||
}
|
@ -8,6 +8,7 @@
|
||||
#pragma once
|
||||
#include <dawn/dawn.h>
|
||||
#include "../player.h"
|
||||
#include "../card.h"
|
||||
|
||||
void pokerWinnerGetFullHand(poker_t *poker,pokerplayer_t *player,card_t *cards);
|
||||
void pokerWinnerInit(poker_t *poker);
|
Reference in New Issue
Block a user