std::string CPropertySheetHelper::GetSlot(const UINT uSlot)
{
	// strMsg = ". Slot n: ";
	std::string strMsg(". Slot ");
	strMsg += '0' + uSlot;
	strMsg += ": ";

	const SS_CARDTYPE OldCardType = m_ConfigOld.m_Slot[uSlot];
	const SS_CARDTYPE NewCardType = m_ConfigNew.m_Slot[uSlot];

	if ((OldCardType == CT_Empty) || (NewCardType == CT_Empty))
	{
		if (NewCardType == CT_Empty)
		{
			strMsg += GetCardName(OldCardType);
			strMsg += " card removed\n";
		}
		else
		{
			strMsg += GetCardName(NewCardType);
			strMsg += " card added\n";
		}
	}
	else
	{
			strMsg += GetCardName(OldCardType);
			strMsg += " card removed & ";
			strMsg += GetCardName(NewCardType);
			strMsg += " card added\n";
	}

	return strMsg;
}
//Displays the kingdom cards chosen for the game
void ChosenKingdomCards(int *arr)
{
        printf("These are the 10 kingdom cards chosen for the game:\n");
        int i;
        for(i = 0; i < 10; i++)
        {
                printf("%s\n" , GetCardName(arr[i]));
        }       
}
//Displays the current player's hand
void PlayersHand(struct gamestate *Game)
{
        int i;
        for(i = 0; i < numHandCards(Game); i++)
        {
             int cardValue = 0;
             cardValue = handCard(i, Game);
             printf("%s\n", GetCardName(cardValue)); 
        }
        
}
Example #4
0
CStr VerifyCard(CStr CardNumber)
{
	CardNumber = CleanCard(CardNumber);
	
	if (CardNumber.Length() == 0) 
		return 0;

	const char * b = CardNumber;
	const char * p;

	p = b;
	while (*p) {
		if (!isdigit(*p))
			return 0;
		++p;
	}

	int l = p - b;

   // check the length
	if ( l > 28 )
		return 0;

	int type = GetCardType(b, l);

	int mask = GetMask( type );

    if ( (l < 12) || ( (ShiftMask(l) && mask) == 0 ) )
		return 0;

   // check the checksum computation
	bool doChecksum;
	if ( type == cc_enroute )
		doChecksum = false;
	else
		doChecksum = true;

   if ( doChecksum && ( !ConfirmChecksum( CardNumber ) ) )
		return 0;

   return GetCardName(type);
}
int main (int argc, char** argv)
{
    
    printf("argument2 is %d\n", argv[1]);
    if(argc == 2)
    {
        srand(atoi(argv[1]));
    }
    else
    {
        //srand(time(NULL));
        srand(600);
    }
    struct gameState G; 
    struct gameState *Game = &G; 
    struct gameState state;
    int randomKingdomCard;
    int randomNumPlayers; 
    int KingdomCards[10];
    int KingdomCardsPos = 0;
    int RandomSeed;
    //Initializes random seed
    //srand (time(NULL));
    
    //int KingdomCards [10] = {adventurer, council_room, mine, minion, tribute, outpost, salvager, sea_hag, remodel, smithy};
    
    
    //Generates random number of players (2-4)
    randomNumPlayers = rand() % 3 + 2;
    printf("The random number of players is: %d\n", randomNumPlayers);

    //Gets the 10 random kingdom cards that must be unique 
    while(KingdomCardsPos != 10)
    {
        //Note: kingdom card values are between 7 and 26
        randomKingdomCard = rand() % 20 + 7;
        //Checks if the kingdom is not already in the array 
        if(isvalueinarray(randomKingdomCard, KingdomCards, KingdomCardsPos) == false)
        {
            KingdomCards[KingdomCardsPos] = randomKingdomCard;
            //printf("The kingdom card number is: %d\n", KingdomCards[KingdomCardsPos]);
            KingdomCardsPos = KingdomCardsPos + 1; 
        }
    }
    
    
    
    
    //Displays kingdom cards chosen 
     ChosenKingdomCards(KingdomCards);
    //Get random seed
    RandomSeed = rand();
    //Initialize game 
    initializeGame(randomNumPlayers, KingdomCards, RandomSeed, Game);
   
//Keep playing Dominion until the game is over 
    int TotTurns = 1;
    while(!isGameOver(Game))
    {
        printf("This is turn %d\n", TotTurns);
        //Displays the current player's hand
        printf("Start hand\n");
        PlayersHand(Game);
       
        //Gets the number of actions 
        int numberActions = 0;
        numberActions = Game->numActions;
        printf("The number of actions is: %d\n", numberActions);
        printf("The number of action cards is: %d\n", NumActionCards(Game));
        
//Action Phase     
        //Activate as many action cards as possible 
        while(Game->numActions > 0)
        {
                //PlayersHand(Game);
                //ChosenKingdomCards(KingdomCards);
                //printf("\n");
                //Exit loop no more action cards left 
                if(NumActionCards(Game) == 0)
                {
                        break;
                }
                //There are action cards in the player's hand 
                else
                {
                        
                        int randomChoice = GetMostExpensiveAction(Game, KingdomCards);
                        printf("The random choice is: %d\n", randomChoice);

                        int cardValue = handCard(randomChoice, Game);
                        printf("the cards name is %s\n", GetCardName(cardValue));

                        //Checks to see if the random card is a kingdom card that was chosen and if it's not gardens 
                        if(isvalueinarray(cardValue, KingdomCards, 10) == true && cardValue != 10)
                        {
                                
                                //printf("the name is %s\n", GetCardName(cardValue));
                               //These cards don't need choices adventurer, council_room, smithy, village, great_hall, tribute, cutpurse, outpost, sea_hag, and treasure_map
                               if(cardValue == 7 || cardValue == 8 || cardValue == 13 || cardValue == 14 || cardValue == 16 || cardValue == 19 || cardValue == 21 || cardValue == 23 || cardValue == 25 || cardValue == 26)
                               {
                                       //printf("number of actions is %d\n", NumActionCards(Game));
                                       int returnValue = playCard(randomChoice, 0 , 0, 0, Game);
                                       //printf("played %s return value is %d\n", GetCardName(cardValue),returnValue);
                                       
                                       //Success was able to play the card 
                                       if(returnValue == 0)
                                       {
                                                printf("Activated %s\n", GetCardName(cardValue)); 
                                                PlayersHand(Game);
  
                                       }
                                       
                                       //Exit the loop if you failed to play treasure_map 
                                       if(returnValue == -1 )
                                       {
                                               
                                               break; 
                                       }
                                       
                               }
                               //These cards require choices exit the loop 
                               else
                               {
                                       break;
                               }
                        }
                        
                }
        }
   
        //Displays had after action has been made 
        printf("Hand after action phase\n");
        PlayersHand(Game);
//Buy phase
        printf("The total money is: %d\n", moneyInHand(Game));
        printf("The total buys is: %d\n", Game->numBuys);
        //Buy a random card while you have money and buys available 
        while(Game->numBuys > 0 && moneyInHand(Game) > 0)
        {
                 int randomChoice = rand () % 17 + 0;
                 int CardValue = 0;
                 //Don't buy anything if you have less than 3 of money
                 if(moneyInHand(Game) < 3)
                 {
                         break; 
                 }
                 //The random card is one of the 10 kingdom cards chosen 
                 if(randomChoice < 10)
                 {
                         CardValue = KingdomCards[randomChoice];
                 }
                 //The random card is curse
                 if(randomChoice == 10)
                 {
                         CardValue = 0;
                 }
                 //The random card is estate 
                 if(randomChoice == 11)
                 {
                         CardValue = 1;
                 }
                 //The random card is duchy 
                 if(randomChoice == 12)
                 {
                        CardValue = 2; 
                 }
                 //The random card is province 
                 if(randomChoice == 13)
                 {
                     CardValue = 3; 
                 }
                 //The random card is copper 
                 if(randomChoice == 14)
                 {
                     CardValue = 4;
                 }
                 //The random card is silver 
                 if(randomChoice == 15)
                 {
                         CardValue = 5;
                 }
                 //The random card is gold
                 if(randomChoice == 16)
                 {
                         CardValue = 6;
                 }
                 
                 //Attempt to buy a card that is greater or equal
                 /*if(moneyInHand(Game) >= MostExpensiveKingdomCard(KingdomCards)-1 && getCost(CardValue) <= moneyInHand(Game))
                 {
                         int returnValue = 0;
                         returnValue = buyCard(CardValue, Game);
                         //You were able to buy the card 
                         if(returnValue == 0)
                         {
                                printf("Player bought %s and it cost %d\n", GetCardName(CardValue), getCost(CardValue));
                                break;
                         }
                         //You could not buy the card 
                         else
                         {
                                printf("The player could not buy %s\n", GetCardName(CardValue));
                         }
                 }*/
                 /*if(moneyInHand(Game) < MostExpensiveKingdomCard(KingdomCards)-1)
                 {
                         int returnValue = 0;
                         returnValue = buyCard(CardValue, Game);
                         //You were able to buy the card 
                         if(returnValue == 0)
                         {
                                printf("Player bought %s and it cost %d\n", GetCardName(CardValue), getCost(CardValue));
                                break;
                         }
                         //You could not buy the card 
                         else
                         {
                                printf("The player could not buy %s\n", GetCardName(CardValue));
                         }
                 }
                 
                 
                 */
                 //if(CardValue != 0 && CardValue != 1 && CardValue)
                 if(CardValue != 0 && CardValue != 1)
                 {
                         int returnValue = 0;
                         returnValue = buyCard(CardValue, Game);
                         //You were able to buy the card 
                         if(returnValue == 0)
                         {
                                printf("Player bought %s and it cost %d\n", GetCardName(CardValue), getCost(CardValue));
                                break;
                         }
                         //You could not buy the card 
                         else
                         {
                                printf("The player could not buy %s\n", GetCardName(CardValue));
                         }
                 }
        }
//End turn  
        printf("end turn\n\n");
        endTurn(Game);
        TotTurns = TotTurns + 1;
    }
//Displays the games results 
    printf ("The game is over!!!!!\n");
    ChosenKingdomCards(KingdomCards);
    printf("The total turns made in the game was %d\n", TotTurns-1);
    printf("This is the supply left of each kingdom card:\n");
    //Displays supply left of each card used in the game 
    for(int i = 0; i < 10; i++)
    {
            int TotCardsLeft =0;
            TotCardsLeft = supplyCount(KingdomCards[i], Game);
            printf("%s: %d\n", GetCardName(KingdomCards[i]),TotCardsLeft);
    }
    printf("%s: %d\n", GetCardName(0),supplyCount(0, Game));
    printf("%s: %d\n", GetCardName(1),supplyCount(1, Game));
    printf("%s: %d\n", GetCardName(2),supplyCount(2, Game));
    printf("%s: %d\n", GetCardName(3),supplyCount(3, Game));
    printf("%s: %d\n", GetCardName(4),supplyCount(4, Game));
    printf("%s: %d\n", GetCardName(5),supplyCount(5, Game));
    printf("%s: %d\n", GetCardName(6),supplyCount(6, Game));
    
    
    int HighestScore = -1;
    int PlayerWhoWon = 0; 
    for(int i = 0; i < randomNumPlayers; i++)
    {
        printf("Player %d score is: %d\n", i, scoreFor(i, Game));
        if(scoreFor(i, Game) > HighestScore)
        {
                HighestScore = scoreFor(i, Game);
                PlayerWhoWon = i;
        }
    }
    printf("The player who won is %d with a score of %d\n", PlayerWhoWon, HighestScore);
    printf("Updated version503\n");
    return 0;
}
Example #6
0
void PrintDeck (cardSet **deck) {
	for(cardType i = 0; i < MAX_CARD_TYPES; i++) {
		printf("%d %ss\n", GetNumCards(deck[i]), GetCardName(deck[i]));
	}
}