int main(int argc,char* argv[]){

	srand(time(NULL));

	int numtasks,rank;
	MPI_Status stats;

	MPI_Init(&argc,&argv);
	MPI_Comm_size(MPI_COMM_WORLD,&numtasks);
	MPI_Comm_rank(MPI_COMM_WORLD,&rank);
	
	cardDatatype = createNewType();
	
		
	switch(rank){
	case READER:
		readCards();
	break;
	case REPLACER:
		replaceAsterisk();
	break;
	case PRINTER:
		printCards();
	break;
	}	
	
	MPI_Finalize();

return 0;
}
Пример #2
0
void compareScores(int expectedScore, int playerNumber, struct state * gameState){
	if(expectedScore == scoreFor(playerNumber, gameState)){
		printf(" - PASSED\n");
	} else {
		printf(" - FAILED\n");
		printf("EXP: %i\n", expectedScore);
		printf("GOT: %i\n", scoreFor(playerNumber, gameState));
		printCards(0, gameState);
	}
}
Пример #3
0
int actDealer(struct player anyone, struct card *aDeck, int *counter, int pullLimit){ //
  char choice = 'h';
  int stay = 1;
  printf("%s TURN:\n", anyone.name);
  printCards(anyone.playerHand, anyone.startCards);
  checkHand(anyone.playerHand, anyone.startCards, &anyone.cardValue);
 /* Players  */
  if(pullLimit == 21){          
    if(anyone.cardValue == 21 && anyone.startCards == 2){   // check if Black Jack
      printf("BLACK JACK!\n");
      stay = 0;
    }
    while(choice == 'h' && stay == 1){           // gives,prints and updates card values while player types 'h'
      printf("Hit or stay? (h/s)\n");
      scanf("%c",&choice);
      getchar();
      if(choice == 'h' && anyone.cardValue <= 20){
        dealCards(&anyone, aDeck, counter);
        printCards(anyone.playerHand, anyone.startCards);
        checkHand(anyone.playerHand, anyone.startCards, &anyone.cardValue);
         
        if(anyone.cardValue > 20 || anyone.cardValue == -1)// if player is busted leave loop
            stay = 0;
          
      }
    }
  }

  /* Dealer */
  while(pullLimit < 18 && stay){
    while(anyone.cardValue < 16){                       // dealer has to pull until cardvalue > 16
        printf("Press enter to see next card\n");
        getchar();
        dealCards(&anyone, aDeck, counter);
        printCards(anyone.playerHand, anyone.startCards);
        checkHand(anyone.playerHand, anyone.startCards, &anyone.cardValue);
       }      
         stay = 0;
        
  }
  return anyone.cardValue;                // update cardvalue
}
Пример #4
0
// start the game of set
void SetGame::playSet()
{
	vector<Card> cards;
	gameDeck.Shuffle();
	gameDeck.Deal(NUMBER_OF_CARDS, cards);

	printCards(cards);
	findAllSets(cards, true).clear();
	gameDeck.Replace(cards);

	// Uncomment this but note that it will run long and probably not succeed!
	// findLargestNonSet();
}
/*
 *  The player chose to stay. This function represents the dealers turn,
 *  returning the final score of the dealer to the caller.
 */
