static void makeGame(Node **queue1, Node **queue2, struct gameState *state) { // check precondition Verify362(NUM_KINGDOM_CARDS < treasure_map - adventurer); srand(RANDOM_SEED); int randomSeed = rand(); int numPlayers = rand() % (MAX_PLAYERS - MIN_PLAYERS + 1) + MIN_PLAYERS; // pick random kingdom cards int kingdomCards[NUM_KINGDOM_CARDS]; for (int i = 0; i < NUM_KINGDOM_CARDS; i++) { int card = rand() % (treasure_map - adventurer + 1) + adventurer; bool tmp = hasCard(kingdomCards, i, card); while (tmp) { card = rand() % (treasure_map - adventurer + 1) + adventurer; tmp = hasCard(kingdomCards, i, card); } kingdomCards[i] = card; } char play[MAX_STR_LEN] = { '\0' }; char s[MAX_STR_LEN] = { '\0' }; int result = initializeGame(numPlayers, kingdomCards, randomSeed, state); toString(kingdomCards, NUM_KINGDOM_CARDS, s); sprintf(play, "initializeGame(numPlayers, kingdomCards, randomSeed, state) = %d\nnumPlayers = %d\nkingdom_cards = %s\nrandomSeed = %d", result, numPlayers, s, randomSeed); recordResult(queue1, queue2, state, play); }
inline void AbstractTimeDependentSimulation::doStepping() { while (time_ < maxTime_ && steps_ < maxNumberOfSteps_) { stepping(); ++steps_; time_ += dt_; if (steps_ % recordFrequency_ == 0) recordResult(); } report(); }
static void playTurn(Node **queue1, Node **queue2, struct gameState *state) { // action phase int handPos = findCardToPlay(state); if (state->numActions > 0 && handPos >= 0) { int choice1; int choice2; int choice3; int card = handCard(handPos, state); if (card == smithy) { // play smithy card choice1 = 0; choice2 = 0; choice3 = 0; } else if (card == mine) { // play mine card if (hasCard(state->hand[state->whoseTurn], numHandCards(state), copper)) { choice1 = findCard(state->hand[state->whoseTurn], numHandCards(state), copper); choice2 = silver; playCard(handPos, choice1, choice2, 0, state); } else if (hasCard(state->hand[state->whoseTurn], numHandCards(state), silver)) { choice1 = findCard(state->hand[state->whoseTurn], numHandCards(state), silver); choice2 = gold; playCard(handPos, choice1, choice2, 0, state); } else if (hasCard(state->hand[state->whoseTurn], numHandCards(state), gold)) { choice1 = findCard(state->hand[state->whoseTurn], numHandCards(state), gold); choice2 = gold; } choice3 = 0; } else if (card == village) { // play village card choice1 = 0; choice2 = 0; choice3 = 0; } else { Verify362(card == adventurer); // play adventurer card choice1 = 0; choice2 = 0; choice3 = 0; } char play[MAX_STR_LEN] = { '\0' }; int result = playCard(handPos, choice1, choice2, choice3, state); sprintf(play, "playCard(%d, %d, %d, %d, state) = %d", handPos, choice1, choice2, choice3, result); recordResult(queue1, queue2, state, play); } // buy phase int supplyPos = findCardToBuy(state); if (supplyPos >= 0) { char play[MAX_STR_LEN] = { '\0' }; int result = buyCard(supplyPos, state); sprintf(play, "buyCard(%d, state) = %d", supplyPos, result); recordResult(queue1, queue2, state, play); } // clean-up phase char play[MAX_STR_LEN] = { '\0' }; int result = endTurn(state); sprintf(play, "endTurn(state) = %d", result); recordResult(queue1, queue2, state, play); }