aboutsummaryrefslogtreecommitdiff
path: root/decks.c
diff options
context:
space:
mode:
authorNathan Vance <nathav63@gmail.com>2015-02-17 10:35:41 -0500
committerNathan Vance <nathav63@gmail.com>2015-02-17 10:35:41 -0500
commitae59eea6c0b8fe2a71896120f196fc200bec56fb (patch)
tree0ee57425862b1849b75c95665c0b9cf1c241c7c6 /decks.c
parentAdded deck data (diff)
download7w-ae59eea6c0b8fe2a71896120f196fc200bec56fb.tar.gz
7w-ae59eea6c0b8fe2a71896120f196fc200bec56fb.tar.bz2
7w-ae59eea6c0b8fe2a71896120f196fc200bec56fb.zip
Now separates out cards for a deck and shuffles!
Diffstat (limited to 'decks.c')
-rw-r--r--decks.c24
1 files changed, 23 insertions, 1 deletions
diff --git a/decks.c b/decks.c
index 0a1f2c2..8f6e22a 100644
--- a/decks.c
+++ b/decks.c
@@ -24,9 +24,12 @@ void shuffle(int *deck, int n)
int scratch[n];
int i = 0;
int size = n;
+ int k;
srand(time(NULL));
while(n) {
- scratch[i++] = deck[rand()%n];
+ k = rand()%n;
+ scratch[i++] = deck[k];
+ for(; k < n-1; k++) deck[k] = deck[k+1];
n--;
}
for(i = 0; i < size; i++) deck[i] = scratch[i];
@@ -35,4 +38,23 @@ void shuffle(int *deck, int n)
int* getdeck(int era, int numplayers)
{
int *ret = get_intarray(numplayers*7);
+ int guilds[10];
+ int i, j;
+ switch(era) {
+ case 0:
+ for(i = 0; i < numplayers*7; i++) ret[i] = era1[i];
+ break;
+ case 1:
+ for(i = 0; i < numplayers*7; i++) ret[i] = era2[i];
+ break;
+ case 2:
+ for(i = 0; i < 10; i++) guilds[i] = i+18;
+ shuffle(guilds, 10);
+ for(i = 0; i < numplayers*6-1; i++) ret[i] = era3[i];
+ for(j = 0; i < numplayers*7; i++, j++) ret[i] = guilds[j];
+ break;
+ default: break;
+ }
+ shuffle(ret, numplayers*7);
+ return ret;
}
bgstack15