本文整理汇总了C++中playCard函数的典型用法代码示例。如果您正苦于以下问题:C++ playCard函数的具体用法?C++ playCard怎么用?C++ playCard使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了playCard函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char* argv[])
{
int coins;
int who;
struct gameState* s = newGame();
int k[10] = {adventurer, gardens, embargo, village, minion, mine, cutpurse,
sea_hag, tribute, smithy};
initializeGame(2, k, 3, s);
coins = s->coins;
who = s->whoseTurn;
s->hand[who][6] = steward;
s->handCount[who]++;
assert(playCard(6, 1, 0, 0, s) == 0);
assert(s->handCount[who] == 7);
s = newGame();
initializeGame(2, k, 3, s);
coins = s->coins;
who = s->whoseTurn;
s->hand[who][6] = steward;
s->handCount[who]++;
assert(playCard(6, 0, 0, 1, s) == 0);
assert(s->handCount[who] == 3);
printf("stewardEffect Passed. \n");
}
示例2: strategyCard
unsigned int Scopa::strategyPlay(std::function<Card()> strategyCard, std::function<CardGroup(std::vector<CardGroup>)> strategyCapture) {
Card cardToPlay = strategyCard();
std::vector<CardGroup> captures = possibleCaptures(cardToPlay.value);
if( captures.size() == 0 ) { return playCard(currentTurn, cardToPlay, CardGroup()); }
else if( captures.size() == 1 ) { return playCard(currentTurn, cardToPlay, captures.front()); }
else { return playCard(currentTurn, cardToPlay, strategyCapture(captures)); }
}
示例3: main
int main() {
printf("Running unit test for card \"steward\"...\n");
struct gameState G;
struct gameState *p = &G;
int seed = 123456789;
int coinsBefore;
int numHandCardsBefore;
int k[10] = {steward, gardens, embargo, village, minion, mine, cutpurse,
sea_hag, tribute, smithy};
initializeGame(2, k, seed, p);
p->hand[0][0] = steward;
coinsBefore = p->coins;
assertTrue(playCard(0, 0, 0, 0, p) == 0, "playCard(0, 0, 0, 0, p) == 0");
assertTrue(p->coins == coinsBefore + 2, "p->coins == coinsBefore + 2"); //BUG: coin values not updating
initializeGame(2, k, seed, p);
p->hand[0][0] = steward;
numHandCardsBefore = numHandCards(p);
assertTrue(playCard(0, 1, 0, 0, p) == 0, "playCard(0, 1, 0, 0, p) == 0");
assertTrue(numHandCards(p) == numHandCardsBefore + 2 - 1, "numHandCards(p) == numHandCardsBefore + 2 - 1");
initializeGame(2, k, seed, p);
p->hand[0][0] = steward;
numHandCardsBefore = numHandCards(p);
assertTrue(playCard(0, 2, 0, 0, p) == 0, "playCard(0, 2, 0, 0, p) == 0");
assertTrue(numHandCards(p) == numHandCardsBefore - 3 , "numHandCards(p) == numHandCardsBefore - 3");
return 0;
}
示例4: main
int main(){
struct gameState g;
int k[10] = {steward, smithy, adventurer, gardens, embargo, cutpurse, mine,
outpost, baron, tribute};
int choice2 = 0;
int choice3 = 0;
int handPos = 0;
initializeGame(2, k, 5, &g);
g.hand[0][0] = steward;
g.whoseTurn = 0;
int num = numHandCards(&g);
playCard(handPos, 1, choice2, choice3, &g);
int numa = numHandCards(&g);
// Steward adds two cards to the hand if choice1 == 1
assertTF(numa = num + 2, "Add 2 card to hand\n");
int coins = g.coins;
// Steward adds two coins if choice1 == 2
printf("coins b: %d\n", g.coins);
playCard(handPos, 2, choice2, choice3, &g);
assertTF(g.coins == coins + 2, "Add 2 coins\n");
printf("coins a: %d\n", g.coins);
num = numHandCards(&g);
// Steward trashes two cards if choice1 == 3
playCard(handPos, 3, choice2, choice3, &g);
numa = numHandCards(&g);
assertTF(numa == num - 3, "Trash 2 cards\n");
checkasserts();
}
示例5: main
//test buyCard()
int main()
{
int kCards[10] = {adventurer, gardens, embargo, village, minion, mine, cutpurse, sea_hag, tribute, smithy};
struct gameState orig, g;
int r, count;
//for consistancy make randomSeed=1
initializeGame(2, kCards, 1, &orig);
//keep copy of original state for testing purposes
memcpy(&g, &orig, sizeof(struct gameState));
//first hand of player 0 is {4 coppers, 1 estate}. 4 coins
count = supplyCount(curse, &g);
r = buyCard(-1, &g);
myAssert(r == -1, "Bought a non-existant card", __LINE__);
r = buyCard(council_room, &g);
myAssert(r == -1, "Bought council room which is not in supply", __LINE__);
r = buyCard(gold, &g);
myAssert(r == -1, "Gold costs 6 coins, bought with 4", __LINE__);
r = buyCard(embargo, &g);
myAssert(r == 0, "Could not buy an embargo with 4 coins", __LINE__);
r = buyCard(copper, &g);
myAssert(r == -1, "Bought more than one card on first turn", __LINE__);
myAssert(count == supplyCount(curse, &g), "curse gained before embargo played", __LINE__);
//player 0 gets embargo in hand buy turn 4 in handPos 3
//advance to turn 4 for player 0
for(int i = 0; i < 6; ++i)
endTurn(&g);
myAssert(handCard(3, &g) == embargo, "Did not properly gain bought embargo", __LINE__);
playCard(3, copper, 0, 0, &g); //put an embargo on coppers
endTurn(&g);
//hand of player 1 turn 4 is {4 coppers, 1 estate}. 4 coins
count = supplyCount(curse, &g);
r = buyCard(copper, &g);
myAssert(r == 0, "Try Buying a copper with a curse on it", __LINE__);
myAssert(count-1 == supplyCount(curse, &g), "Improper amount of curses removed from supply", __LINE__);
//advance to turn 5 where curse should appear in handPos 0
for(int i = 0; i < 2; ++i)
endTurn(&g);
r = handCard(0, &g);
myAssert(r == curse, "Player 1 did not recieve curse", __LINE__);
//restart game
buyCard(smithy, &orig);
//smithy will show up in turn 4 in handPos 3
//turn 4 player 0 hand is {4 coppers, 1 smithy}
for(int i = 0; i < 6; ++i)
endTurn(&orig);
buyCard(silver, &orig);
r = playCard(3, 0, 0, 0, &orig);
r = myAssert(r == -1, "buyCard could not advance the phase", __LINE__);
//done
if(r == 0)
printf("Tests completed successfully!\n");
return 0;
}
示例6: buy_card
void buy_card(struct gameState* p, int not_bought[10], int k[10])
{
int money = 0, j;
for(j = 0; j < numHandCards(p); j++)
{
if(handCard(j,p) == copper)
{
playCard(j, -1, -1, -1, p);
money++;
}
if(handCard(j,p) == silver)
{
playCard(j, -1, -1, -1, p);
money += 2;
}
if(handCard(j,p) == gold)
{
playCard(j, -1, -1, -1, p);
money += 3;
}
}
if(money > 7)
{
buyCard(province, p);
printf("%d Bought province\n", p->whoseTurn);
}
else if(money > 5)
{
for(j = 0; j < 10; j++)
{
if(!(bought(not_bought, p, k[j])))
{
buyCard(k[j], p);
printf("%d Bought %s\n", p->whoseTurn, get_name(k[j]));
j = 10;
}
}
}
else if(money > 5)
{
buyCard(gold, p);
printf("%d Bought gold\n", p->whoseTurn);
}
else if(money > 2)
{
buyCard(silver, p);
printf("%d Bought silver\n", p->whoseTurn);
}
else
{
buyCard(copper, p);
printf("%d Bought copper\n", p->whoseTurn);
}
}
示例7: play
void play(struct gameState *p,int pcard, int favCard, int *pnumcard, int who, int money){
int i = 0;
char cardname[32];
cardNumToName(favCard, cardname);
printf("your fav card is %s\n",cardname);
if (pcard != -1) {
cardNumToName(favCard, cardname);
printf("%d: %s played from position %d\n",who, cardname, pcard);
playCard(pcard, 1, 1, 1, p);
printf("%s played.\n",cardname);
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("%d: bought province\n",who);
buyCard(province, p);
}
else if (money >= 6) {
printf("%d: bought gold\n",who);
buyCard(gold, p);
}
else if ((money >= 4) && (*pnumcard < 2)) {
printf("%d: bought %s\n",who, cardname);
buyCard(favCard, p);
*pnumcard++;
}
else if (money >= 3) {
printf("%d: bought silver\n",who);
buyCard(silver, p);
}
printf("%d: end turn\n",who);
endTurn(p);
}
示例8: main
//test baron
int main()
{
int kCards[10] = {adventurer, gardens, embargo, village, minion, baron, cutpurse, sea_hag, tribute, smithy};
struct gameState g, orig;
int r;
//for consistancy make randomSeed=1
initializeGame(2, kCards, 1, &orig);
//turn 1 of player 0 is {4 coppers, 1 estate}. 4 coins
gainCard(baron, &orig, 2, 0);
memcpy(&g, &orig, sizeof(struct gameState));
//play baron normal, discard estate. get 4 coins
r = supplyCount(estate, &g);
playCard(5, 1, 0, 0, &g);
myAssert(r == supplyCount(estate, &g), "Baron gained estate while discarding", __LINE__);
myAssert(numHandCards(&g) == 4, "Did not properly discard", __LINE__);
for(int i = 0; i < numHandCards(&g); ++i)
myAssert(handCard(i, &g) == copper, "Did not properly discard", __LINE__);
//have 8 coins total
r = buyCard(gold, &g);
myAssert(r == 0, "Did not have 6 coins to buy gold", __LINE__);
r = buyCard(silver, &g);
myAssert(r == -1, "Bought silver, had more than 8 coins", __LINE__);
r = buyCard(estate, &g);
myAssert(r == 0, "Did not have 8 coins or 2 buys for estate", __LINE__);
r = buyCard(copper, &g);
myAssert(r == -1, "Got more than +1 buy from baron", __LINE__);
//play baron normal, dont discard estate so gain one
memcpy(&g, &orig, sizeof(struct gameState));
r = supplyCount(estate, &g);
playCard(5, 0, 0, 0, &g);
myAssert(r-1 == supplyCount(estate, &g), "Baron did not gain estate", __LINE__);
myAssert(handCard(4, &g) == estate, "Baron discarded estate in hand while gaining", __LINE__);
r = buyCard(duchy, &g);
myAssert(r == -1, "Bought duchy, gained coins when gaining estate", __LINE__);
//play baron, discard estate but have none so gain one
discardCard(4, 0, &orig, 0);
r = supplyCount(estate, &orig);
playCard(4, 1, 0, 0, &orig);
r = myAssert(r-1 == supplyCount(estate, &orig), "Did not gain with no estates in hand", __LINE__);
//done
if(r == 0)
printf("Tests completed successfully!\n");
return 0;
}
示例9: main
//test council room card
int main(){
printf("Start to test minion card.\n");
struct gameState state;
int numCard0, numCard1, numCard2, numCard3, numAct0;
int kindom[10] = {1,2,3,4,5,6,7,8,9,10};
initializeGame(4, kindom, 2, &state);
//player0 get2 2 cards in hand
state.handCount[0] = 2;
state.handCount[1] = 2;
state.handCount[2] = 5;
//the first card is minion
state.hand[0][0] = minion;
//player 0's turn
state.whoseTurn = 0;
//card number for 3 players
numCard0 = state.handCount[0];
numCard1 = state.handCount[1];
numCard2 = state.handCount[2];
numCard3 = state.handCount[3];
//action of current player
numAct0 = state.numActions;
//printf("numCard1 is: %d\n", numCard1 );
playCard(0, 0, 1, 0, &state);
//draw 4 card and discard 1 card
//printf("numCard1 is now: %d\n", state.handCount[1]);
printf("Testing handCount for player1 choice2 .\n");
assert (state.handCount[0] == 4);
printf("Passed.\n");
printf("Testing handCount for other players, choice2.\n");
assert (state.handCount[1] == numCard1);
assert (state.handCount[2] == 4);
printf("Passed.\n");
printf ("Testing the number of action.\n");
assert (numAct0 == state.numActions);
printf ("Passed.\n");
printf("Testing coins, choice1.\n");
state.handCount[0] = 1;
state.coins = 0;
state.hand[0][0] = minion;
state.whoseTurn = 0;
playCard(0, 1, 0, 0, &state);
printf("coins=");
assert (state.coins == 2);
printf("Bug found in line 910 of dominion.c.\n");
//assert (state.numBuys == numBuy + 1);
printf("Passed.\n");
printf("Card minion is working.\n");
}
示例10: main
int main (int argc, char** argv)
{
struct gameState g;
int players, seed, fails, deck, hand, check, test = 0;
int k[10] = {adventurer, gardens, embargo, village, minion, mine, cutpurse, sea_hag, tribute, smithy};
printf ("Starting tests.\n");
while(test<MAX_TESTS)
{
if(!argc)
seed = rand();
else
seed = 42;
players = rand() % 4;
initializeGame(players, k, seed, &g);
deck = rand() % MAX_DECK;
hand = rand() % MAX_HAND;
g.whoseTurn = players;
g.deckCount[players] = deck;
g.handCount[players] = hand;
addCardToHand(players, smithy, &g);
check = g.handCount[players];
playCard(hand, 0, 0, 0, &g);
if(check+2!=g.handCount[players])
fails++;
test++;
}
printf ("Test finished with %d fails out of %d tests.\n",fails,test);
return 0;
}
示例11: main
int main()
{
printf("CARD TEST THREE -- RUNNING\n");
struct gameState g;
int r, prevcoins;
int k[10] = {village, smithy, cutpurse, minion, council_room, sea_hag,treasure_map, ambassador, tribute, salvager};
initializeGame(2, k, 5, &g);
prevcoins = g.coins;
printf("# coins before minion = %d\n", prevcoins);
//give player 0 a minion
gainCard(minion, &g, 2, 0);
r = g.hand[0][5];
cassert(r == minion, "card 5 in hand is minion");
testfun("playCard with card = minion, +2 coins");
r = playCard(5, 1, 0, 0, &g); //choice 1; +2 coins
cassert(r == 0, "minion played");
r = g.numActions;
cassert(r == 1, "# actions = 1"); //assert # actions is 1
printf("# coins after minion = %d\n", g.coins);
r = g.coins;
cassert(r != prevcoins, "# coins changed"); //assert # coins is 2 more
printf("CARD TEST THREE -- FINISHED\n\n");
return 0;
}
示例12: main
int main() {
printf("Testing card: feast...\n");
// Setup
struct gameState G;
int k[10] = {village, smithy, feast, mine, outpost, adventurer, baron, cutpurse, tribute, embargo};
initializeGame(2, k, 10, &G);
G.whoseTurn = 1;
G.hand[1][0] = feast;
int handCount = G.handCount[1];
int deckCount = G.deckCount[1];
int discardCount = G.discardCount[1];
// Do something
// playCard(int handPos, int choice1, int choice2, int choice3, struct gameState *state)
playCard(0, village, 0, 0, &G);
// Did something, now check it
my_assert(G.handCount[1] == handCount, "Wrong number of cards in hand");
my_assert(G.deckCount[1] == deckCount, "Wrong number of cards in deck");
my_assert(G.discardCount[1] == discardCount + 1, "Wrong number of cards in discard");
my_assert(G.discard[1][0] == village, "Village card not in discard");
}
示例13: main
int main(int argc, char *argv[]){
struct gameState g;
int seed, test_max, num_playaz, player, deck_size, hand_size, output, turn, i;
int k[10] = {smithy,adventurer,gardens,embargo,cutpurse,mine,ambassador,outpost,baron,tribute};
if(argc = 3){
seed = atoi(argv[1]);
test_max = atoi(argv[2]);
output = atoi(argv[3]);
}
for(i = 0; i < test_max; i++){
num_playaz = rand() %3 + 2;
initializeGame(num_playaz, k, seed, &g);
//randomly test players
player = rand() % num_playaz;
deck_size = rand() % MAX_DECK;
hand_size = rand() % MAX_HAND;
g.whoseTurn = player;
g.deckCount[player] = deck_size;
g.handCount[player] = hand_size;
addCardToHand(player, smithy, &g);
playCard(hand_size, 0, 0, 0, &g);
printf("Smithy Test #%d: Players [%d] Player [%d] Deck Count [%d] Hand Count [%d + 1]\n", i, num_playaz, player, deck_size, hand_size);
}
}
示例14: main
int main(){
printf("\nCardtest4: great_hall\n");
struct gameState G;
int k[10] = {duchy, council_room, great_hall, province, baron, adventurer, smithy, minion, village, steward};
int hcBefore, hcAfter, actions_before, actions_after;
initializeGame(2, k, 3, &G);
G.hand[0][0] = great_hall;
hcBefore = G.handCount[0];
actions_before = G.numActions;
playCard(1, -1, -1, -1, &G);
hcAfter = G.handCount[0];
actions_after = G.numActions;
my_assert(hcAfter == hcBefore, "Handcounts."); //play 1 draw 1;
my_assert(actions_after == actions_before, "Actions."); //action +1 -1
printf("End Caretest4.\n");
return 0;
}
示例15: main
int main (int argc, char** argv) {
struct gameState G;
// Setting up the game state
G.numPlayers = 1;
G.whoseTurn = 0;
G.numBuys = 1;
G.numActions = 1;
G.coins = 0;
G.supplyCount[duchy] = 2;
// Player 0 stuff
G.handCount[0] = 3;
G.hand[0][0] = steward;
G.hand[0][1] = estate;
G.hand[0][2] = estate;
G.deckCount[0] = 2;
G.deck[0][0] = duchy;
G.deck[0][1] = duchy;
G.discardCount[0] = 0;
// Calling playCard with steward
int result;
result = playCard(0, 2, 1, 2, &G);
// Checking the results
printf("CARD TEST 4: STEWARD-------------\n");
printf("Value (expected): Actual\n");
printf("result (0): %i\n", result);
printf("handCount[0] (2): %i\n", G.handCount[0]);
printf("numActions (0): %i\n", G.numActions);
printf("coins (2): %i\n", G.coins);
printf("discardCount (3): %i\n", G.discardCount[0]);
return 0;
}