int stay(char *dealerHand, char *deck, int *deckPointer) {
    printCards(dealerHand,0,0,false);

    int dealerScore = computeScore(dealerHand);
    if(dealerScore >= 17) { // Don't have the dealer try to hit on 17 or up
        return dealerScore;
    }

    while(true) {
        drawCard(dealerHand,deck, deckPointer);
        dealerScore = computeScore(dealerHand);
        printCards(dealerHand,0,0,false);
        if(dealerScore == BUST) {
            break;
        } else if(dealerScore == BLACKJACK) {
            break;
        } else if(dealerScore >= 16) {
            break;
        }
    }

    return dealerScore;
}
Пример #6
0
/*
 *
 * I took a brute force approach to this, using some rough math first to know that I should start around 18-20,
 * After one day, I found a 19 card deal without a set, then continued on with 20
 * this random guesser with infinite loops took 5 days on a powerful computer to randomly find the 20 nonset deal
 * There was a 1 in 4,694,436,188,839,116,720 (I think) chance of this happening per iteration! (I got lucky on the random)
 * I ran it on 21, but by the deadline the 20 is all I found. I think that this is the true largest anyway
 
 * Here's the output of the 20 cards it found without a set:

A Purple Striped Oval with the number 1
A Green Striped Diamond with the number 2
A Green Solid Oval with the number 1
A Purple Open Squiggle with the number 3
A Purple Solid Squiggle with the number 2
A Purple Solid Oval with the number 1
A Purple Solid Squiggle with the number 1
A Green Striped Diamond with the number 1
A Purple Solid Oval with the number 2
A Green Open Diamond with the number 3
A Green Solid Oval with the number 2
A Green Striped Oval with the number 1
A Red Striped Diamond with the number 3
A Purple Striped Oval with the number 2
A Purple Striped Squiggle with the number 3
A Green Solid Diamond with the number 3
A Green Striped Oval with the number 2
A Green Solid Squiggle with the number 3
A Purple Striped Diamond with the number 3
A Red Solid Squiggle with the number 3

 * Average number of available sets at -
 * 12:  12!/(9!3!) * 1/79 = 2.78...
 * 18:  18!/(15!3!) * 1/79 = 10.33
 * 19:  19!/(16!3!) * 1/79 = 12.27
 * 20:  20!/(17!3!) * 1/79 = 14.43
 *
 */
