#include "Dice_Funcs.h" static uint8_t Has_Straight(uint8_t *roll_results, uint8_t dice){ /* return 1 if dice are a straight, else 0 should only be run when dice == full amount (first roll)*/ if(dice == 1) return 1; if(dice == 0) return 0; uint8_t num1 = 0; uint8_t num2 = SIDES; uint8_t match_found = 0; uint8_t *roll_results_ordered = malloc(dice*sizeof(uint8_t) ); //find lowest rolled number for(num1=0; num1 1) num2++; } if(num2 > 2) return 1; return 0; } void Roll_Dice(void){ uint8_t num1 = 0; uint8_t num2 = pd[gs.Cur_Player].rdc; for(num1=0; num1 2){ for(num3=0; num3 5){ if( Has_Three_Pair(num_counts, rolling_dice) ){ //must do entirely different if greater than 6 dice //could potentially have multiple three pairs ... //or three pairs + 1 + 5 + 3 of kind + etc. if(score < gs.Three_Pairs_Score){ rolling_dice = gs.Dice; score_final += gs.Three_Pairs_Score; continue; } } } if(rolling_dice == gs.Dice){ if( Has_Straight(roll_results, rolling_dice) ){ if(score < gs.Straight_Score){ rolling_dice = gs.Dice; score_final += gs.Straight_Score; continue; } } } //do zilch test here if(score == 0){ turn_not_over = 0; score_final = 0; continue; } uint32_t AI_Dice_Selections(void){ //mark the dice that the AI will keep, then return the score of those //set end turn if needed uint8_t dice_rolled = pd[gs.Cur_Player].rdc; uint8_t num1 = 0; uint8_t num2 = 0; for(num1=0; num1 2){ //FIXME: for more than 6 dice rolling_dice = dice_rolled - num_counts[num2]; num3 = 1; score_final += num_scores[num2]; break; } } if(num3 == 1) continue; //keep only a 1 to increase probabilities? if(num_counts[0] != 0){ //we have a 1 if(num_counts[0] < 3){ //we have less than 1000 //keep just 1 rolling_dice = dice_rolled - 1; score_final += 100; continue; } //keep them all rolling_dice = dice_rolled - num_counts[0]; score_final += num_scores[0]; continue; } //have only a 5 ? if(num_counts[4] != 0){ //we have a 5 rolling_dice = dice_rolled - 1; score_final += 50; continue; } //FIXME: function return value for main cleanup ie: errno printf("Error 1 !\n"); exit(0); } } if(score_final+score < pd[p_num].min_score_will_keep){ //must keep rolling num3 = 0; for(num2=0; num2 2){//FIXME: for more than 6 dice rolling_dice = dice_rolled - num_counts[num2]; num3 = 1; score_final += num_scores[num2]; break; } } if(num3 == 1) continue; if(num_counts[0] != 0){ if(num_counts[0] < 3){ rolling_dice = dice_rolled - 1; score_final += 100; continue; } rolling_dice = dice_rolled - num_counts[0]; score_final += num_scores[0]; continue; } if(num_counts[4] != 0){ rolling_dice = dice_rolled - 1; score_final += 50; continue; } //FIXME: see above printf("Error 2 !\n"); exit(0); }else{ turn_not_over = 0; } if( rolling_dice < pd[p_num].min_dice_will_roll){ //will keep rolling if new rolling_dice value is not too low //take score and end turn turn_not_over = 0; } score_final += score; } // free(roll_results); // free(kept_dice); // return score_final; //} void *Worker_Func(void *data){ uint32_t num1, num2; uint32_t turn = 0; uint8_t ten_k_reached = 0; uint32_t tentative_winner = 0; uint32_t leader_score = 0; struct timeval cur; gettimeofday(&cur, NULL); //pd = (struct Player_Data *)malloc(sizeof(struct Player_Data) * Num_Players); while(1==1){ sleep(1); if(gs.Exit_Program) break; } //free(pd); //pthread_exit(NULL); return NULL; } uint32_t Score_Of_Selection(void){ //return the score of currently selected dice //call from any selection activity callback //maybe use for AI too uint32_t Score = 0; uint8_t num1 = 0; } uint8_t Valid_Dice_Selection(uint8_t index){ //return TRUE if selected dice are valid and it is OK for a LOCAL_PLAYER to roll //all selected dice must contribute to points //If FALSE then Dice_Selections must be reset, and user given another chance to select properly //Function Don't edit any objects outside of itself uint8_t num1 = 0; uint8_t num2 = 0; uint8_t num_dice_selected = 0; uint8_t num_counts[SIDES]; for(num1=0; num1 5){ if(Has_Three_Pair(gs.Num_Counts, gs.Dice_Rolled)) return TRUE; } //has x of kind (void)memset(num_counts, '\0', sizeof(uint8_t) * SIDES); for(num2=0; num2