home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / games / tbridge.zip / BID.BR next >
Text File  |  1986-06-01  |  25KB  |  766 lines

  1.  {  ╔══════════════════════════════════════════════════════╗
  2.     ║          INPUT.BR  Module of BRIDGE.PAS              ║                                                      ║
  3.     ║                                                      ║
  4.     ║                Last modified 10/29/85                ║
  5.     ║                                                      ║
  6.     ║    Bids for the program and gets the users bids      ║
  7.     ║    from the keyboard and updates bidding information ║
  8.     ╚══════════════════════════════════════════════════════╝
  9.  }
  10. type  BidClassType  =
  11.          (OpenPass,        { Open Pass }
  12.           open1S,          { Open 1 Suit    (1 He) }
  13.           open2S,          { Open 2 Suit    (2 He) }
  14.           OpenNT,          { Open   NT      (1 NT) }
  15.  
  16.           Resppass,        { Response Pass  (1 He, Pass) }
  17.           resp2S,          { Response 2 S   (1 He, 2 He) }
  18.           resp3S,          { Response 3 S   (1 He, 3 He) }
  19.           resp1o1,         { Response 1-o-1 (1 He, 1 Sp) }
  20.           resp2o1,         { Response 2-o-1 (1 He, 2 Cl) }
  21.           resp1NT,         { Response 1 NT  (1 He, 1 NT) }
  22.           resp2NT,         { Response 2 NT  (1 He, 2 NT) }
  23.  
  24.           resp2S2NT,       { Response 2 S - 2 NT  (2 He, 2 NT) }
  25.           resp2Snorm,      { Response 2 S - Norm  (2 He, Others) }
  26.  
  27.           Stayman,         { Stayman  (1 NT, 2 Cl) }
  28.           RespStayman,     { Stayman response }
  29.           Blackwood,       { Blackwood (4 NT or 5 NT) }
  30.           RespBlackwood,   { Blackwood response }
  31.  
  32.           resp1NT2S,       { Response 1 NT - 2 S  (1 NT, 2 He) }
  33.           SecondBidNT,     { 2nd Bid NT     (1 He, 2 Cl, 2 NT) }
  34.           Shutout,         { Shutout Bids   (Open 3 He) }
  35.           OverCall,        { Opponent OverCall }
  36.  
  37.           NormPass,        { Normal Pass }
  38.           NormDBL,         { Normal Dbl }
  39.           NormRDBL,        { Normal RDbl }
  40.           NormBid,         { Normal Bid }
  41.           Illegal);        { Illegal Bid }
  42.  
  43. { The TYPes of the Bids found in Bids }
  44. var
  45.   BidTyp:  array[-4..51] of BidClassType;
  46.  
  47. procedure InitBids;
  48. { Initialize Bids[-4..-1] and BidTyp[-4..-1] }
  49. var
  50.   i: integer;
  51. begin
  52.   for i := -4 to -1 do
  53.   begin
  54.     Bids[i] := Pass;
  55.     BidTyp[i] := OpenPass;
  56.   end;
  57. end; { InitBids }
  58.  
  59. function Jumps(Bid: BidType): integer;
  60. { Count Number of Jumps from Contract to Bid }
  61. begin
  62.    if Bid.Trump <= Contract.Trump then
  63.       Jumps := Bid.Level-Contract.Level-1
  64.    else
  65.       Jumps := Bid.Level-Contract.Level;
  66. end; { Jumps }
  67.  
  68. type  NumberType  =  0..4;
  69.  
  70. function Number(Player: HandType;   v: ValueType): NumberType;
  71. { Count how many cards Player has of the Value }
  72. var
  73.   n : NumberType;
  74.   i : CardNoType;
  75. begin
  76.   n := 0;
  77.   for i := 0 to 12 do
  78.     if Sdist[Player,i].Value = v then
  79.       n := n + 1;
  80.   Number := n;
  81. end; { Number }
  82.  
  83. function BidClass(Bid: BidType): BidClassType;
  84. { Determines which BidClass the Bid belongs to,
  85.   using Contract, Bids and BidTyp }
  86. var
  87.   PartnerBidtyp: BidClassType;
  88. begin
  89.   with Bid do
  90.   begin
  91.     BidClass := NormBid;                  { Normal Bid }
  92.     if Jumps(Bid) >= 2 then               { Double Jumps are Illegal }
  93.       BidClass := Illegal;
  94.     PartnerBidtyp := BidTyp[BidNo-2];
  95.     if (PartnerBidtyp = Stayman) and      { Stayman response }
  96.        EqBid(Bids[BidNo - 1],Pass) then
  97.       BidClass :=  RespStayman
  98.     else
  99.       if (PartnerBidtyp = Blackwood) and  { Blackwood response }
  100.          EqBid(Bids[BidNo - 1],Pass) then
  101.         BidClass :=  RespBlackwood
  102.       else
  103.       if PartnerBidtyp = open2S then      { Response to opening 2 in Suit }
  104.       begin
  105.         BidClass := resp2Snorm;
  106.         if EqBid(Bids[BidNo-1],Pass) then
  107.         begin
  108.           if (Level = 2) and (Trump = NT) then  { 2 NT is weak }
  109.             BidClass := resp2S2NT
  110.           else
  111.             if EqBid(Bid,Pass) then { Pass is Illegal, other Bids are strong }
  112.               BidClass := Illegal
  113.          end
  114.          else
  115.            if EqBid(Bid,Pass) then
  116.              BidClass := resp2S2NT;
  117.       end
  118.       else
  119.         if EqBid(Bid,Pass) then                   { Passes }
  120.           if PartnerBidtyp = OpenPass then
  121.             BidClass := OpenPass
  122.           else
  123.             if PartnerBidtyp = open1S then
  124.               BidClass := Resppass
  125.             else
  126.               BidClass := NormPass
  127.         else
  128.          if EqBid(Bid,Dbl) then                   { Doubles }
  129.            BidClass := NormDBL
  130.          else
  131.            if EqBid(Bid,RDbl) then                { Redoubles }
  132.              BidClass := NormRDBL else
  133.       if (Trump = NT) and                         { Blackwood }
  134.          ((Level = 4) or
  135.           (Level = 5) and (BidTyp[BidNo-4] = Blackwood)) then
  136.         BidClass := Blackwood else
  137.       if PartnerBidtyp = OpenNT then  { Response to opening in NT }
  138.       begin
  139.         if Level = Bids[BidNo-2].Level + 1 then
  140.           if Trump = Club then        { Club is Stayman }
  141.             BidClass := Stayman else
  142.             { 2 in Suit is very weak }
  143.             if (Level = 2) and (Trump <> NT) then
  144.                BidClass := resp1NT2S
  145.       end
  146.       else
  147.         if (Trump = NT) and           { Opening 1 in Suit, second Bid NT }
  148.            ((PartnerBidtyp = resp1o1) and (Level <= 2) or
  149.            (PartnerBidtyp = resp2o1) and (Level <= 3)) then
  150.           BidClass := SecondBidNT
  151.         else
  152.          { Response to opening 1 in Suit }
  153.           if PartnerBidtyp = open1S then
  154.           begin
  155.             if Trump = Bids[BidNo-2].Trump then
  156.             begin
  157.               if Level = 2 then
  158.                 BidClass := resp2S
  159.               else
  160.                 if Level = 3 then
  161.                   BidClass := resp3S;
  162.             end
  163.             else
  164.               if Trump = NT then
  165.               begin
  166.                 if Level = 1 then
  167.                   BidClass := resp1NT
  168.                 else
  169.                   if Level = 2 then
  170.                     BidClass := resp2NT;
  171.               end
  172.               else
  173.                 if Level = 1 then
  174.                   BidClass := resp1o1
  175.                 else
  176.                   if Level = 2 then
  177.                     BidClass := resp2o1;
  178.           end
  179.           else
  180.            if BidNo < 4 then
  181.              if (Trump = NT) and (PartnerBidtyp = OpenPass) then
  182.                BidClass := OpenNT         { Opening in NT }
  183.            else
  184.              if EqBid(Contract,Pass) then
  185.                if Level = 1 then          { Opening in Suit }
  186.                  BidClass := open1S
  187.                else
  188.                  if Level = 2 then
  189.                    BidClass := open2S
  190.                  else
  191.                    BidClass := Shutout
  192.              else
  193.                if Trump <> NT then       { Opponents first Bid }
  194.                  if Jumps(Bid) = 0 then
  195.                    BidClass := OverCall
  196.                  else
  197.                    BidClass := Shutout;
  198.   end; { with }
  199. end; { BidClass }
  200.  
  201. type  TaskType  =  (CalcInfo,Evaluate);
  202.  
  203. function BidSystem(Bid: BidType;   Task: TaskType): integer;
  204. { Depending on Task, BidSystem will
  205.   Task CalcInfo:  Update Info according to the Bid.
  206.   Task Evaluate:  Evaluate how the Bid fits with the present Hand }
  207. var
  208.   Player, Partner : HandType;   { Player to Bid and his Partner }
  209.   InfoPlayer      : InfoType;   { Updated Info for Player }
  210.   BidVal          : integer;    { The Evaluation of Bid }
  211.   Test            : BOOLEAN;    { Evaluate the Bid by testing
  212.                                   the Hand with InfoPlayer }
  213.  
  214.    { Necessary points to win a Contract }
  215. const MinTab: array[BOOLEAN,LevelType] of integer  =
  216.                 ((0,20,20,23,26,29,33,37),    { Suit contracts }
  217.                  (0,20,20,26,29,32,35,39));   { NT   contracts }
  218.  
  219. procedure NormalPass;
  220. { Pass if the present Contract is correct }
  221. var
  222.   p : integer;
  223. begin
  224.   with InfoPlayer,Contract do
  225.   begin
  226.     p := Info[Partner].MinP;
  227.     if Level = 7 then
  228.       MaxP := 40
  229.     else
  230.       MaxP := MinTab[false,Level + 1]-p-2;
  231.  
  232.     if not odd(Player + Dummy) then
  233.     begin
  234.       if (Level < 4) and not ((Level = 3) and (Trump = NT)) then
  235.         MaxP := Max(MaxP,24-p)      { Check Game chance }
  236.       else
  237.         if (Level > 4) or (Trump >= Heart) then
  238.         begin
  239.           if Level < 6 then         { Check slam chance }
  240.             MaxP := Max(MaxP,32-p);
  241.           BidVal := 9;
  242.         end;
  243.             { Check the Suit }
  244.         if Trump <> NT then
  245.           Minl[Trump] := 7-Info[Partner].Minl[Trump];
  246.     end;
  247.                { if the Opponent Bids then Pass means weak Hand }
  248.     if not EqBid(Bids[BidNo-1],Pass) then
  249.       MaxP := Max(MaxP,MinP + 2);
  250.   end; { with }
  251. end; { NormalPass }
  252.  
  253. procedure NormalBid;
  254. { All normal Bids }
  255.  
  256. function MinPoints(Level: integer;
  257.                    Trump: TrumpType; Jump: BOOLEAN): integer;
  258. { Minimum points for Bidding Level in TRUMPH }
  259. var
  260.   Pts, MinPts : integer;
  261.   FoundTrump  : TrumpType;
  262.  
  263. function FoundSuit: TrumpType;
  264. { Returns the eventual chosen trumpsuit }
  265. var
  266.   s : SuitType;
  267. begin
  268.   FoundSuit := NT;
  269.   for s := Club to Spade do
  270.     if Info[Player].Minl[s] + Info[Partner].Minl[s] >= 8 then
  271.       FoundSuit := s;
  272. end; { FoundSuit }
  273.  
  274. begin { MinPoints }
  275.   with Info[Partner] do
  276.   begin
  277.     { Make sure Partner can Bid the right Trump without getting too High }
  278.     FoundTrump := FoundSuit;
  279.     if (Trump > FoundTrump) and (Trump <> NT) then
  280.       Level := Level + 1;
  281.     Level := Min(Level,7);
  282.     MinPts := InfoPlayer.MinP;
  283.     { Bidding when the Opponent has bidden means extra strength }
  284.     if not EqBid(Bids[BidNo-1],Pass) then
  285.       MinPts := MinPts + 3;
  286.     Pts := MinTab[Trump = NT,Level]-MinP-1;
  287.     if odd(Player + Dummy) and not Jump then
  288.       Pts := Pts-2;
  289.     MinPts := Max(MinPts,Pts);
  290.     if Jump or (Trump = Contract.Trump) or
  291.       (FoundTrump <> NT) and (FoundTrump = Contract.Trump) then
  292.       if Level > 5-Ord(Trump) div 2 then   { Above Game means slam interest }
  293.          Pts := 33-MaxP
  294.       else                                 { Jump means Game demand }
  295.         if (Level = 5-Ord(Trump) div 2) or Jump then
  296.           Pts := 25-MinP
  297.         else
  298.           Pts := 26-MaxP;
  299.     MinPoints := Max(MinPts,Pts);
  300.   end; { with }
  301. end; { MinPoints }
  302.  
  303. var
  304.   s : SuitType;
  305.   i : integer;
  306.   n : LevelType;
  307. begin { NormalBid }
  308.   with Sdata[Player],InfoPlayer,Bid do
  309.   begin
  310.     if Trump <> NT then                    { Trump Length }
  311.       Minl[Trump] := Min(Max(Minl[Trump] + 1,4),
  312.                          8-Info[Partner].Minl[Trump])
  313.     else
  314.       if Level <> 3 then                   { NT means No singletons }
  315.       begin
  316.         for s := Club to Spade do
  317.           Minl[s] := 2;
  318.         BidVal := -9;
  319.         i := BidNo-2;
  320.         while i >= 0 do
  321.         begin
  322.           with Bids[i] do
  323.             if (Trump = NT) and (Level > 0) then
  324.               BidVal := 0;
  325.           i := i-4;
  326.         end;
  327.       end;
  328.   n := Level-Jumps(Bid);            { Calculate MinP and MaxP }
  329.   MinP := MinPoints(n  ,Trump,false);
  330.   MaxP := MinPoints(n + 1,Trump,true);
  331.   MaxP := Max(MaxP,MinP + 3);
  332.   if n = Level then
  333.     MaxP := MaxP-1
  334.   else
  335.   begin
  336.     MinP := MaxP;
  337.     MaxP := Info[Player].MaxP;
  338.   end;
  339.          { Bid in major when possible }
  340.   if (l[Heart] + Info[Partner].Minl[Heart]  >=  8) or
  341.      (l[Spade] + Info[Partner].Minl[Spade]  >=  8) then
  342.   begin
  343.     if Trump = NT then
  344.       BidVal := -100
  345.     else
  346.       if l[Trump] + Info[Partner].Minl[Trump]  <  8 then
  347.         BidVal := -100;
  348.   end
  349.   else
  350.     { do not Bid if Partner Bids 3 NT }
  351.     if (Contract.Level = 3) and (Contract.Trump = NT) then
  352.       BidVal := -100;
  353.     if Level >= 5 then   { do not Bid if Partner has used Blackwood }
  354.     begin
  355.       i := BidNo-2;
  356.       while i >= 0 do
  357.       begin
  358.         if BidTyp[i] = Blackwood then
  359.           BidVal := -300;
  360.         i := i-4;
  361.       end;
  362.     end;
  363.   end;
  364. end; { NormalBid }
  365.  
  366. procedure NormalDBL;
  367. { Double if the Contract will go at least 2 down }
  368. var
  369.   Tricks: integer;
  370. begin
  371.   with Sdata[Player],Contract do
  372.   begin
  373.     Tricks := (p-DistPoints(Player) + Max(Info[Partner].MinP-2,0)) div 4-1;
  374.     if Trump <> NT then
  375.       if l[Trump] > 3 then
  376.         Tricks := Tricks + l[Trump]-3;
  377.      BidVal := 10;
  378.      if Tricks < 2 + 7-Level then
  379.        BidVal := -140;
  380.   end;
  381. end; { NormalDBL }
  382.  
  383. var
  384.   s   : SuitType;
  385.   Val : integer;
  386.   Len : integer;
  387. begin { BidSystem }
  388.   Player := (Dealer + BidNo) and 3;
  389.   Partner := (Player + 2) and 3;
  390.   InfoPlayer := Info[Player];
  391.   Test := true;
  392.   BidVal := 0;
  393.   with Sdata[Player],InfoPlayer,Bid do
  394.   begin
  395.     case BidClass(Bid) of
  396.       { Opening Bids }
  397.       OpenPass: begin   { Opening Pass, 0-12 p }
  398.                   MaxP := 12;
  399.                 end;
  400.       open1S  : begin   { Opening 1 S, 13-23 p, 4 trumps }
  401.                   MinP := 13;
  402.                   MaxP := 23;
  403.                   Minl[Trump] := 4;
  404.                 end;
  405.       open2S  : begin   { Opening 2 S, 24- ? p, 4 trumps }
  406.                   MinP := 24;
  407.                   Minl[Trump] := 4;
  408.                 end;
  409.       OpenNT  : begin                         { Opening NT }
  410.                   if Level = 1 then
  411.                     MinP := 16                { 1 NT  16-18 p }
  412.                   else
  413.                     MinP := 16 + Level*3;     { 2 NT  22-24 p }
  414.                   MaxP := MinP + 2;
  415.                   for s := Club to Spade do    { No singletons }
  416.                     Minl[s] := 2;
  417.                   if DistPoints(Player) > 1 then
  418.                     BidVal := -100;
  419.                 end;
  420.  
  421.       { Response to 1 in Suit }
  422.       Resppass : begin   { 1 He, Pass   0- 5 p }
  423.                    if EqBid(Bids[BidNo-1],Pass) then
  424.                      MaxP := 5
  425.                    else
  426.                      MaxP := 8;
  427.                  end;
  428.       resp2S   : begin   { 1 He, 2 He   6- 9 p, 4 trumps }
  429.                    MinP := 6;
  430.                    MaxP := 9;
  431.                    Minl[Trump] := 4;
  432.                  end;
  433.       resp3S   : begin   { 1 He, 3 He  13-16 p, 4 trumps }
  434.                    MinP := 13;
  435.                    MaxP := 16;
  436.                    Minl[Trump] := 4;
  437.                  end;
  438.       resp1o1  : begin   { 1 He, 1 Sp   6- ? p }
  439.                    MinP := 6;
  440.                    Minl[Trump] := 4;
  441.                  end;
  442.       resp2o1  : begin   { 1 He, 2 Cl  10- ? p }
  443.                    MinP := 10;
  444.                    Minl[Trump] := 4;
  445.                  end;
  446.       resp1NT  : begin   { 1 He, 1 NT   6- 9 p, any distribution }
  447.                    MinP := 6;
  448.                    MaxP := 9;
  449.                    BidVal := -20;
  450.                  end;
  451.       resp2NT  : begin   { 1 He, 2 NT  13-16 p, NT distribution }
  452.                    MinP := 13;
  453.                    MaxP := 16;
  454.                    for s := Club to Spade do
  455.                      Minl[s] := 2;
  456.                    if DistPoints(Player) > 1 then
  457.                      BidVal := -100;
  458.                  end;
  459.  
  460.       { Response to 2 in Suit }
  461.       resp2S2NT : begin  { 2 He, 2 NT   0- 8 p }
  462.                     MaxP := 8;
  463.                     BidVal := -20;
  464.                   end;
  465.       resp2Snorm: begin   { 2 He, anything else, an Ace and a King }
  466.                     MinP := 7;
  467.                     if (Number(Player,Ace)*2 +
  468.                        Number(Player,King) < 3) or (Jumps(Bid) >= 1) then
  469.                       BidVal := -200;
  470.                       if Trump <> NT then
  471.                         Minl[Trump] := 4;
  472.                   end;
  473.  
  474.       { Conventions }
  475.       Stayman   : begin   { Stayman  7- ? p }
  476.                     if Level = 2 then
  477.                       MinP := 7;
  478.                     if (l[Heart] <> 4) and (l[Spade] <> 4) then
  479.                       BidVal := -200
  480.                     else
  481.                       BidVal := 20;
  482.                   end;
  483.       RespStayman   : begin   { Response, He or Sp 4 trumps, otherwise Di }
  484.                         if ((Trump = NT) or
  485.                            (Level <> Bids[BidNo-2].Level)) and
  486.                            EqBid(Bids[BidNo-1],Pass) then
  487.                           BidVal := -100
  488.                         else
  489.                           if (Trump <> NT) and (Trump >= Heart) then
  490.                           begin
  491.                             Minl[Trump] := 4;
  492.                             BidVal := 10;
  493.                           end;
  494.                       end;
  495.       Blackwood     : begin   { Blackwood, not used }
  496.                         MinP := MinTab[false,Level + 2]-Info[Partner].MinP-1;
  497.                         BidVal := -200;
  498.                       end;
  499.       RespBlackwood : begin   { Response, show Number of aces or kings }
  500.                         Test := false;   BidVal := -200;
  501.                         if (Level = Bids[BidNo-2].Level + 1) then
  502.                           if Number(Player,Ace-(Level-5)) = Ord(Trump) then
  503.                             BidVal := 10;
  504.                         if Level = 0 then
  505.                           BidVal := -40;
  506.                       end;
  507.  
  508.       { Other special Bids }
  509.       resp1NT2S     : begin   { 1 NT, 2 He, 0- 6 p, odd distribution }
  510.                         MaxP := 6;
  511.                         Minl[Trump] := 6;
  512.                       end;
  513.       SecondBidNT   : begin   { 1 He, 2 Cl, 2 NT  13-15 p, 3 NT 19-21 p }
  514.                         if Level = Contract.Level then
  515.                           MaxP := 15
  516.                         else
  517.                         begin
  518.                           MinP := 19;
  519.                           MaxP := 21;
  520.                         end;
  521.                         for s := Club to Spade do
  522.                           Minl[s] := 2;
  523.                         if DistPoints(Player) > 1 then
  524.                           BidVal := -100;
  525.                       end;
  526.       Shutout       : begin   { Shut out Bid, 7 trumps, weak Hand }
  527.                         MaxP := 12;
  528.                         Minl[Trump] := 7;
  529.                         if l[Trump]-1 + Number(Player,Ace)  >= 6 + Level-2 then
  530.                           BidVal := Level
  531.                         else
  532.                            BidVal := -300;
  533.                       end;
  534.       OverCall      : begin   { Opponent OverCall, 8- ? p, 5 trumps }
  535.                         MinP := 8;
  536.                         Minl[Trump] := 5;
  537.                         if l[Trump] + p div 4  <  Level + 6 then
  538.                          BidVal := -120;
  539.                       end;
  540.  
  541.       NormPass      : NormalPass;
  542.  
  543.       NormBid       : NormalBid;
  544.  
  545.       NormDBL       : NormalDBL;
  546.  
  547.       NormRDBL,
  548.       Illegal       : begin   { Never redouble }
  549.                         BidVal := -600;
  550.                         Test := false;
  551.                       end;
  552.  
  553.     end { case };
  554.  
  555.     { Add the new information to the old }
  556.     MinP := Max(MinP,Info[Player].MinP);
  557.     MaxP := Min(MaxP,Info[Player].MaxP);
  558.     MaxP := Max(MaxP,MinP);
  559.     for s := Club to Spade do
  560.       Minl[s] := Max(Minl[s],Info[Player].Minl[s]);
  561.     case Task of
  562.       CalcInfo: Info[Player] := InfoPlayer;   { Update Info[Player] }
  563.       Evaluate: if Test then
  564.                 begin
  565.                    { Adjust BidVal according to the Test }
  566.                    Val := 0;
  567.                    { Test the Hand against Info }
  568.                    for s := Club to Spade do
  569.                      if l[s] < Minl[s] then
  570.                        Val := Val + (Minl[s]-l[s])*40;
  571.                    if p > MaxP then
  572.                      Val := Val + (p-MaxP)*12;
  573.                    if p < MinP then
  574.                      Val := Val + (MinP-p)*16;
  575.                    if Val > 0 then
  576.                      BidVal := BidVal-100-Val;
  577.                    { Try to give Partner as much information
  578.                      as possible }
  579.                    if Level > 0 then
  580.                    begin
  581.                      if Trump = NT
  582.                        then BidVal := BidVal + 11
  583.                      else
  584.                      begin
  585.                        BidVal := BidVal + (l[Trump]-
  586.                                  Info[Player].Minl[Trump])*2;
  587.                        if (Trump >= Heart) and (l[Trump] >= 5) then
  588.                          BidVal := BidVal + 1;
  589.                        for s := Succ(Trump) to Spade do
  590.                          if l[s] >= 5 then BidVal := BidVal-1;
  591.                        Len := 8-Info[Partner].Minl[Trump];
  592.                        if (Info[Player].Minl[Trump] < Len)
  593.                          and (Minl[Trump] >= Len) then
  594.                          BidVal := BidVal + 5;
  595.                      end;
  596.                      if (Level <= 3) and
  597.                         not ((Level = 3) and (Trump = NT)) then
  598.                           BidVal := BidVal + 8;
  599.                    end; { if }
  600.                    if Level > 5-Ord(Trump) div 2 then
  601.                      BidVal := BidVal + 10;
  602.                 end; { if }
  603.     end { case };
  604.   end; { with }
  605.   BidSystem := BidVal;
  606. end; { BidSystem }
  607.  
  608. procedure FindBid(var BestBid: BidType; var Restart : boolean );
  609. { Find BEST Bid for Player, either by calculating it or
  610.   by reading it from keyboard }
  611. var
  612.   Player      : HandType;
  613.   BestVal,Val : integer;
  614.   Bid         : BidType;
  615.   Bidding     : boolean;
  616. label 10;
  617.  
  618. function ErrorFound : boolean;
  619. begin
  620.   ErrorFound := false;
  621.   if not Computer[Player] then
  622.     if EqBid(BestBid,Pass) and (Pos(Command,'PASS') <> 1) then
  623.       ErrorFound := true;
  624. end; { ErrorFound }
  625.  
  626. begin
  627.   repeat
  628.     Player := (Dealer + BidNo) and 3;    { Try and Evaluate each Bid }
  629.     BestBid := Pass;   BestVal := 1;   Val := 0;
  630.     if Computer[Player] then
  631.       BestVal := BidSystem(Pass,Evaluate)
  632.     else
  633.     begin
  634.       Bidding :=  true;
  635.       Answer(Player,Command, Bidding, Restart);
  636.       if Restart then
  637.         Exit;
  638.     end;
  639.     if not EqBid(Contract,Pass) then
  640.       if odd(Player + Dummy) then
  641.       begin
  642.         if Doubled = 0 then
  643.         begin
  644.           if Computer[Player] then
  645.           begin
  646.             Val := BidSystem(Dbl,Evaluate);
  647.             if Val > BestVal then
  648.             begin
  649.               BestBid := Dbl;
  650.               BestVal := Val;
  651.             end;
  652.           end
  653.           else
  654.             if Pos(Command,'DBL') = 1 then
  655.               BestBid := Dbl;
  656.         end;
  657.       end
  658.       else
  659.         if Doubled = 1 then
  660.         begin
  661.           if Computer[Player] then
  662.           begin
  663.             Val := BidSystem(RDbl,Evaluate);
  664.             if Val > BestVal then
  665.             begin
  666.               BestBid := RDbl;
  667.               BestVal := Val;
  668.             end;
  669.           end
  670.           else
  671.             if Pos(Command,'RDBL') = 1 then
  672.               BestBid := RDbl;
  673.         end;
  674.     with Bid do
  675.     begin
  676.       Level := 7;
  677.       Trump := NT;
  678.       while not EqBid(Bid,Contract) do
  679.       begin
  680.         if Computer[Player] then
  681.         begin
  682.           Val := BidSystem(Bid,Evaluate);
  683.           if Val >= BestVal then
  684.           begin
  685.             BestBid := Bid;
  686.             BestVal := Val;
  687.           end;
  688.         end
  689.         else
  690.           if (Command = chr(Ord('0') + Level) + TrumpName[Trump][1]) then
  691.             BestBid := Bid;
  692.         if Trump <> Club then
  693.           Trump := Pred(Trump)
  694.         else
  695.         begin
  696.           Level := Level-1;
  697.           Trump := NT;
  698.         end;
  699.       end; { while }
  700.     end; { with }
  701.     { Read Bid again if last input is Illegal }
  702.     if ErrorFound then
  703.       Error(' INVALID Bid ');
  704.   until Computer[Player] or
  705.         not (EqBid(BestBid, Pass) and (Command <> 'PASS'));
  706. end; { FindBid }
  707.  
  708. procedure MakeBid(Bid: BidType);
  709. { Make the Bid and Update variables }
  710. var
  711.   i   : integer;
  712.   Val : integer;
  713. begin
  714.   Val := BidSystem(Bid,CalcInfo);   { Update Info }
  715.   Bids[BidNo] := Bid;
  716.   BidTyp[BidNo] := BidClass(Bid);
  717.   if Bid.Level > 0 then
  718.   begin
  719.     Contract := Bid;
  720.     Doubled := 0;
  721.     i := BidNo;
  722.     repeat                      { Find declarer and Dummy }
  723.       with Bids[i] do
  724.         if (Level > 0) and (Trump = Contract.Trump) then
  725.           Dummy := (Dealer + i + 2) and 3;
  726.       i := i-2;
  727.     until i < 0;
  728.   end
  729.   else
  730.     if not EqBid(Bid,Pass) then
  731.       Doubled := Succ(Doubled);
  732.   PrintBid((Dealer + BidNo) and 3,Bid);
  733.   BidNo := BidNo + 1;
  734. end; { MakeBid }
  735.  
  736. function Threepass: BOOLEAN;
  737. { Test if last three Bids were Pass }
  738. var
  739.   i : integer;
  740. begin
  741.   if BidNo < 4 then
  742.     Threepass := false
  743.   else
  744.   begin
  745.     Threepass := true;
  746.     for i := BidNo-3 to BidNo-1 do
  747.       if not EqBid(Bids[i],Pass) then
  748.         Threepass := false;
  749.   end;
  750. end; { Threepass }
  751.  
  752. function DoneBidding(var BestBid : BidType): boolean;
  753. var
  754.   Restart : boolean;
  755. begin
  756.   Restart := false;
  757.   repeat
  758.     FindBid(BestBid,Restart);
  759.     DoneBidding := not Restart;
  760.     if Restart then
  761.       Exit;
  762.     MakeBid(BestBid);
  763.   until Threepass;
  764. end; { DoneBidding }
  765.  
  766. { end BID.BR }