Ejemplo n.º 1
0
Archivo: main.cpp Proyecto: CCJY/coliru
template <class... Ts> example(Ts&&... vs) : m_sum(compute_sum(vs...)) { }
Ejemplo n.º 2
0
Archivo: main.cpp Proyecto: CCJY/coliru
 Ts1 compute_sum(const Ts1& arg1, const Ts&... args)
 {
     return arg1 + compute_sum(args...); 
 }
Ejemplo n.º 3
0
void BasePlayer::add_card(Card* c) {
  Hand::add_card(c);  

  if (compute_sum() > BLACKJACK)
    set_state (BUST);
}
Ejemplo n.º 4
0
/* 
 * 1. Checks for BUST/WIN/LOSS
 * 2. Updates the players' bank of chips. If the players' score is EXACTLY 21
 *    (a natural), then chips increase by 1.5 (3 to 2). This explains why the
 *    chips_bank is a 'double' type. 
 * 3. Display the game summary
 * 
 * TODO: The checks in this function can be re-arranged to be shorter. Re-visit.
 */
void Player::check_and_declare_winner(int dtotal) {

  int ptotal = compute_sum();

  // Check Player bust first
  if (is_bust()) {

    chip_bank_ -= bet_;

    std::cout << "[BlackJack] PLAYER SUMMARY for " << name_ << " : " << std::endl;
    std::cout << "\t\tSTATE    : BUST" << std::endl;
    std::cout << "\t\tTOTAL    : " << ptotal << std::endl;
    std::cout << "\t\tLOST     : " << bet_ << " chips" << std::endl;
    std::cout << "\t\tCHIPS BALANCE : " << chip_bank_ << std::endl << std::endl;    

    return;
  }

  std::stringstream player_summary;

  player_summary << "[BlackJack] PLAYER SUMMARY for " << name_ << " : " << std::endl;


  if (dtotal > BLACKJACK) {
    
    if (ptotal < BLACKJACK) {

      set_state (WIN);
      chip_bank_ += bet_;

      player_summary << "\t\tSTATE          : WON" << std::endl;
      player_summary << "\t\tTOTAL          : " << ptotal << std::endl;
      player_summary << "\t\tCHIPS BALANCE  : " << chip_bank_ << std::endl;
      player_summary << "\t\tWINNINGS       : " << bet_ << " chips" << std::endl << std::endl;
      player_summary << "\t\tDEALER-STATE   : BUST\n";
      player_summary << "\t\tDEALER-TOTAL   : " << dtotal << std::endl;
    }
    else {
      set_state (NATURAL_WIN); // = BlackJack
      chip_bank_ += 1.5 * bet_;

      player_summary << "\t\tSTATE          : NATURAL WIN (21)" << std::endl;
      player_summary << "\t\tTOTAL          : " << ptotal << std::endl;
      player_summary << "\t\tCHIPS BALANCE  : " << chip_bank_ << std::endl;
      player_summary << "\t\tWINNINGS       : " << 1.5 * bet_ << " chips" << std::endl << std::endl;
      player_summary << "\t\tDEALER-STATE   : BUST\n";
      player_summary << "\t\tDEALER-TOTAL   : " << dtotal << std::endl;
    }
  }
  else {
    if (dtotal > ptotal) {	       
      set_state (LOSE);
      chip_bank_ -= bet_;

      player_summary << "\t\tSTATE          : LOST" << std::endl;
      player_summary << "\t\tTOTAL          : " << ptotal << std::endl;
      player_summary << "\t\tCHIPS BALANCE  : " << chip_bank_ << std::endl;
      player_summary << "\t\tLOST           : " << bet_ << " chips" << std::endl << std::endl;
      player_summary << "\t\tDEALER-STATE   : WON" << std::endl;
      player_summary << "\t\tDEALER-TOTAL   : " << dtotal << std::endl;
    }
    else if (ptotal == dtotal) {
      set_state (TIE);

      player_summary << "\t\tSTATE          : PUSH (DRAW)" << std::endl;
      player_summary << "\t\tTOTAL          : " << ptotal << std::endl;
      player_summary << "\t\tCHIPS BALANCE  : " << chip_bank_ << std::endl;
      player_summary << "\t\tWINNINGS       : NIL " << std::endl << std::endl;
      player_summary << "\t\tDEALER-STATE   : PUSH (DRAW) \n";
      player_summary << "\t\tDEALER-TOTAL   : " << dtotal << std::endl;
    }
    else {

      if (ptotal < BLACKJACK) {
	set_state (WIN);
	chip_bank_ += bet_;

	player_summary << "\t\tSTATE          : WIN" << std::endl;
	player_summary << "\t\tTOTAL          : " << ptotal << std::endl;
        player_summary << "\t\tCHIPS BALANCE  : " << chip_bank_ << std::endl;
	player_summary << "\t\tWINNINGS       : " << bet_ << " chips" << std::endl << std::endl;
      }
      else {
	set_state (NATURAL_WIN);
	chip_bank_ += 1.5 * bet_;	

	player_summary << "\t\tSTATE          : NATURAL WIN (21)" << std::endl;
	player_summary << "\t\tTOTAL          : " << ptotal << std::endl;
        player_summary << "\t\tCHIPS BALANCE  : " << chip_bank_ << std::endl;
	player_summary << "\t\tWINNINGS       : " << 1.5 * bet_ << " chips" << std::endl << std::endl;
      }

      player_summary << "\t\tDEALER-STATE     : LOST \n";
      player_summary << "\t\tDEALER-TOTAL     : " << dtotal << std::endl;      
    }
  }
  
  std::cout << player_summary.str() << std::endl; // May also save to a file
}
Ejemplo n.º 5
0
int main(int argc, char** argv) {
 MPI_Init(NULL, NULL);
int n=90;


int world_rank,world_size,hypercube_size,hypercube_rank;
MPI_Comm hypercube_3d;

  MPI_Comm_rank(MPI_COMM_WORLD, &world_rank);
  MPI_Comm_size(MPI_COMM_WORLD, &world_size);

//Initializing the dimensions and periods
int ndims=3;
int processPerDims[3]={3,3,3};
int periods[3]={1,1,1}

//Create the ring topology
MPI_Cart_create(MPI_COMM_WORLD,ndims,dims,periods,1,&hypercube_3d);



MPI_Comm_rank(ring_1d,&hypercube_rank);
MPI_Comm_size(ring_1d,&hypercube_size);

printf("the ranks are %d\n", hypercube_rank);
printf("the size is %d\n", hypercube_size);

  int num_elements_per_proc = n/9;

  // Create a random array of elements on the root process. Its total
  // size will be the number of elements per process times the number
  // of processes
 int *rand_nums =(int*)malloc(sizeof(int) * n);
int k=0;
  if (hypercube_rank == 0) {
   
    rand_nums = create_rand_nums(n);
  }

  // For each process, create a buffer that will hold a subset of the entire
  // array
  int *sub_rand_nums = (int*)malloc(sizeof(int) * num_elements_per_proc);

  // Scatter the random numbers from the root process to all processes in
  // the MPI world
  MPI_Scatter(rand_nums, num_elements_per_proc, MPI_INT, sub_rand_nums,
		  num_elements_per_proc, MPI_INT, 0, hypercube_3d);
 for(k=0;k<num_elements_per_proc;k++)
{
        printf("\n My rank is %d and value is: %d",hypercube_rank,sub_rand_nums[k]);
}

  
  // Compute the sum  of your subset
  int sub_sum = compute_sum(sub_rand_nums, num_elements_per_proc);
printf("\nI am rank %d and my sum is %d\n",hypercube_rank,sub_sum);
 
  int *sub_sums=NULL;
  if (hypercube_rank == 0) {
 sub_sums = (int*)malloc(sizeof(int) * hypercube_size);
  }
 
  MPI_Gather(&sub_sum, 1, MPI_INT, sub_sums,1, MPI_INT, 0, hypercube_3d);

int j;
for(j=0;j<hypercube_size;j++){
printf("I am after gather sum %d\n",sub_sums[j]);
}
 
  // p
  // p
  // p
  // p
  // p
  // Now thiae are the random values: %d",rand_nums[k]);
  // }
  // we have all of the partial averages on the root, compute the
  // total average of all numbers. Since we are assuming each process computed
  // an average across an equal amount of elements, this computation will
  // produce the correct answer.
 

  if (hypercube_rank == 0) {
    int sum = compute_sum(sub_sums, hypercube_size);
    printf("Sum of all hypercube_3d is %d\n", sum);
  }
if(hypercube_size==0){
free(rand_nums);
free(sub_sums);
}
free(sub_rand_nums);

  MPI_Barrier(MPI_COMM_WORLD);
  MPI_Finalize();
}