home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / x / xcu16.zip / clients / xhearts / hearts.h < prev    next >
C/C++ Source or Header  |  1991-10-03  |  8KB  |  317 lines

  1. /*
  2.  * Copyright 1991 Cornell University
  3.  *
  4.  * Permission to use, copy, modify, and distribute this software and its
  5.  * documentation for any purpose and without fee is hereby granted, provided
  6.  * that the above copyright notice appear in all copies and that both that
  7.  * copyright notice and this permission notice appear in supporting
  8.  * documentation, and that the name of Cornell U. not be used in advertising
  9.  * or publicity pertaining to distribution of the software without specific,
  10.  * written prior permission.  Cornell U. makes no representations about the
  11.  * suitability of this software for any purpose.  It is provided "as is"
  12.  * without express or implied warranty.
  13.  *
  14.  * CORNELL UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  15.  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  16.  * EVENT SHALL CORNELL UNIVERSITY BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  17.  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
  18.  * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
  19.  * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  20.  * PERFORMANCE OF THIS SOFTWARE.
  21.  *
  22.  * Author:  Gene W. Dykes, Program of Computer Graphics
  23.  *          580 Theory Center, Cornell University, Ithaca, NY 14853
  24.  *          (607) 255-6713   gwd@graphics.cornell.edu
  25.  */
  26.  
  27.  
  28. #include <stdio.h>
  29.  
  30. #define N_PLAYERS        4
  31. #define N_SUITS            4
  32. #define N_SUITS_PLUS_ONE    5
  33. #define N_DISCARDS        3
  34. #define N_TRICKS        13
  35. #define CARDS_PER_PLAYER    13
  36. #define CARDS_PER_SUIT        13
  37. #define CARDS_PER_DECK        52
  38. #define SHOOT_POINTS        26
  39.  
  40. #define SUIT_SPADES    0
  41. #define SUIT_HEARTS    1
  42. #define SUIT_DIAMONDS    2
  43. #define SUIT_CLUBS    3
  44.  
  45. #define RANK_ACE    12
  46. #define RANK_KING    11
  47. #define RANK_QUEEN    10
  48. #define RANK_JACK    9
  49. #define RANK_TEN    8
  50. #define RANK_NINE    7
  51. #define RANK_EIGHT    6
  52. #define RANK_SEVEN    5
  53. #define RANK_SIX    4
  54. #define RANK_FIVE    3
  55. #define RANK_FOUR    2
  56. #define RANK_THREE    1
  57. #define RANK_TWO    0
  58.  
  59. #define HEART_POINTS     1
  60. #define QUEEN_POINTS    13
  61. #define JACK_POINTS    10
  62.  
  63. #define HEART_POINT_CARDS    13
  64. #define QUEEN_POINT_CARDS     1
  65. #define JACK_POINT_CARDS     1
  66.  
  67. typedef void (*Program)() ;
  68.  
  69. typedef enum
  70.     {
  71.     HumanPhysiology,
  72.     ComputerPhysiology
  73.     } Physiology ;
  74.  
  75. typedef enum
  76.     {
  77.     NullMoonDecision,
  78.     LowerMe,
  79.     RaiseOthers
  80.     } MoonDecision ;
  81.  
  82. typedef enum
  83.     {
  84.     NullHandDecision,
  85.     AnotherHand,
  86.     NoMore
  87.     } HandDecision ;
  88.  
  89. typedef enum
  90.     {
  91.     NullClear,
  92.     ClearOnLegalPlay,
  93.     ClearOnLegalDiscard,
  94.     ClearOnReceipt
  95.     } PlayerError ;
  96.  
  97. typedef enum
  98.     {
  99.     NullMode,
  100.     DiscardMode,
  101.     ConfirmDMode,
  102.     ConfirmRMode,
  103.     PlayMode
  104.     } PlayerMode ;
  105.  
  106. typedef enum
  107.     {
  108.     InitialPass,
  109.     LeftPass,
  110.     RightPass,
  111.     AcrossPass,
  112.     KeepPass
  113.     } CurrentPass ;
  114.  
  115. typedef enum
  116.     {
  117.     LeftRightAcross,
  118.     LeftRight,
  119.     LeftRightAcrossKeep,
  120.     LeftRightKeep
  121.     } PassingStyle ;
  122.  
  123. typedef struct
  124.     {
  125.     XtAppContext app ;
  126.     Display    *dpy[N_PLAYERS] ;
  127.     Widget    wlm_id[N_PLAYERS] ;
  128.     Widget    top[N_PLAYERS] ;
  129.     Widget    table_deck[N_PLAYERS] ;
  130.     Widget    play_tbl[N_PLAYERS] ;
  131.     Widget    exchange_tbl[N_PLAYERS] ;
  132.     Widget    exchange_deck[N_PLAYERS] ;
  133.     Widget    exchange_discard[N_PLAYERS] ;
  134.     Widget    exchange_waiting[N_PLAYERS] ;
  135.     Widget    exchange_confirm_d[N_PLAYERS] ;
  136.     Widget    exchange_confirm_r[N_PLAYERS] ;
  137.     Widget    moon_decision[N_PLAYERS] ;
  138.     Widget    hand_decision[N_PLAYERS] ;
  139.     Widget    *hands[N_PLAYERS][N_SUITS] ;
  140.     Widget    score[N_PLAYERS][N_PLAYERS] ;
  141.     Widget    points[N_PLAYERS][N_PLAYERS] ;
  142.     Widget    tricks[N_PLAYERS][N_PLAYERS] ;
  143.     Widget    plays[N_PLAYERS][N_PLAYERS] ;
  144.     Widget    discards[N_PLAYERS][N_DISCARDS] ;
  145.     Widget    discard_bitmaps[N_PLAYERS][N_DISCARDS] ;
  146.     Widget    discard_suit[N_PLAYERS][N_DISCARDS][N_SUITS_PLUS_ONE] ;
  147.     Widget    south_bitmap[N_PLAYERS] ;
  148.     Widget    north_bitmap[N_PLAYERS] ;
  149.     Widget    east_bitmap[N_PLAYERS] ;
  150.     Widget    west_bitmap[N_PLAYERS] ;
  151.     Widget    discard_bitmap[N_PLAYERS][N_DISCARDS] ;
  152.     Widget    south_suit[N_PLAYERS][N_SUITS_PLUS_ONE] ;
  153.     Widget    north_suit[N_PLAYERS][N_SUITS_PLUS_ONE] ;
  154.     Widget    east_suit[N_PLAYERS][N_SUITS_PLUS_ONE] ;
  155.     Widget    west_suit[N_PLAYERS][N_SUITS_PLUS_ONE] ;
  156.     } XStruct ;
  157.  
  158. typedef struct
  159.     {
  160.     String    symbol ;
  161.     int        card ;
  162.     } Rank ;
  163.  
  164. typedef struct
  165.     {
  166.     String    symbol ;
  167.     Pixel    color[N_PLAYERS] ;
  168.     String    color_string ;
  169.     String    character ;
  170.     String    name ;
  171.     Rank    *rank; 
  172.     } Suit ;
  173.  
  174. typedef struct
  175.     {
  176.     int        suit ;
  177.     int        rank ;
  178.     } Card ;
  179.  
  180. typedef struct
  181.     {
  182.     Boolean    dealt ;
  183.     int        dealt_to ;
  184.     } Deal ;
  185.  
  186. typedef struct
  187.     {
  188.     int        card[N_PLAYERS] ;
  189.     int        leader ;
  190.     } Trick ;
  191.  
  192. typedef struct
  193.     {
  194.     int        score ;
  195.     Boolean    exchanged ;
  196.     Boolean    discard_confirmed ;
  197.     Boolean    exchange_confirmed ;
  198.     Boolean    legal_play ;
  199.     PlayerError    error_mode ;
  200.     int        n_chosen ;
  201.     PlayerMode    mode ;
  202.     int        pass_from ;
  203.     HandDecision hand_decision ;
  204.     Physiology    physiology ;
  205.     Program    discard_program ;
  206.     Program    play_program ;
  207.     String    name_string ;
  208.     } Player ;
  209.  
  210. typedef struct
  211.     {
  212.     /*
  213.      * These are useful public history attributes
  214.      */
  215.     int        goal ;
  216.     short    xsubi[3] ;
  217.     PassingStyle passing_style ;
  218.     int        n_discards ;
  219.     Boolean    jack_counts ;
  220.     Boolean    points_on_first_trick ;
  221.     Trick    trick[N_TRICKS] ;        
  222.     } History ;
  223.  
  224. typedef struct
  225.     {
  226.     /*
  227.      * These are private history attributes
  228.      */
  229.     int        cards_dealt[CARDS_PER_PLAYER] ;
  230.     int        cards_passed[N_DISCARDS] ;
  231.     int        cards_received[N_DISCARDS] ;
  232.     int        n_in_suit[N_SUITS] ;
  233.     int        *suit[N_SUITS] ;
  234.     } PvtHistory ;
  235.  
  236. typedef struct
  237.     {
  238.     String    seed ;
  239.     int        sleep_seconds ;
  240.     Boolean    conceded ;
  241.     String    seat[N_PLAYERS] ;
  242.     int        ccw[N_PLAYERS] ;
  243.     int        cw[N_PLAYERS] ;
  244.     MoonDecision moon_decision ;
  245.     HandDecision hand_decision ;
  246.     String    player_file ;
  247.     String    wlm_file ;
  248.     String    log_file ;
  249.  
  250.     Player    player[N_PLAYERS] ;
  251.     Deal    deck[CARDS_PER_DECK] ;
  252.     XStruct    x ;
  253.     Suit    suit[N_SUITS] ;
  254.     } Game ;
  255.  
  256. typedef struct
  257.     {
  258.     /*
  259.      * This is a snapshot of the current state of the game
  260.      */
  261.     int        n_tricks_played ;
  262.     int        n_played_to_trick ;
  263.     CurrentPass current_pass ;
  264.     } Snap ;
  265.  
  266. typedef struct
  267.     {
  268.     /*
  269.      * These are tables of just about anything one would want to know
  270.      * if examining the state of the game
  271.      */
  272.     int        total_points_taken ;
  273.     int        n_point_cards ;
  274.     int        n_point_cards_taken ;
  275.     int        n_points_taken[N_PLAYERS] ;
  276.     int        n_tricks_taken[N_PLAYERS] ;
  277.     int        total_hearts_played ;
  278.     int        trick_winner[N_TRICKS] ;
  279.     int        n_hearts_played[N_TRICKS] ;
  280.     Boolean    jack_played ;        
  281.     int        jack_played_trick ;
  282.     Boolean    queen_played ;        
  283.     int        queen_played_trick ;
  284.     Boolean    points_broken ;
  285.     int        points_broken_trick ;
  286.     Card    deck[CARDS_PER_DECK] ;
  287.     int        cards_per_suit[N_SUITS] ;
  288.     int        trick_taking_rank ;
  289.     int        sole_point_holder ;
  290.     } Info ;
  291.  
  292. #define CurrentTrick    (snap->n_tricks_played)
  293. #define SuitLead    (info->deck[history->trick[CurrentTrick].card[0]].suit)
  294. #define Leader        (history->trick[CurrentTrick].leader)
  295. #define ActivePlayer    (active_player (game, history, snap, info))
  296. #define TrickWinner    (info->trick_winner[CurrentTrick])
  297. #define LastTrickWinner    (info->trick_winner[CurrentTrick - 1])
  298. #define JackWinner    (info->trick_winner[info->jack_played_trick])
  299. #define ThereArePointsInTrick \
  300.    ( \
  301.     (info->n_hearts_played[CurrentTrick] > 0) || \
  302.     (info->queen_played && (info->queen_played_trick == CurrentTrick))\
  303.    )
  304. #define HeartsInThisTrick (info->n_hearts_played[CurrentTrick])
  305. #define QueenInThisTrick \
  306.     (info->queen_played && (info->queen_played_trick == CurrentTrick))
  307. #define JackInThisTrick \
  308.     (info->jack_played && (info->jack_played_trick == CurrentTrick))
  309.  
  310. extern Game *game ;
  311. extern History *history ;
  312. extern PvtHistory pvt_history[N_PLAYERS] ;
  313. extern Snap *snap ;
  314. extern Info *info ;
  315.  
  316. extern FILE *logerr ;
  317.