int hit(double * arr, int * left, int t , double prob , int* player_ace, int hits){ //printf("hit(t = %d, hits = %d);\n",t,hits); if(hits == 0){ t = optimal_score(t, *player_ace); if(t>21){ arr[22] += prob; } else arr[t] += prob; } else{ for(int j=2;j<12;j++){ --left[j]; if(j == 11){ ++(*player_ace); int temp_hits = hits - 1; hit(arr, left, t+j , (prob * (double)(left[j]+1) / (double)(sum_left(left)+1) ) , player_ace, temp_hits); --(*player_ace); } else{ int temp_hits = hits - 1; hit(arr, left, t+j , (prob * (double)(left[j]+1) / (double)(sum_left(left)+1) ) , player_ace, temp_hits); } ++left[j]; } } return 1; }
void sum_left(struct node *root, int *sum) { if (root != NULL){ sum_left(root->left, sum); *sum = *sum + root->data; sum_left(root->right, sum); } }
int dealerProbability(double * arr, int * left, int t , double prob){ if(t<17){ int i=2; do{ if(left[i]){ if(t+i>21) arr[22] += (prob * (double)left[i] / (double)sum_left(left)); else if(t+i >= 17) arr[t+i] += (prob * (double)left[i] / (double)sum_left(left)); else{ --left[i]; dealerProbability(arr, left, t+i , (prob * (double)(left[i]+1) / (double)(sum_left(left)+1) ) ); ++left[i]; } } ++i; } while(i < 12); } return 0; }
int get_left_subtree_sum(struct node *root){ if (root == NULL) return NULL; int sum = 0; sum_left(root->left, &sum); return sum; }