void SetGame::findLargestNonSet()
{
	vector<Card> NoSetCards;
	vector<Card> testCards;
	Deck testDeck;

	int startNum = 19;
	for (int num = 0; num < 3; num++)
	{
		// this will run for a long time and has a small chance of succeeding!!!
		for (int i = 0; i < 10000; i++)
		// while (true)
		{
			testDeck.Shuffle();
			testDeck.Deal(startNum + num, testCards);
			if (findAllSets(testCards, false).size() == 0)
			{
				cout << "Found no sets in a deal of " << startNum + num << " cards. Continuing with " << startNum + num + 1 << endl;
				NoSetCards = testCards;
				break;
			}
			else if (i % 100 == 0)
			{
				cout << "Testing " << startNum + num << " the " << i << "th time" << endl;
			}
			else if (i == 9999)
			{
				cout << "Found sets in 10000 random deals of " << startNum + num << " cards" << endl;
				goto END;
			}
			testDeck.Replace(testCards);
		}
	}
END:
	printCards(NoSetCards);

	int x;
	cin >> x;
}
Пример #7
0
int main(void){
  printf("WELCOME TO HENRYS BLACKJACK\n");
  //player1
  struct player player1;
  printf("Type name for player1: ");
  scanf("%s",player1.name);
  getchar();
  player1.playerHand = NULL;
  player1.cardValue = 0;
  player1.startCards = 2;
  printf("utan ptr: %d\n", player1.startCards);
  //player2
  struct player player2;
  printf("Type name for player2: ");
  scanf("%s",player2.name);
  getchar();
  player2.playerHand = NULL;
  player2.cardValue = 0;
  player2.startCards = 2;
  //computer
  struct player comp;
  strcpy(comp.name, "the dealer");
  comp.playerHand = NULL;
  comp.cardValue = 0;
  comp.startCards = 1;

  int cardCounter = 0;
  struct card *deck = NULL;
  deck = createDeck(deck);    // deck created
  int i;
  for(i=0; i<20; i++)
    shuffleDeck(deck);   // deck shuffled

  /* Name giving and first cards dealing  */
  printf("\n\nHand of %s:\n", player1.name);
  dealCards(&player1, deck, &cardCounter);
  printCards(player1.playerHand, player1.startCards);
  printf("\n\nHand of %s: \n", player2.name);
  dealCards(&player2, deck, &cardCounter);
  printCards(player2.playerHand, player2.startCards);

  printf("\n\nHand of %s: \n", comp.name);
  dealCards(&comp, deck, &cardCounter);
  printCards(comp.playerHand, comp.startCards);


  /* Hit or stay face  */
 printf("------------------------------------------------------\n");
 player1.cardValue = actDealer(player1,deck, &cardCounter,22);
 printf("------------------------------------------------------\n");
 player2.cardValue = actDealer(player2,deck, &cardCounter,22);
 printf("------------------------------------------------------\n");
    if(player1.cardValue  == -1 && player2.cardValue == -1){  // if both loses dealer does not have to continue
        printf("Both players lost!\n");
        printf("--------------------Game-finished---------------------\n");
        goto masteJagKompletteraNufragetecken;
    }
 comp.cardValue = actDealer(comp,deck,&cardCounter,17);
 printf("------------------------------------------------------\n");
 whoWon(player1, player2, comp);
 printf("--------------------Game-finished---------------------\n");

masteJagKompletteraNufragetecken:
/* Freeing memory */
free(deck);
free(player1.playerHand);
free(player2.playerHand);
free(comp.playerHand);
return 0;
}
Пример #8
0
void printHand(struct gameState *state, int player) {
    printCards(state->hand[player], state->handCount[player], "hand");
}
void loop() {
    static char deck[DECK_SIZE];
    static char dealerHand[HAND_SIZE];
    static char hand[HAND_SIZE];
    static int deckPointer = 0;

    static int playerScore = 0;
    static int dealerScore = 0;
    static bool first = true;
    static bool checkForWinner = false;


    if(first) {
        generateDeck(deck);
        drawHand(hand,deck, &deckPointer);
        drawHand(dealerHand, deck, &deckPointer);
        playerScore = computeScore(hand);

        if(playerScore == BLACKJACK) {
            printGameResult("Blackjack!", playerScore);
            resetGame(hand, dealerHand, deck, &playerScore, &dealerScore, &deckPointer, &checkForWinner);
        }
        first = false;
    }

    if(sensorValue != analogRead(A0)) {
        sensorValue = analogRead(A0);
        Button button = (Button) getButton();

        switch (button) {
            case UP_BTN:
                playerScore = hit(hand,deck, &deckPointer);
                break;
            case DOWN_BTN:
                dealerScore = stay(dealerHand,deck, &deckPointer);
                checkForWinner = true;
                break;
            case LEFT_BTN:
                break;
            case RIGHT_BTN:
                break;
            case SELECT_BTN:
                resetGame(hand,dealerHand,deck,&playerScore,&dealerScore,&deckPointer,&checkForWinner);
                break;
            default:
                break;
        }
    }

    printCards(hand,1,0, false);

    if(computeScore(hand) == BLACKJACK) {
        printGameResult("Win!", playerScore);
        resetGame(hand,dealerHand,deck,&playerScore,&dealerScore,&deckPointer,&checkForWinner);

    } else if(computeScore(hand) == BUST) {
        printGameResult("Bust!", computeScoreNoBust(hand));
        resetGame(hand,dealerHand,deck,&playerScore,&dealerScore,&deckPointer,&checkForWinner);
    }

    if(checkForWinner) {
        printCards(dealerHand, 0,0,false);
        if(computeScore(hand) > computeScore(dealerHand)) {
            printGameResult("Win!", computeScore(hand));
        } else if(computeScore(hand) == computeScore(dealerHand)) {
            printGameResult("Tie.", computeScore(hand));
        } else {
            printGameResult("Lose.", computeScore(hand));
        }

        resetGame(hand,dealerHand,deck,&playerScore,&dealerScore,&deckPointer,&checkForWinner);
    } else {
        printCards(dealerHand,0,0,true);
    }

    computeScore(hand) > 9 ? lcd.setCursor(14,1) : lcd.setCursor(15,1);
    lcd.print(computeScore(hand));
    delay(100);
}
Пример #10
0
void CardTableContainer::print()
{
    qDebug() << printCards();
}