home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / games / tbridge.zip / BRIDGE.PAS < prev    next >
Pascal/Delphi Source File  |  1986-06-01  |  7KB  |  205 lines

  1. {$C-}
  2.  {
  3.  
  4.             ╔══════════════════════════════════╗
  5.             ║   BRIDGE.PAS main module.        ║
  6.             ║   Last modified 10/29/85         ║
  7.             ╚══════════════════════════════════╝
  8.  
  9.   This program plays bridge, the most popular card game in
  10.   the world.
  11.  
  12.   System requirements:  IBM PC and true compatibles
  13.                         TURBO PASCAL 3.0
  14.                         DOS 2.0 or later
  15.                         192 K-bytes system memory minimum
  16.  
  17.   List of include modules:
  18.     DISPLAY.BR     SCORE.BR       DEFAULTS.BR 
  19.     INIT.BR        INPUT.BR       BID.BR 
  20.     PLAY.BR 
  21.  
  22.   List of data files:
  23.     BRIDGE        - Script of games played.  Created in INIT.BR.
  24.  
  25. }
  26. { Search control constants }
  27. const maxdeals    = 3;   { Maximum number of deals in the a search }
  28.       branchvalue = 0;   { Branch-value controlling the branching }
  29. var   cheat:  boolean;   { Indicates cheating during play }
  30.  
  31. const searchfac   = 8;   { Weight of search evaluation }
  32.       heurisfac   = 3;   { Weight of direct heuristics }
  33.  
  34. { The 4 hands }
  35. const
  36.   north =  0;
  37.   east  =  1;
  38.   south =  2;
  39.   west  =  3;
  40.  
  41. type
  42.   handtype  = north..west;
  43.  
  44. { The cards and bids }
  45. const
  46.   ace   = 14;
  47.   king  = 13;
  48.  
  49. type
  50.   valuetype = 2..ace;              { NT means No Trumph }
  51.   trumptype = (club,diamond,heart,spade,nt);
  52.   suittype  = club..spade;
  53.  
  54.   cardtype  = record
  55.                 suit:   suittype;    { Suit }
  56.                 value:  valuetype;   { Value }
  57.                 known,               { Card is known to player }
  58.                 played: boolean;     { Card has been played }
  59.               end;
  60.  
  61.   leveltype = 0..7;                   { Bid levels }
  62.  
  63.   bidtype   = record                  { Representation of bids }
  64.                 level: leveltype;
  65.                 trump: trumptype;
  66.               end;
  67.  
  68. const { Representation of the special bids }
  69.       pass : bidtype = (level: 0;   trump: nt);
  70.       dbl  : bidtype = (level: 0;   trump: club);
  71.       rdbl : bidtype = (level: 0;   trump: diamond);
  72.  
  73. { The DISTribution of the cards, and the state of the game.
  74.   REL and Rdist contains the real situation.
  75.   SIM and Sdist contains a simulated situation used in the search }
  76.  
  77. type
  78.   cardnotype   = 0..12;               { Index in DIST }
  79.   indextype    = 0..51;               { Used as index in DIST }
  80.  
  81. var   { DISTribution }
  82.   Rdist, Sdist: array[handtype,cardnotype] of cardtype;
  83.  
  84. { DATA about each of the 4 hands.
  85.   L contains the length of the 4 suits.
  86.   P contains number of points, including distribution points.
  87.   L but not P is updated when a card is played.
  88.   Thus P refers to the hand before any cards were played }
  89.  
  90. type  lengthtype = 0..13;
  91. var
  92.   rdata,sdata: array[handtype] of
  93.                       record
  94.                          l : array[suittype] of lengthtype;
  95.                          p : integer;
  96.                       end;
  97.  
  98.  
  99.  
  100. { INFORMATION about the real deal, known by all players.
  101.   This information is obtained mainly through the biddings.
  102.   MINL contains the minimum length of the suits.
  103.   Minus 1 means that the player have shown a void suit in the play.
  104.   MINP and MAXP contains the minimum and maximum number of points,
  105.   including distribution points.
  106.   MINL is updated for each bid and when a card is played.
  107.   MINP and MAXP are only updated at biddings.
  108.   Thus MINP and MAXP refer to the hand before any cards
  109.   were played }
  110.  
  111. type  infotype = record
  112.                     minl:      array[suittype] of -1..13;
  113.                     minp,maxp: integer;
  114.                  end;
  115.       PlayerHand = array[HandType] of boolean;
  116. var   info: array[handtype] of infotype;
  117.  
  118.  
  119.  
  120. var   { The BIDS made in the game, indexed by BIDNO.
  121.         BIDNO contains the number of bids made }
  122.       bids:        array[-4..51] of bidtype;
  123.       bidno:       0..52;
  124.  
  125.       contract:    bidtype;               { The contract }
  126.       doubled:     0..2;                  { Doubling status }
  127.       dummy:       handtype;              { The dummy hand }
  128.  
  129.       { The played game, card by card }
  130.       game:        array[indextype] of
  131.                       record
  132.                          hand: handtype;       { Hand }
  133.                          no:   cardnotype;     { Index to Rdist }
  134.                       end;
  135.  
  136.       rel,sim:     record        { State of the game during play }
  137.                       { Number of played cards }
  138.                       round:       0..52;
  139.                       { Tricks won by declarer }
  140.                       wontricks:   0..13;
  141.                       { Leading hand in this trick }
  142.                       leadhand:    handtype;
  143.                       { Lead suit }
  144.                       leadsuit:    suittype;
  145.                       { Best card in the trick }
  146.                       bestcard:    cardtype;
  147.                       { Player of best card }
  148.                       besthand:    handtype;
  149. { Hand to play }
  150.                       playinghand: handtype;
  151.                    end;
  152.  
  153.       TrickNo,
  154.       firstno:     0..13;                 { Trick number counters }
  155.  
  156.       GameNo:      integer;               { Game number }
  157.       dealer:      handtype;              { First player to bid }
  158.       computer:    PlayerHand;            { Indicates which hands }
  159.                                           {  the computer plays }
  160.       ShowTricks : boolean;               { Indicates whether past
  161.                                             tricks will be shown }
  162.       { The deals are saved on the disc }
  163.       outputfile:  text;
  164.  
  165. {$I DISPLAY.BR   }
  166. {$I SCORE.BR     }
  167. {$I DEFAULTS.BR  }
  168. {$I INIT.BR      }
  169. {$I INPUT.BR     }
  170. {$I BID.BR       }
  171. {$I PLAY.BR      }
  172.  
  173. var
  174.   BestBid    : BidType;                { Chosen bid }
  175.   BestChoice : CardNoType;             { Chosen card }
  176.   Redeal     : boolean;
  177.  
  178. begin { program body }
  179.   InitScore;
  180.   InitDefaults;
  181.   InitGames;
  182.   InitBids;
  183.   NewScreen;
  184.   repeat
  185.     ResetGame;
  186.     while not DoneBidding(BestBid) do;              { do bidding }
  187.     CleanUpBids;
  188.     if Contract.Level > 0 then
  189.     begin
  190.       DummyMessage;        { Play for your partner the declarer? }
  191.       StartPlay;
  192.       PlayCards(BestChoice, Redeal);
  193.       ResetPartner;                { if you switched w/ declarer }
  194.       if not Redeal then
  195.       begin
  196.         PrintResult;                      { Show contract winner }
  197.         CalculateScore;
  198.       end;
  199.     end { if }
  200.     else;                                     { Everyone passed! }
  201.     ChangeDefaults;                     { Display defaults menu? }
  202.   until false;                   { program terminates when user  }
  203. end.                             { selects eXit on the main menu }
  204.  
  205.