void print_pack_of_cards(pack_of_cards *pack) { char i; for (i = 0; i < MAX_CARDS; i++) { print_card_name(pack -> queue[i]); } }
char byte_to_card(char mask, card *card) { if (mask == -1) return 0; char flag = 0; char xor; int i,j; mask = mask & ~(1 << 6); for (i = 0; i < SIZE_COLORS; i++) { xor = color_card[i] ^ mask; for (j = 0; j < SIZE_NUMBERS; j++) { if (number_card[j] == xor) { card -> number_card = number_card[j]; flag = 1; break; } } if (flag) break; } if (!flag) return 0; flag = 0; xor = mask ^ number_card[j]; card -> color_card = xor; print_card_name(card); return 1; }
int main(int argc, char** argv){ //srand(time(NULL)); struct gameState *p = newGame(); int a, b, c, d, gs, k[10]; int ActCardVal, numPlayers, cardPos; char *cardTitle; char card_string[32]; for (a=0 ; a < MAX_TESTS ; a++){ printf("\n************************** STARTING GAME %i **************************\n\n", a+1); // RANDOMIZE NUMBER OF PLAYERS ------------------------ numPlayers = (rand() % 3) + 2; // 2-4 Players // RANDOMIZE KINGDOM CARDS ---------------------------- printf("KingdomCards: \n"); for (b=0 ; b<10 ; b++){ ActCardVal = (rand()%20)+7; c=0; while (c<b){ // check previous actions cards if (k[c]==ActCardVal){ ActCardVal = (rand()%20)+7; c=0; } c++; } k[b]=ActCardVal; cardNumToName(k[b],card_string); printf( "%d --> %s (%i) \n" , b+1 , card_string, ActCardVal); } printf("\n"); // INITIALIZE GAME ------------------------------------ gs = initializeGame(numPlayers, k, 2, p); int money = 0; int smithyPos = -1; int adventurerPos = -1; int i=0; int numSmithies = 0; int numAdventurers = 0; while (!isGameOver(p)) { printf("------------------------------------------\n"); money = 0; smithyPos = -1; adventurerPos = -1; for (i = 0; i < numHandCards(p); i++) { if (handCard(i, p) == copper) money++; else if (handCard(i, p) == silver) money += 2; else if (handCard(i, p) == gold) money += 3; else if (handCard(i, p) == smithy) smithyPos = i; else if (handCard(i, p) == adventurer) adventurerPos = i; } if ((rand() % 5) == 0) { if (smithyPos != -1) { printf("Player %i: smithy (%i) played from position %i\n", whoseTurn(p), ActCardVal, smithyPos); playCard(smithyPos, -1, -1, -1, p); if (ActCardVal < 0 || ActCardVal > 26) { printf("--> Card play failed\n"); } else { printf("--> Card play successful\n"); } money = 0; i = 0; while (i<numHandCards(p)) { if (handCard(i, p) == copper) { playCard(i, -1, -1, -1, p); money++; } else if (handCard(i, p) == silver) { playCard(i, -1, -1, -1, p); money += 2; } else if (handCard(i, p) == gold) { playCard(i, -1, -1, -1, p); money += 3; } i++; } } if (money >= 8) { printf("Player %i: bought province\n", whoseTurn(p)); buyCard(province, p); } else if (money >= 6) { printf("Player %i: bought gold\n", whoseTurn(p)); buyCard(gold, p); } else if ((money >= 4) && (numSmithies < 2)) { printf("Player %i: bought smithy\n", whoseTurn(p)); buyCard(smithy, p); numSmithies++; } else if (money >= 3) { printf("Player %i: bought silver\n", whoseTurn(p)); buyCard(silver, p); } printf("Player %i: end turn\n", whoseTurn(p)); endTurn(p); } else if ((rand() % 5) == 1) { if (adventurerPos != -1) { printf("Player %i: adventurer (%i) played from position %i\n", whoseTurn(p), ActCardVal, adventurerPos); gs = playCard(adventurerPos, -1, -1, -1, p); if (ActCardVal < 0 || ActCardVal > 26) { printf("--> Card play failed!\n"); } else { printf("--> Card play successful\n"); } } money = 0; i = 0; while (i<numHandCards(p)) { if (handCard(i, p) == copper) { playCard(i, -1, -1, -1, p); money++; } else if (handCard(i, p) == silver) { playCard(i, -1, -1, -1, p); money += 2; } else if (handCard(i, p) == gold) { playCard(i, -1, -1, -1, p); money += 3; } i++; } if (money >= 8) { printf("Player %i: bought province\n", whoseTurn(p)); buyCard(province, p); } else if ((money >= 6) && (numAdventurers < 2)) { printf("Player %i: bought adventurer\n", whoseTurn(p)); buyCard(adventurer, p); numAdventurers++; } else if (money >= 6) { printf("Player %i: bought gold\n", whoseTurn(p)); buyCard(gold, p); } else if (money >= 3) { printf("Player %i: bought silver\n", whoseTurn(p)); buyCard(silver, p); } printf("Player %i: endTurn\n", whoseTurn(p)); endTurn(p); } else { cardPos = rand() % numHandCards(p); ActCardVal = p->hand[whoseTurn(p)][cardPos]; cardTitle = print_card_name(ActCardVal); printf("Player %i: %s (%i) played from %i\n", whoseTurn(p), cardTitle, ActCardVal, cardPos); gs = playCard(ActCardVal, rand() % numHandCards(p), rand() % numHandCards(p), rand() % numHandCards(p), p); if (ActCardVal < 0 || ActCardVal > 26) { printf("--> Card play failed!\n"); } else { printf("--> Card play successful\n"); } money = 0; i = 0; while (i<numHandCards(p)) { if (handCard(i, p) == copper) { playCard(i, -1, -1, -1, p); money++; } else if (handCard(i, p) == silver) { playCard(i, -1, -1, -1, p); money += 2; } else if (handCard(i, p) == gold) { playCard(i, -1, -1, -1, p); money += 3; } i++; } if (money >= 8) { printf("Player %i: bought province\n", whoseTurn(p)); buyCard(province, p); } else if ((money >= 6) && (numAdventurers < 2)) { printf("Player %i: bought adventurer\n", whoseTurn(p)); buyCard(adventurer, p); numAdventurers++; } else if (money >= 6) { printf("Player %i: bought gold\n", whoseTurn(p)); buyCard(gold, p); } else if (money >= 3) { printf("Player %i: bought silver\n", whoseTurn(p)); buyCard(silver, p); } printf("Player %i: endTurn\n", whoseTurn(p)); endTurn(p); } } printf ("\n###################\n# FINAL SCORE \n"); int tempScore; for (d=0 ; d<numPlayers ; d++){ tempScore = scoreFor(d,p); printf("# Player %i: %i\n", d,tempScore); } printf ("###################\n\n"); } return 0; }