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 #ifndef Dealer_h
25 #define Dealer_h 1
26 #include <assert.h>
27 
28 
29 #include "Hands.h"
30 
31 class Player;
32 class Deck;
33 class Seat;
34 
35 
36 class Dealer : public Hands
37 {
38 
39   public:
40       Dealer( Seat * dealerSeat );
~Dealer()41       ~Dealer() {};
42 
43       void CollectAnte	() const;
44       void DealCards		() ;
45       void AskBet			() const;
46       void CollectBet	() const;
47       void NewGame		() ;
48 		long JackPot      () const;
49 		void JackPot      (long);
50 		void MinJackPot   (long);
51       void Add    (Player *) ;
52       void Remove (Player *) ;
53 		Deck* GetDeck () const;
54 		void  SetDeck (Deck*);
55 		Seat* GetSeat () const;
CurrentPlayer()56 		Player* CurrentPlayer() { return _players[_current]; }
FirstPlayer()57 		Player* FirstPlayer() { _current = 0; return _players[_current]; }
58 		Player* NextPlayer();
CurrentSpot()59 		int	CurrentSpot()  { return _current + 1; }
60   protected:
61 
62 
63   private:
64       Dealer(const Dealer &right);
65       const Dealer & operator=(const Dealer &right);
66       int operator==(const Dealer &right) const;
67       int operator!=(const Dealer &right) const;
68 
69   private:
70       Deck *   _deck;
71       Seat *   _seat;
72 		long     _jackPot;
73 		long     _minjackPot;
74       Player * _players[10];
75 		int      _current;
76 };
77 
JackPot()78 inline long Dealer::JackPot() const
79 {
80 	return _jackPot;
81 }
82 
MinJackPot(long jackpot)83 inline void Dealer::MinJackPot(long jackpot)
84 {
85 	 _minjackPot = jackpot;
86 }
87 
JackPot(long jackpot)88 inline void Dealer::JackPot(long jackpot)
89 {
90 	 _jackPot = jackpot;
91 }
92 
Add(Player * newPlayer)93 inline void Dealer::Add    (Player* newPlayer)
94 {
95    int i;
96    for(i=0; i < 10; i++)
97       if( !_players[i] ){
98 			_players[i] = newPlayer;
99          break;
100       }
101    if(i == 10) throw (" Can not add more player. ");
102 }
103 
Remove(Player * aplayer)104 inline void Dealer::Remove (Player* aplayer)
105 {
106    int pos = 20, i;
107 	for(i=0; _players[i]; i++)
108 		if(aplayer == _players[i])
109 		{
110 			pos = i; break;
111 		}
112 
113    if(pos >= 10) throw ("Player not in dealer list. ");
114 	for(i=9; !_players[i]; i--);
115    _players[pos] = _players[i];
116    _players[i] = (Player *) 0 ;
117 }
118 
GetDeck()119 inline Deck* Dealer::GetDeck () const
120 {
121 	return _deck;
122 }
123 
SetDeck(Deck * deck)124 inline void  Dealer::SetDeck (Deck* deck)
125 {
126 	assert(deck);
127 	_deck = deck;
128 }
129 
GetSeat()130 inline Seat*   Dealer::GetSeat () const
131 {
132 	return _seat;
133 }
134 
NextPlayer()135 inline Player* Dealer::NextPlayer()
136 {
137 	if(_players[_current+1])
138 		return _players[++_current];
139 
140 	return (Player*) 0;
141 }
142 
143 #endif
144 
145 
146