Exemple #1
0
END_TEST

START_TEST (test_hand_blackjack)
{
  hand *h = get_hand();

  /* this is not blackjack */
  add_card_to_hand(h, 40);
  add_card_to_hand(h, 20);

  score_hand(h);
  print_hand(h);
  ck_assert(!hand_is_blackjack(h) );

  /* three cards with 21 is not blackjack*/
  //add_card_to_hand(
  
  /* this should be blackjack */
  reset_hand(h);
  add_card_to_hand(h, 1);
  add_card_to_hand(h, 50);
  score_hand(h);
  print_hand(h);
  ck_assert(hand_is_blackjack(h));
  
  free_hand(h);
} 
Exemple #2
0
Hand *create_batch_hand(char *card_info)
{
    char rank[3], suit[10];
    Hand *hand = create_hand();
    char *cp = card_info;
    int i = 0;
    sscanf(cp, "%s of %[a-z]s\n", rank, suit);
    add_card_to_hand(hand, rank, suit);
    while(cp = strchr(cp+1, ',')) { 
 	sscanf(cp, ", %s of %[a-z]s\n", rank, suit);	 
 	add_card_to_hand(hand, rank, suit); 
    } 
    return hand;
}
Exemple #3
0
END_TEST  

START_TEST (test_hand_to_string)
{
  hand *h = get_hand();
  char buffer[256];
  add_card_to_hand(h, 33);
  add_card_to_hand(h, 23);
  add_card_to_hand(h, 27);

  score_hand(h);
  
  strcpy(buffer, "# player ");
  hand_to_string(h, buffer);

  printf("[%s]\n", buffer);
  free_hand(h);
}
Exemple #4
0
int take_top_card(struct player *p, struct deck *d) {
	if (NULL == p) {
		return ERR_UNINITIALIZED_PLAYER;
	}
	if (NULL == d) {
		return ERR_UNINITIALIZED_DECK;
	}

 	return add_card_to_hand(p->h, pop(d));
}
Exemple #5
0
END_TEST     

/**
 * test the scoring functions */

START_TEST (test_hand_score)
{
  int test_card = 33;
  int expected = 0;
  hand *h = get_hand();

  /* empty hand, no score */
  ck_assert_msg(score_hand(h) ==  0, "expected empty hands to have zero score, got %d", score_hand(h)); 

  /* one card, easy score */
  add_card_to_hand(h, test_card);
  score_hand(h);
  print_hand(h);
  expected = get_value(test_card);
  ck_assert_msg(h->score == expected, "expected score %d, got %d", expected, h->score);

  /* two cards, no aces */
  add_card_to_hand(h, test_card+8);
  score_hand(h);
  print_hand(h);  
  expected += get_value(test_card+8);
  ck_assert_msg(h->score == expected, "expected score %d, got %d", expected, h->score);

  /* one card, an ace */
  reset_hand(h);
  add_card_to_hand(h, 1);
  score_hand(h);
  print_hand(h);
  ck_assert_int_eq(h->score, 11);
  ck_assert_int_eq(h->low_score, 1);
    
  
  /* two cards, an ace and the test_card */
  reset_hand(h);
  add_card_to_hand(h,1);
  add_card_to_hand(h, test_card);
  score_hand(h);
  print_hand(h);
  ck_assert_int_eq(h->score, 20);
  ck_assert_int_eq(h->low_score, 10);
  

  /* two cards, test_card then ace */
  reset_hand(h);
  add_card_to_hand(h, test_card);
  add_card_to_hand(h,1);
  score_hand(h);
  print_hand(h);
  /* scores should be the same as before, we just changed the ordering of the cards */
  ck_assert_int_eq(h->score, 20);
  ck_assert_int_eq(h->low_score, 10);
  
  reset_hand(h);
  add_card_to_hand(h, test_card);
  add_card_to_hand(h,1);
  add_card_to_hand(h, test_card-8);
  score_hand(h);
  print_hand(h);

  ck_assert_int_eq(h->score, 17);
  ck_assert_int_eq(h->low_score, 17);

  /* two aces */
  /* score list should be: 1+1, 1+11, 11+11 */
  /* tain't working */
  reset_hand(h);
  add_card_to_hand(h,1);
  add_card_to_hand(h,2);
  add_card_to_hand(h,12);  
  score_hand(h);
  print_hand(h);

  ck_assert_int_eq(h->score, 16);
  ck_assert_int_eq(h->low_score, 6);

  
  reset_hand(h);
  add_card_to_hand(h,1);
  add_card_to_hand(h,11);    
  add_card_to_hand(h,2);
  add_card_to_hand(h,3);
  add_card_to_hand(h,12);  
  score_hand(h);
  print_hand(h);

  ck_assert_int_eq(h->score, 20);
  ck_assert_int_eq(h->low_score, 10);

  printf("# special weird case \n");
  reset_hand(h);
  add_card_to_hand(h,40);
  add_card_to_hand(h,2);    
  add_card_to_hand(h,1);
  add_card_to_hand(h,45);
  score_hand(h);
  print_hand(h);

  //ck_assert_int_eq(h->score, 20);
  //ck_assert_int_eq(h->low_score, 10);
  
  
  /* busted?*/
  printf("# bust case \n");
  reset_hand(h);
  add_card_to_hand(h, 43);
  add_card_to_hand(h, 44);
  add_card_to_hand(h, 45);
  score_hand(h);
  print_hand(h);

  ck_assert_int_eq(h->score, h->low_score);
  ck_assert_int_eq(h->score, 30);
  
  free_hand(h);
}