コード例 #1
0
ファイル: testdominion.c プロジェクト: cs362sp15/projects
static int findCardToPlay(struct gameState *state) {
  // randomly order cards to play
  int cards[NUM_CARDS_TO_PLAY];
  for (int i = 0; i < NUM_CARDS_TO_PLAY; i++) {
    // pick card to check
    int card = randomCardToPlay();
    bool tmp = hasCard(cards, i, card);
    while (tmp) {
      card = randomCardToPlay();
      tmp = hasCard(cards, i, card);
    }
    cards[i] = card;

    // check card
    int n = numHandCards(state);
    for (int j = 0; j < n; j++) {
      int tmp = handCard(j, state);
      if (card == tmp) {
        return j;
      }
    }
  }

  // didn't find card to play
  return -1;
}
コード例 #2
0
ファイル: testdominion.c プロジェクト: cs362sp15/projects
static int findCardToBuy(struct gameState *state) {
  // randomly order cards to buy
  int coins = countCoins(state);
  int cards[NUM_CARDS_TO_BUY];
  for (int i = 0; i < NUM_CARDS_TO_BUY; i++) {
    // pick card to check
    int card = randomCardToBuy();
    bool tmp = hasCard(cards, i, card);
    while (tmp) {
      card = randomCardToBuy();
      tmp = hasCard(cards, i, card);
    }
    cards[i] = card;

    // check card
    int cost = cardToBuyCost(card);
    int supply = supplyCount(card, state);
    if (supply > 0 && cost <= coins) {
      // found card to buy
      return card;
    }
  }

  // didn't find any card to buy
  return -1;
}
コード例 #3
0
ファイル: testdominion.c プロジェクト: cs362sp15/projects
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);
}
コード例 #4
0
ファイル: canvasplayer.cpp プロジェクト: HelWeis/SchafKopf
void CanvasPlayer::cardPlayed( Card* c )
{
    CanvasCard* card = hasCard( c->id() );
    if( card )
    {
        card->hide();
    }
}
コード例 #5
0
ファイル: Hand.cpp プロジェクト: littleLemming/Cards
bool Hand::dropCard(Karte k) {
	if (hasCard(k)) {
		Karte x = k;
		int z = -1;
		for (int i = 0; i < karten.size(); i++) {
			if (karten[i].equals(k)) {
				z = i;
				break;
			}
		}
		karten.erase(karten.begin()+z);
		return true;
	}
	return false;
}
コード例 #6
0
ファイル: Hand.cpp プロジェクト: littleLemming/Cards
Karte Hand::dropCard(int color,int number) {
	Karte k = findCard(color,number);
	if (hasCard(color,number)) {
		Karte x = k;
		int z = -1;
		for (int i = 0; i < karten.size(); i++) {
			if (karten[i].getNum() == number && karten[i].getColor() == color) {
				z = i;
				break;
			}
		}
		karten.erase(karten.begin()+z);
		return k;
	}
	throw "noSuchCard";
}
コード例 #7
0
ファイル: testdominion.c プロジェクト: cs362sp15/projects
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);
}