home *** CD-ROM | disk | FTP | other *** search
/ synchro.net / synchro.net.tar / synchro.net / main / BBS / MC.ZIP / MC3.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1988-05-06  |  18.5 KB  |  578 lines

  1. {                             Milliways Casino                               }
  2. {                  Copyright (C) 1987 by Charles Ezzell & Matthew Warner     }
  3. {                            All Rights Reserved                             }
  4. {                                                                            }
  5. {                                                                            }
  6. overlay procedure twenty_one;
  7. type
  8.   handset = array[1..12] of integer;
  9.   cards = array[1..52] of integer;
  10. var
  11.   new_hand, gameover, strangers_hand_done, player_hand_done,
  12.   strangers_blackjack, player_blackjack, dealer_blackjack,
  13.   strangers_done,      player_done,      dealer_done,
  14.   strangers_double,    player_double,
  15.   strangers_insurance, player_insurance,
  16.   strangers_busted,    player_busted,    dealer_busted : boolean;
  17.  
  18.   cardcnt,
  19.   strangers_cards, player_cards, dealer_cards,
  20.   scardval,       pcardval,     dcardval : integer;
  21.  
  22.   player_payoff,   player_amount,   player_bet,
  23.   strangers_payoff, strangers_amount, strangers_bet:real;
  24.  
  25.   min, max : integer;
  26.  
  27.   min_name, max_name, sst, st, ss : str;
  28.   cha : char;
  29.   card : cards;
  30.   strangers_hand, player_hand, dealer_hand : handset;
  31.   cvalue : array[1..13] of string[20];
  32.   csuit  : array[1..4] of string[10];
  33.  
  34. procedure twenty1_init;
  35. begin
  36.   csuit[1]:='Hearts';csuit[2]:='Diamonds';csuit[3]:='Spades';csuit[4]:='Clubs';
  37.   cvalue[1]:='Ace'; cvalue[2]:='Two'; cvalue[3]:='Three'; cvalue[4]:='Four';
  38.   cvalue[5]:='Five'; cvalue[6]:='Six'; cvalue[7]:='Seven'; cvalue[8]:='Eight';
  39.   cvalue[9]:='Nine'; cvalue[10]:='Ten'; cvalue[11]:='Jack';
  40.   cvalue[12]:='Queen'; cvalue[13]:='King';
  41.   cardcnt := 53;
  42. end;
  43.  
  44. procedure twenty1_welcome;
  45. var cha : char;
  46. begin
  47.   print('Welcome to the Blackjack Room.');
  48.   nl;
  49.   print('There are 3 empty seats around the room.'+#13+#10);
  50.   print('You notice that each of them are at different tables,');
  51.   print('each one having different betting limits.'+#13+#10);
  52.   nl;
  53.   print('Table 1 :     $10 - $500');
  54.   print('Table 2 :    $100 - $1,000');
  55.   print('Table 3 :    $500 - $10,000');
  56.   nl;
  57.   prompt('Which table do you sit at? (1-3) ');
  58.   onek(cha,'123');
  59.   case cha of
  60.     '1' : begin
  61.             min:=10; max:=500;
  62.             min_name:='$10'; max_name:='$500';
  63.           end;
  64.     '2' : begin
  65.             min:=100; max:=1000;
  66.             min_name:='$100'; max_name:='$1,000';
  67.           end;
  68.     '3' : begin
  69.             min:=500; max:=10000;
  70.             min_name:='$500'; max_name:='$10000';
  71.           end;
  72.   end;
  73. end;
  74.  
  75. procedure shuffle (var card : cards);
  76. var i, x : integer;
  77.     count : integer;
  78.     used : array[1..52] of boolean;
  79. begin
  80.   checkhangup; if hangup then leave;
  81.   prompt ('shuffling...');
  82.   for i := 1 to 52 do
  83.    used[i] := false;
  84.   count := 52;
  85.   while (count > 0) do begin
  86.     repeat
  87.       x := round(random * 52 + 0.5);
  88.     until not used[x];
  89.     card[count] := x;
  90.     used[x] := true;
  91.     count := count - 1;
  92.   end;
  93.   st := #8+#8+#8+#8+#8+#8+#8+#8+#8+#8+#8+#8;
  94.   prompt (st+'            '+st);
  95.   prompt (#13+#10+#13+#10);
  96. end;
  97.  
  98. procedure showcard (hand : handset; inhand:integer; showit:boolean);
  99. var i, j, x, y, c, s : integer;
  100.     cv : str;
  101. begin
  102.   for i := 1 to inhand do begin
  103.     checkhangup; if hangup then leave;
  104.     x := hand[i] - 1;
  105.     c := x mod 13 + 1;
  106.     s := x div 13 + 1;
  107.     if showit or (i <> 2) then begin
  108.       cv:=cvalue[c]+' of '+csuit[s]
  109.     end else begin
  110.       cv := 'HIDDEN CARD';
  111.     end;
  112.     print(cv);
  113.   end;
  114. end;
  115.  
  116. function dealcard:integer;
  117. begin
  118.   cardcnt := cardcnt + 1;
  119.   if (cardcnt > 35) and new_hand then begin
  120.     shuffle (card);
  121.     cardcnt := 1;
  122.   end;
  123.   dealcard := card[cardcnt];
  124. end;
  125.  
  126. function handvalue (hand:handset; cardcount:integer) : integer;
  127. var i, x, y, ace : integer;
  128. begin
  129.   x:=0;
  130.   ace:=0;
  131.   for i:=1 to cardcount do begin
  132.     y:=(hand[i]-1) mod 13 + 1;
  133.     if y>10 then y:=10;
  134.     if y=1 then begin
  135.       y:=11;
  136.       ace:=ace+1;
  137.     end;
  138.     x:=x+y;
  139.   end;
  140.   while (x>21) and (ace>0) do begin
  141.     x:=x-10;
  142.     ace:=ace-1;
  143.   end;
  144.   if x>21 then x:=0;
  145.   if (cardcount=2) and (x=21) then x:=22;
  146.   handvalue:=x;
  147. end;
  148.  
  149. procedure stranger_bets;
  150. var temp:str;
  151.     test, temp_max:integer;
  152. begin
  153.   strangers_bet:=0.0;
  154.   if player[0].strangers_money<min then strangers_gets_more_money;
  155.   temp_max:=max div 2;
  156.   repeat
  157.     strangers_bet:=random(temp_max);
  158.     test:=round(strangers_bet);
  159.   until (strangers_bet>min) and (test mod 100 = 0);
  160.   if random(10)+1>5 then strangers_bet:=strangers_bet+temp_max;
  161.   str(strangers_bet:0:0,temp);
  162.   temp:=format_money(temp,false);
  163.   if strangers_bet>player[0].strangers_money then strangers_gets_more_money;
  164.   print('The stranger bets '+temp+'.');
  165.   nl;pausescr;
  166. end;
  167.  
  168. procedure get_bet_21;
  169. var temp : str;
  170.     test, error: integer;
  171. begin
  172.   player_bet:=0.0;
  173.   check_winnings;
  174.   check_random;
  175.   repeat
  176.     checkhangup; if hangup then leave;
  177.     print('The dealer tells you to place your bet.');
  178.     print('('+min_name+'-'+max_name+')');
  179.     print('(0 to quit)');
  180.     print('(S for stats)');nl;
  181.     prompt('How much are you betting? ');
  182.     input(temp,6);
  183.     if (temp<>'B') and (temp<>'S') and (temp<>'0')then begin
  184.       val(temp,player_bet,error);
  185.       if (error<>0) or (player_bet<min) or (player_bet>max) then print('Illegal amount')
  186.     end else if temp='S' then player_stats;
  187.     if temp='0' then gameover:=true;
  188.     if not gameover then
  189.      if frac(player_bet/10) <> 0.0 then begin
  190.        nl;
  191.        print('The dealer looks down at you and says:');
  192.        print(thisuser.name+', all bets must be in multiples of 10.');
  193.        print('Please redo your bet.');
  194.        nl;nl;
  195.     end;
  196.   until gameover or (player_bet>=min) and (player_bet<=max)and (frac(player_bet/10)=0.0);
  197.   if not gameover then begin
  198.     temp_money := player[pn].players_money-player_bet;
  199.     if temp_money<0 then sell_to_bruno;
  200.     nl;
  201.     if not stranger_dates_kathy then stranger_bets;
  202.   end;
  203. end;
  204.  
  205. procedure deal_first_cards;
  206. begin
  207.   new_hand:=true;
  208.   if not stranger_dates_kathy then strangers_hand[1]:=dealcard;
  209.   player_hand[1]:=dealcard;
  210.   dealer_hand[1]:=dealcard;
  211.   if not stranger_dates_kathy then strangers_hand[2]:=dealcard;
  212.   player_hand[2]:=dealcard;
  213.   dealer_hand[2]:=dealcard;
  214.   if not stranger_dates_kathy then strangers_cards:=2;
  215.   dealer_cards:=2;
  216.   player_cards:=2;
  217.   new_hand:=false;
  218. end;
  219.  
  220. procedure stranger_hand;
  221. var choice:char;
  222.     test_num:integer;
  223. begin
  224.   strangers_done:=false;
  225.   strangers_payoff:=1.0;
  226.   choice:=' ';
  227.   repeat
  228.     nl;print('Strangers Hand:');
  229.     showcard(strangers_hand,strangers_cards,true);
  230.     scardval:=handvalue(strangers_hand,strangers_cards);
  231.     if (scardval>0) and (scardval<22) then begin
  232.       str(scardval,sst);
  233.       print('The stranger has: '+sst);
  234.     end;
  235.     if scardval=0 then begin
  236.       print('The stranger busted!');
  237.       strangers_hand_done:=true;
  238.       strangers_done:=true;
  239.       strangers_busted:=true;
  240.       pausescr;
  241.     end;
  242.     if choice='D' then strangers_done:=true;
  243.     if not strangers_done then begin
  244.       test_num:=random(100)+1;
  245.       if (scardval>9) and (scardval<12) and (strangers_cards=2) and
  246.        (test_num>20) then choice:='D';
  247.       if choice<>'D' then begin
  248.         case scardval of
  249.            1..11 : choice:='H';
  250.           12..14 : if test_num<50 then choice:='H' else choice:='S';
  251.           15..16 : if test_num<25 then choice:='H' else choice:='S';
  252.           17..21 : choice:='S';
  253.         end;
  254.       end;
  255.       case choice of
  256.         'H' : begin
  257.                 print('The stranger takes another card.');
  258.                 strangers_cards:=strangers_cards+1;
  259.                 strangers_hand[strangers_cards]:=dealcard;
  260.                 strangers_done:=false;
  261.               end;
  262.         'S' : begin
  263.                 str(scardval,sst);
  264.                 print('The stranger stands with '+sst+'.');
  265.                 strangers_done:=true;
  266.               end;
  267.         'D' : begin
  268.                 print('The stranger doubles his bet.');
  269.                 strangers_cards:=strangers_cards+1;
  270.                 strangers_hand[strangers_cards]:=dealcard;
  271.                 strangers_done:=false;
  272.                 strangers_payoff:=2.0;
  273.               end;
  274.       end;
  275.       pausescr;
  276.     end;
  277.   until strangers_done;
  278.   nl;
  279. end;
  280.  
  281. procedure players_hand;
  282. var test_num:integer;
  283. begin
  284.   checkhangup; if hangup then leave;
  285.   strangers_double:=false;
  286.   player_double:=false;
  287.   cha:=' ';
  288.   dcardval:=handvalue(dealer_hand,dealer_cards);
  289.   pcardval:=handvalue(player_hand,player_cards);
  290.   if not stranger_dates_kathy then
  291.    scardval:=handvalue(strangers_hand,strangers_cards)
  292.     else begin
  293.       scardval:=99;
  294.       strangers_hand_done:=true;
  295.     end;
  296.   print('Dealers Hand');
  297.   showcard(dealer_hand,dealer_cards,false);nl;
  298.   if (scardval=22) or (pcardval=22) or (((dealer_hand[1]-1) mod 13)=0) then begin
  299.     if scardval=22 then begin
  300.       print('Strangers Hand');
  301.       showcard(strangers_hand,strangers_cards,true);nl;
  302.       print('The stranger has BLACKJACK!');
  303.       strangers_hand_done:=true;
  304.       strangers_blackjack:=true;
  305.       strangers_payoff:=1.5;
  306.     end;
  307.     if not strangers_hand_done then begin
  308.       print('Strangers Hand');
  309.       showcard(strangers_hand,strangers_cards,false);nl;
  310.     end;
  311.     pausescr;
  312.     nl;
  313.     if pcardval=22 then begin
  314.       print('Your Hand');
  315.       showcard(player_hand,player_cards,true);nl;
  316.       print('You have BLACKJACK!');
  317.       player_payoff:=1.5;
  318.       player_hand_done:=true;
  319.       player_blackjack:=true;
  320.       pausescr;
  321.     end;
  322.     if (not player_hand_done) or (not strangers_hand_done) then
  323.      if ((dealer_hand[1]-1) mod 13)=0 then begin
  324.       if not player_hand_done then begin
  325.         str(pcardval,st);
  326.         print('Your Hand');
  327.         showcard(player_hand,player_cards,true);nl;
  328.         print('You have '+st);
  329.         pausescr;
  330.       end;
  331.       nl;
  332.       print('The dealer may have blackjack.');
  333.       test_num:=random(10)+1;
  334.       if (not strangers_hand_done) then
  335.        if test_num>=8 then begin
  336.          print('The stranger takes insurance.');
  337.          strangers_insurance:=true;
  338.       end else print('The stranger does not take insurance.');
  339.       nl;
  340.       if not player_hand_done then begin
  341.         prompt('Do you wish insurance? ');
  342.         onek(cha,'YN');
  343.         if cha='Y' then player_insurance:=true;
  344.       end;
  345.       if dcardval=22 then begin
  346.         nl;
  347.         print('The dealer has blackjack!');
  348.         player_hand_done:=true;
  349.         dealer_blackjack:=true;
  350.         strangers_hand_done:=true;
  351.         pausescr;
  352.       end else print('The dealer does not have blackjack.');
  353.     end;
  354.   end;
  355.   if (not strangers_hand_done) and (scardval<>99) then stranger_hand;
  356.   if not player_hand_done then begin
  357.     player_payoff:=1.0;
  358.     player_done:=false;
  359.     repeat
  360.       checkhangup; if hangup then leave;
  361.       print (#13+#10+'your hand:');
  362.       showcard (player_hand,player_cards,true);
  363.       pcardval := handvalue (player_hand,player_cards);
  364.       if (pcardval > 0) and (pcardval < 22) then begin
  365.         str (pcardval,st);
  366.         print ('You have: '+st);
  367.       end;
  368.       if pcardval=0 then begin
  369.         print('You busted!');
  370.         player_done:=true;
  371.         player_busted:=true;
  372.       end;
  373.       if cha='D' then player_done:=true;
  374.       if not player_done then begin
  375.         if (pcardval>9) and (pcardval<12) and (player_cards=2)
  376.          then player_double:=true else player_double:=false;
  377.         prompt ('H)it S)tand ');
  378.         if player_double then prompt ('D)ouble ');
  379.         prompt ('[H/S');
  380.         if player_double then prompt ('/D');
  381.         prompt ('] : ');
  382.         st := 'HS';
  383.         if player_double then st := st + 'D';
  384.         onek (cha,st);
  385.         prompt (#13+#10);
  386.         case cha of
  387.           'H' : begin
  388.                   print ('You take another card.');
  389.                   player_cards := player_cards + 1;
  390.                   player_hand[player_cards] := dealcard;
  391.                   player_done := false;
  392.                 end;
  393.           'S' : begin
  394.                   str (pcardval,st);
  395.                   print ('You stand pat with '+st+'.');
  396.                   player_done := true;
  397.                 end;
  398.           'D' : begin
  399.                   print ('You double your bet.');
  400.                   player_cards := player_cards + 1;
  401.                   player_hand[player_cards] := dealcard;
  402.                   player_done := false;
  403.                   player_payoff := 2.0;
  404.                 end;
  405.         end;
  406.       end;
  407.     until player_done;
  408.   end;
  409. end;
  410.  
  411. procedure dealers_hand;
  412. begin
  413.   dealer_done:=false;
  414.   if ((pcardval<>22) or (scardval<>22))
  415.    and ((pcardval<>0) or (scardval<>0))
  416.     and ((not player_hand_done) or (not strangers_hand_done)) then
  417.    repeat
  418.      checkhangup; if hangup then leave;
  419.      print (' ');
  420.      showcard (dealer_hand,dealer_cards,true);
  421.      dcardval := handvalue (dealer_hand,dealer_cards);
  422.      if (dcardval=0) then begin
  423.        print ('Dealer goes *** BUST ***');
  424.        dealer_done:=true;
  425.        dealer_busted:=true;
  426.      end else begin
  427.        prompt ('Dealer has ');
  428.        if dcardval=22 then st:='BLACKJACK' else str(dcardval,st);
  429.        print (st);
  430.        if (dcardval < 17) then begin
  431.          print ('dealer takes a hit.');
  432.          dealer_cards := dealer_cards + 1;
  433.          dealer_hand[dealer_cards] := dealcard;
  434.          dealer_done := false;
  435.        end else begin
  436.          print ('dealer stands pat.');
  437.          dealer_done := true;
  438.        end;
  439.      end;
  440.      pausescr;
  441.    until dealer_done;
  442.    nl;
  443. end;
  444.  
  445. procedure process_hands;
  446. var player_won,strangers_won,player_push,strangers_push:boolean;
  447. begin
  448.   checkhangup; if hangup then leave;
  449.   player_won:=false;strangers_won:=false;
  450.   player_push:=false;strangers_push:=false;
  451.  
  452.   {look for winning hands}
  453.   if (pcardval>dcardval) or player_blackjack then player_won:=true;
  454.   if scardval<>99 then
  455.    if (scardval>dcardval) or strangers_blackjack then strangers_won:=true;
  456.  
  457.   { PROCESS STRANGERS HAND }
  458.   if not stranger_dates_kathy then
  459.    if strangers_won then begin
  460.     print('The stranger wins his hand!');
  461.     if strangers_insurance then begin
  462.       print('However, he losses his insurance money.');
  463.       strangers_payoff:=strangers_payoff-0.5;
  464.     end;
  465.   end else begin
  466.     if (scardval=dcardval) and not strangers_blackjack
  467.      and not strangers_busted then strangers_push:=true;
  468.     if strangers_push then begin
  469.       print('The stranger and dealers hands push.');
  470.       if strangers_insurance then begin
  471.         print('However, he losses his insurance money.');
  472.         strangers_payoff:=-0.5;
  473.       end else strangers_payoff:=0.0;
  474.     end else begin
  475.       print('The stranger loses.');
  476.       strangers_payoff:=-strangers_payoff;
  477.       if dealer_blackjack and strangers_insurance then begin
  478.         print('The stranger''s insurance protects him from blackjack,');
  479.         print('but he loses his insurance money.');
  480.         strangers_payoff:=strangers_payoff+0.5;
  481.       end else if (not dealer_blackjack) and player_insurance then begin
  482.         print('The stranger loses both his bet and insurance.');
  483.         strangers_payoff:=strangers_payoff-0.5;
  484.       end;
  485.     end;
  486.   end;
  487.  
  488.   { PROCESS PLAYER'S HAND }
  489.   if player_won then begin
  490.     print ('You win your hand!');
  491.     if player_insurance then begin
  492.       print('However, you lose your insurance money.');
  493.       player_payoff:=player_payoff-0.5;
  494.     end;
  495.   end else begin
  496.     if (pcardval=dcardval) and not player_blackjack
  497.      and not player_busted then player_push:=true;
  498.     if player_push then begin
  499.       print ('Your Hands push. No win or loss.');
  500.       if player_insurance then begin
  501.         print('However, you lose your insurance money.');
  502.         player_payoff:=-0.5;
  503.       end else player_payoff:=0.0;
  504.     end else begin
  505.       print ('You lose.');
  506.       player_payoff := -player_payoff;
  507.       if dealer_blackjack and player_insurance then begin
  508.         print ('Insurance protects you from blackjack.');
  509.         print ('(You lose your insurance money though.)');
  510.         player_payoff:=player_payoff+0.5;
  511.       end else if (not dealer_blackjack) and player_insurance then begin
  512.         print('You lose your bet and insurance');
  513.         player_payoff:=player_payoff-0.5;
  514.       end;
  515.     end;
  516.   end;
  517.   player_amount := player_bet * player_payoff;
  518.   player[pn].players_money:=player[pn].players_money + player_amount;
  519.   player[pn].won_today:=player[pn].won_today+player_amount;
  520.   str (abs(player_amount):0:0,st);st:=format_money(st,false);
  521.   if not stranger_dates_kathy then begin
  522.     strangers_amount:=strangers_bet*strangers_payoff;
  523.     player[0].strangers_money:=player[0].strangers_money+strangers_amount;
  524.     str(abs(strangers_amount):0:0,sst);sst:=format_money(sst,false);
  525.     if strangers_amount<>0.0 then begin
  526.       prompt(sst);
  527.       if strangers_amount>0.0 then prompt(' added to') else prompt(' subtracted from');
  528.       print(' the strangers bankroll.');
  529.     end;
  530.   end;
  531.   if player_amount <> 0.0 then begin
  532.     prompt (st);
  533.     if player_amount > 0.0 then prompt (' added to') else prompt (' subtracted from');
  534.     print (' your bankroll.');
  535.     nl;
  536.   end;
  537.   if player_amount>0 then player[0].jackpot:=player[0].jackpot-player_amount*0.05
  538.    else player[0].jackpot:=player[0].jackpot+player_bet* 0.10;
  539.   pausescr;
  540. end;
  541.  
  542. begin
  543.   checkhangup; if hangup then leave;
  544.   twenty1_init;
  545.   twenty1_welcome;
  546.   gameover := false;
  547.   prompt('You take your seat');
  548.   if not stranger_dates_kathy then begin
  549.     print(', and notice');
  550.     print('the stranger sitting to your right');
  551.     print('surrounded by his girls.');
  552.   end else print('.');
  553.   repeat
  554.     tleft;
  555.     player_payoff:=1.0;strangers_payoff:=1.0;
  556.     player_insurance:=false;strangers_insurance:=false;
  557.     player_done:=false;strangers_done:=false;
  558.     player_hand_done:=false;strangers_hand_done:=false;
  559.     strangers_blackjack:=false; dealer_blackjack:=false; player_blackjack:=false;
  560.     strangers_busted:=false; dealer_busted:=false; player_busted:=false;
  561.     checkhangup; if hangup then leave;
  562.     if player[pn].bruno>0 then buy_from_bruno;
  563.     str(player[pn].players_money:0:0,st);str(player[0].strangers_money:0:0,sst);
  564.     st:=format_money(st,false);sst:=format_money(sst,false);
  565.     nl;
  566.     if not stranger_dates_kathy then print('The stranger has '+sst+'.');
  567.     print('You have '+st+'.');
  568.     checkhangup; if hangup then leave;
  569.     get_bet_21;
  570.     if not gameover then begin
  571.       deal_first_cards;
  572.       players_hand;
  573.       dealers_hand;
  574.       process_hands;
  575.     end;
  576.   until gameover or hangup
  577. end; {end twenty_one}
  578.