home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / TOP / USR / SRC / yahtzee.t.Z / yahtzee.t / comp_select.c < prev    next >
Text File  |  1988-07-28  |  937b  |  43 lines

  1. /* comp_select.c
  2.  *    determines in which category the heuristics will place a
  3.  *    set of dice.
  4.  */
  5. #include <stdio.h>
  6. #include "defs.h"
  7.  
  8. #define three_of_a_kind 7
  9. #define four_of_a_kind 8
  10.  
  11. extern float cost_list[13][51];
  12. extern int machine[max_players];
  13. extern int scoreboard[max_players][max_marks];
  14.  
  15. int computer_select(player, dice, available, avail_count)
  16.  
  17. int player, dice[Five_Dice], available[13], avail_count;
  18.  
  19.     {
  20.     int i, best_mark, value;
  21.     float benefit, best_benefit = -1000.0;
  22.  
  23.     for (i = 0; i < avail_count; ++i)
  24.         {
  25.  
  26. /* determine the value of the dice for each available category */
  27.         value = eval(available[i], dice);
  28.  
  29. /* offset the value with the heuristic cost table */
  30.         benefit = value + cost_list[available[i] - 1][value];
  31.         if (benefit > best_benefit)
  32.             {
  33.  
  34. /* remember best category thus far */
  35.             best_benefit = benefit;
  36.             best_mark = available[i];
  37.             }
  38.         }
  39.  
  40. /* return overall best category */
  41.     return(best_mark);
  42.     }
  43.