I know that any array is fixed in size, but what I care about is finding the last value in a colum of the array. If anyone is wondering what card game this is it's called Baker's Dozen. You start off with 13 columns of 4 cards in each column. A column can have max 11 cards and you place a lower value card on top of a higher value card or put it in 1 of the 4 suit piles starting with ace and going up. You can only move 1 card at a time.
I'm not showing the displayBoard() function cuz that's not important. The first commented out section is me checking that the user didn't choose an empty column to move a card from. As soon as I can figure out how to find the last item in a column the sooner I can add more code.
Code:
typedef struct
{
char face[3];
int suit;
} Card;
void fillDeck(Card eDeck[], char cardFaces[][3], int cardSuits[]);
void shuffle(Card fDeck[]);
void deal(Card fDeck[], Card stacks[][13]);
void displayBoard(Card stacks[][13], Card piles[][13]);
int main()
{
Card deck[52];
char facesList[13][3] = {"A", "2", "3", "4", "5", "6", "7", "8",
"9", "10", "J", "Q", "K"};
int suitsList[4] = {3, 4, 5, 6};
Card stacks[4][13];
Card piles[4][13];
int oldPos, pile;
int cardCount = 0;
char newPos;
fillDeck(deck, facesList, suitsList);
shuffle(deck);
system("PAUSE");
deal(deck, stacks);
while(cardCount != 51)
{
displayBoard(stacks, piles);
printf("\n\nChoose a column(1-13): ");
scanf(" %d", &oldPos);
oldPos--;
// if(stacks[0][oldPos] == 0)
// {
// printf("There's nothing to move in this column.");
// system("PAUSE");
// system("CLS");
// continue;
// }
printf("\nWhere to move this card to? (1-13 or p): ");
scanf(" %c", &newPos);
if(newPos == 'p') //needs wrong pile checker
{
printf("\nWhich pile? (1-4): ");
scanf(" %d", &pile);
pile--;
//needs more stuff
}
//check card is one more than card to be placed
}
system("PAUSE");
return 0;
}
void fillDeck(Card eDeck[], char cardFaces[][3], int cardSuits[])
{
int i;
for(i=0; i<=51; i++)
{
strcpy(eDeck[i].face, cardFaces[i%13]);
eDeck[i].suit = cardSuits[i/13];
}
}
void shuffle(Card fDeck[])
{
int i;
int randPos;
Card temp;
srand(time(NULL));
for(i = 0; i <= 51; i++)
{
randPos = rand() % 52;
temp = fDeck[i];
fDeck[i] = fDeck[randPos];
fDeck[randPos] = temp;
}
}
void deal(Card fDeck[], Card stacks[][13])
{
int i, k;
int j = 0;
for(i = 0; i < 4; i++)
{
for(k = 0; k < 13; k++)
{
stacks[i][k] = fDeck[j];
j++;
}
}
}