home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / games / volume3 / miles / part02 / main.c < prev    next >
C/C++ Source or Header  |  1988-01-25  |  10KB  |  276 lines

  1. /* main.c */
  2. /* maybe */
  3.  
  4. /**********************************************************************/
  5. /*                                                                    */
  6. /*           MM   MM  IIIIIII  L        L        EEEEEEE              */
  7. /*           M M M M     I     L        L        E                    */
  8. /*           M  M  M     I     L        L        EEEE                 */
  9. /*           M     M     I     L        L        E                    */
  10. /*           M     M  IIIIIII  LLLLLLL  LLLLLLL  EEEEEEE              */
  11. /*                                                                    */
  12. /*      BBBBBB    OOOOO   RRRRRR   NN    N  EEEEEEE   SSSSSS          */
  13. /*      B     B  O     O  R     R  N N   N  E        S                */
  14. /*      BBBBBB   O     O  RRRRRR   N  N  N  EEEEE     SSSSS           */
  15. /*      B     B  O     O  R    R   N   N N  E              S          */
  16. /*      BBBBBB    OOOOO   R     R  N    NN  EEEEEEE  SSSSSS           */
  17. /*                                                                    */
  18. /*                                                                    */
  19. /* Creation: Edmond Dujardin                                          */
  20. /*           (c) 1962 Parker Brothers, Inc.                           */
  21. /*                                                                    */
  22. /* Written by: Brett K. Carver                                        */
  23. /*             Hewlett-Packard, 1983.                                 */
  24. /*                                                                    */
  25. /* Copyright: (c) Brett K. Carver, Hewlett-Packard, 1986.             */
  26. /*                                                                    */
  27. /**********************************************************************/
  28.  
  29. #include <curses.h>
  30. #include "miles.h"
  31.  
  32. /**********************************************************************/
  33. /*                                                                    */
  34. /*              CONSTANTS AND VARIABLES                               */
  35. /*                                                                    */
  36. /**********************************************************************/
  37.  
  38. /**********************************/
  39. /* external procedure definitions */
  40. /**********************************/
  41.  
  42. extern initialize_io();
  43. extern display_banner();
  44. extern cleanup_io();
  45. extern deal_card();
  46. extern display_hand();
  47. extern display_pick();
  48. extern display_deck();          /* <=========================== debug */
  49. extern wait_for_move();
  50. extern valid_move();
  51. extern remove_card();
  52. extern play_card();
  53. extern compute_play_weight();
  54. extern compute_discard_weight();
  55. extern format();
  56. extern initialize_game();
  57. extern any_cards_left();
  58. extern another_match();
  59. extern another_question();
  60. extern extension_question();
  61. extern tabulate_score();
  62. extern init_random();
  63. extern random();
  64. extern message ();
  65. extern write_screen();
  66.  
  67. /*********************************/
  68. /* external variable definitions */
  69. /*********************************/
  70.  
  71. extern int deck[20];            /* shufled deck of cards */
  72. extern int hand[2][15];         /* current status of players */
  73. extern int change[2][15];       /* parallel structure of booleans */
  74. extern int cards_played[20];    /* set of cards already played */
  75. extern int extension;           /* boolean for extension */
  76. extern int whose_turn;          /* you, me, or -1 if game done */
  77. extern int play;                /* play=TRUE, discard=FALSE, drawn=-1 */
  78. extern int card_number;         /* card to play */
  79. extern int debug;               /* flag for debug output */
  80. extern char *screen;
  81.  
  82. extern char *T_shuffling_cards;
  83. extern char *T_make_play;
  84. extern char *T_you_won;
  85. extern char *T_me_won;
  86. extern char *T_endgame;
  87.  
  88. /**********************************************************************/
  89. /*                                                                    */
  90. /*              UTILITIES TO PLAY YOU AND ME TURNS                    */
  91. /*                                                                    */
  92. /**********************************************************************/
  93.  
  94. /*********************/
  95. /* you play one card */
  96. /*********************/
  97. you_play_turn()
  98. {
  99. card_number = 6;
  100. if (hand[you][card_number] = deal_card())
  101.     play = -1;
  102. else
  103.     play = TRUE;
  104. change[you][card_number] = TRUE;
  105. display_hand(you);
  106. display_pick(0);
  107. if (debug) display_deck();         /* <=========================== debug */
  108. while (TRUE) {
  109.     wait_for_move();
  110.     if (valid_move(you,card_number,play,TRUE)) {
  111.          remove_card(&cards_played[0],hand[you][card_number]);
  112.          if (play_card(you,card_number,play))
  113.               return(you);
  114.          else
  115.               return(me);
  116.          }
  117.     display_pick(0);
  118.     }
  119. }
  120.  
  121. /********************/
  122. /* me play one card */
  123. /********************/
  124. me_play_turn()
  125. {
  126. int me_card;
  127. int me_play;
  128. int me_weight;
  129. int weight;
  130. int i;
  131. hand[me][6] = deal_card();
  132. if (debug)            /* <=========================== debug */
  133.     for (i=0; i<7; i++)        /* <=========================== debug */
  134.          change[me][i] = TRUE;    /* <=========================== debug */
  135. remove_card(&cards_played[0],hand[me][6]);
  136. if (debug) display_hand(me);    /* <=========================== debug */
  137. if (debug) display_deck();      /* <=========================== debug */
  138. me_card = 0;
  139. me_play = TRUE;
  140. me_weight = -1;
  141. for (i=0; i<7; i++) {
  142.     weight = 0;                 /* <=========================== debug */
  143.     if (valid_move(me,i,TRUE,TRUE))
  144.          if ((weight = compute_play_weight(i)) > me_weight) {
  145.               me_weight = weight;
  146.               me_card = i;
  147.               me_play = TRUE;
  148.               }
  149.     if (debug)                  /* <=========================== debug */
  150.          format(weight,i + hand_loc + 20);
  151.     weight = 0;                 /* <=========================== debug */
  152.     if (valid_move(me,i,FALSE,TRUE))
  153.          if ((weight = compute_discard_weight(i)) > me_weight) {
  154.               me_weight = weight;
  155.               me_card = i;
  156.               me_play = FALSE;
  157.               }
  158.     if (debug)                  /* <=========================== debug */
  159.          format(weight,i + hand_loc + 30);
  160.     }
  161. if (debug) write_screen();      /* <=========================== debug */
  162. if (debug) sleep(2);            /* <=========================== debug */
  163. if (play_card(me,me_card,me_play))
  164.     return(me);
  165. else
  166.     return(you);
  167. }
  168.  
  169. /****************************/
  170. /* check for useable cards */
  171. /****************************/
  172. int useable_card(who,play)
  173. int who;
  174. int play;
  175. {
  176. int i;
  177. for (i=0; i<7; i++)
  178.     if (valid_move(who,i,play,FALSE))
  179.          return(TRUE);
  180. return(FALSE);
  181. }
  182.  
  183. /**********************************************************************/
  184. /*                                                                    */
  185. /*              MAIN PROGRAM                                          */
  186. /*                                                                    */
  187. /**********************************************************************/
  188.  
  189. /****************/
  190. /* main program */
  191. /****************/
  192. main ()
  193. {
  194. initialize_io();
  195. display_banner();
  196. message(T_shuffling_cards,TRUE);
  197. init_random();
  198. while (TRUE) {
  199.     hand[you][score] = hand[me][score] = 0;         /* set scores to 0 */
  200.     while (hand[you][score] < 10000 && hand[me][score] < 10000) {
  201.          initialize_game();
  202.          while (whose_turn != -1) {
  203.               switch (whose_turn) {
  204.                    case you : {
  205.                        if (deck[0] == 0)              /* no cards left to draw*/
  206.                              if ( ! useable_card(you,FALSE)) {  /* or to play */
  207.                                   whose_turn = me;
  208.                                   break;
  209.                                   }
  210.                         message(T_make_play,TRUE);
  211.                         whose_turn = you_play_turn();
  212.                         display_hand(you);
  213.                         display_hand(me);
  214.                         if (extension) {
  215.                              if (hand[you][miles] == 1000)
  216.                                   whose_turn = -1;
  217.                              }
  218.                         else
  219.                              if (hand[you][miles] == 700)
  220.                                   if (!(extension = extension_question()))
  221.                                        whose_turn = -1;
  222.                         break;
  223.                         }
  224.                    case me : {
  225.                         if (deck[0] == 0)             /* no cards left to draw*/
  226.                              if ( ! useable_card(me,FALSE)) {   /* or to play */
  227.                                   whose_turn = you;
  228.                                   break;
  229.                                   }
  230.                         whose_turn = me_play_turn();
  231.                         display_hand(you);
  232.                         display_hand(me);
  233.                         if (extension) {
  234.                              if (hand[me][miles] == 1000)
  235.                                   whose_turn = -1;
  236.                              }
  237.                         else
  238.                              if (hand[me][miles] == 700) {
  239.                                   if (hand[you][miles] == 0 ||
  240.                                       (deck[0] - 25 - (random() % 10)) < 0)
  241.                                        extension = FALSE;
  242.                                   else
  243.                                        extension = 2;
  244.                                   if (!extension)
  245.                                        whose_turn = -1;
  246.                                   }
  247.                         break;
  248.                         }
  249.                    }
  250.               if (whose_turn != -1 && deck[0] == 0)  /* no cards left to draw */
  251.                    if ( ! useable_card(you,TRUE) && ! useable_card(me,TRUE)) {
  252.                         message(T_endgame,FALSE);
  253.                         refresh();
  254.                         getch();
  255.                         whose_turn = -1;
  256.                         }
  257.               }
  258.          tabulate_score(TRUE);
  259.          if (hand[you][score] < 10000 && hand[me][score] < 10000)
  260.               if (!another_question())
  261.                    break;
  262.          }
  263.     if (hand[you][score] > hand[me][score])
  264.         message(T_you_won,FALSE);
  265.     else
  266.         message(T_me_won,FALSE);
  267.     sleep(2);
  268.     if (!another_match())
  269.          break;
  270.     }
  271. cleanup_io();
  272. exit(0);
  273. }
  274.  
  275. /*********** end of program **********/
  276.