1 /*
2  * (c) Copyright 1997, Qun Zhang.
3  *
4  * Permission to use, copy, modify, distribute, and sell this software
5  * and its documentation for any purpose is hereby granted without fee,
6  * provided that the above copyright notice appear in all copies and
7  * that both that copyright notice and this permission notice appear in
8  * supporting documentation, and that the name of Qun Zhang not be used
9  * in advertising or publicity pertaining to distribution of the software
10  * without specific, written prior permission.  Qun Zhang make no
11  * representations about the suitability of this software for any purpose.
12  * It is provided "as is" without express or implied warranty.
13  *
14  * THE ABOVE-NAMED DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16  * EVENT SHALL THE ABOVE-NAMED 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  */
23 
24 #include "stdlib.h"
25 #include <iostream>
26 #include "Card.h"
27 #include "Deck.h"
28 #include "Dealer.h"
29 #include "Player.h"
30 
31 using namespace std;
32 
Dealer(Seat * dealerSeat)33 Dealer::Dealer( Seat * dealerSeat ) : _seat(dealerSeat), _current(0)
34 {
35    _minjackPot = 2000000;
36 
37    for(int i=0; i<10; i++)
38 		_players[i] = (Player*) 0;
39 }
CollectAnte() const40 void Dealer::CollectAnte() const
41 {
42    int ante;
43 
44 	for(int i=0; _players[i]; i++)
45    {
46 		cout << endl << "Progressive ? 0/1" << endl;
47 		cin >> ante;
48 		_players[i]->Progressive(ante);
49 		cout << "Bet Ante: " << endl; // need to be replaced by GUI
50 		cin >> ante;
51 		try{
52 		   _players[i]->Ante(ante);
53 		}
54 		catch (const char *mess)
55 		{
56 			cout << mess << endl;
57 		}
58 	}
59 }
60 
DealCards()61 void Dealer::DealCards()
62 {
63 	Card *card;
64 
65    for(int j=0; j< 5; j++)
66 	{
67 		for(int i=0; _players[i]; i++)
68 			_players[i]->AddCard(_deck->GetCard());
69 		card =_deck->GetCard();
70 #ifdef DEBUG
71 		if( j == 4 ) card->ShowFront();
72 		else card->ShowBack();
73 #endif
74 		AddCard(card);
75   	}
76 }
77 
AskBet() const78 void Dealer::AskBet() const
79 {
80 	Card ** hand;
81 	char    v;
82 
83 	for(int i=0; _players[i]; i++)
84 	{
85 		hand = _players[i]->Cards();
86 		for(int j=0; j < 5; j++)
87 			hand[j]->ShowFront();
88 		cout << "Bet ? : Y/N ";
89 		cin >> v;
90 		if(v == 'Y' || v == 'y') _players[i]->Bet(10);
91       else _players[i]->Fold();
92 	}
93 }
94 
CollectBet() const95 void Dealer::CollectBet() const
96 {
97 	Card ** hand = Cards();
98 
99 	for(int j=0; j < 5; j++)
100 		hand[j]->ShowFront();
101 	cout << endl;
102 
103 	if(Score() < 573496) // Does not have a King/Ace or higher
104    {
105 #ifdef DEBUG
106 		cout << "Dealer does not have a ACE/KING or higher." << endl;
107 #endif
108 		for(int i=0; _players[i]; i++)
109 		{
110 			(_players[i]->Score()) ?  // see if the player has folded.
111 				_players[i]->Pay(_players[i]->Ante()):
112 				_players[i]->Pay(- _players[i]->Ante());
113 			_players[i]->NewGame();
114 		}
115 	}
116 	else{ // Pay based on Hands
117 		int amount;
118 		for(int i=0; _players[i]; i++)
119 		{
120 			if(_players[i]->Score() < Score())
121 			{
122 				amount = _players[i]->Ante() + _players[i]->Bet();
123 				amount = -amount;
124 			}
125 			else if (_players[i]->Score() == Score())
126 			{
127 				amount = 0;
128 			}
129 			else{
130 				amount =  _players[i]->Ante() +
131 					       _players[i]->Bet()*_players[i]->PayRate();
132 #ifdef DEBUG
133 				cout << "Ante: " << _players[i]->Ante() <<endl;
134 				cout << "PayRate: " << _players[i]->PayRate() <<endl;
135 				cout << "TotalPay: " << amount <<endl;
136 #endif
137 			}
138 			_players[i]->Pay(amount);
139 			_players[i]->NewGame();
140 		}
141 	}
142 }
143 
NewGame()144 void Dealer::NewGame()
145 {
146 	int i;
147 	for(i=0; _players[i]; i++)
148 		_players[i]->NewGame();
149 
150 	Hands::NewGame();
151 
152    srand(time(0));
153    long pot = rand()%1000000;
154 
155    _jackPot += (rand()%1) ? pot : -pot;
156    _jackPot = ( _jackPot > _minjackPot) ?  _jackPot : _minjackPot;
157 
158 	if(_deck->CardsLeft() < i*5+10)
159 	{
160 		_deck->Shuffle();
161 		_deck->Cut();
162 		_deck->Cut();
163 	}
164 
165    _current = 0;
166 }
167 
168