View Javadoc

1   //  Open Hold em is a java-based, server and client environment for hosting 
2   //  your own texas hold poker tournaments, and regular tables. It is full 
3   //  customizable and deployable in a number of different java-based hosting 
4   //  environments.
5   //  Copyright (C) 2005 Chris A. Mattmann <chris@baron.pagemewhen.com>
6   //
7   //  This program is free software; you can redistribute it and/or modify
8   //  it under the terms of the GNU General Public License as published by
9   //  the Free Software Foundation; either version 2 of the License, or
10  //  (at your option) any later version.
11  //
12  //  This program is distributed in the hope that it will be useful,
13  //  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  //  GNU General Public License for more details.
16  //
17  //  You should have received a copy of the GNU General Public License
18  //  along with this program; if not, write to the Free Software
19  //  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
20  //
21  //  $Id: RuleSet.java,v 1.2 2005/08/07 02:48:35 mattmann Exp $
22  
23  package com.openholdem.structs;
24  
25  import java.util.SortedSet;
26  import java.util.TreeSet;
27  
28  /***
29   * @author mattmann
30   * @version $Revision: 1.2 $
31   * 
32   * <p>A set of rules that define a poker game instance.</p>
33   * 
34   */
35  public class RuleSet {
36  
37      /* the name of the poker game we're playing */
38      private String fGameName = null;
39      
40      /* the number of cards a player holds in her hand */
41      private int fNumPlayerCards = -1;
42      
43      private int fMinHandCardsUsed = -1;
44      
45      private int fMaxHandCardsUsed = -1;
46      
47      private int fNumCommunityCards = -1;
48      
49      private SortedSet fHandRanks = null;
50      
51      
52      /***
53       * <p>Construct a new Rule Set with default parameters</p>
54       */
55      public RuleSet() {
56          fHandRanks = new TreeSet();
57      }
58      
59      public RuleSet(int npCards, int minCards, int maxCards, int nComm, SortedSet ranks){
60          fNumPlayerCards = npCards;
61          fMinHandCardsUsed = minCards;
62          fMaxHandCardsUsed = maxCards;
63          fNumCommunityCards = nComm;
64          fHandRanks = ranks;
65      }
66      
67      
68      
69      public class HandRank implements Comparable{
70          private int fRank = -1;
71          private String fHandName = null;
72          
73          public HandRank(){
74              
75          }
76          
77          public int hashCode(){
78              return fRank;
79          }
80          
81          public boolean equals(Object o){
82              return (this.compareTo(o) == 0);
83          }
84          
85          public HandRank(int rank,String name){
86              fRank = rank;
87              fHandName = name;
88          }
89          
90          public String toString(){
91              StringBuffer rStr = new StringBuffer();
92              rStr.append("["+fHandName+","+fRank+"]");
93              
94              return rStr.toString();
95          }
96  
97          public int compareTo(Object o){
98              int compareVal = -1;
99              
100             HandRank otherRank = (HandRank)o;
101             
102             //lower the rank, higher the card
103             if(otherRank.getFRank() > this.fRank){
104                 compareVal = -1;
105             }
106             else if(otherRank.getFRank() < this.fRank){
107                 compareVal = 1;
108             }
109             else if(otherRank.getFRank() == this.fRank){
110                 compareVal = 0;
111             }
112             
113             return compareVal;
114         }
115         
116         /***
117          * @return Returns the fHandName.
118          */
119         public String getFHandName() {
120             return fHandName;
121         }
122 
123         /***
124          * @param handName The fHandName to set.
125          */
126         public void setFHandName(String handName) {
127             fHandName = handName;
128         }
129 
130         /***
131          * @return Returns the fRank.
132          */
133         public int getFRank() {
134             return fRank;
135         }
136 
137         /***
138          * @param rank The fRank to set.
139          */
140         public void setFRank(int rank) {
141             fRank = rank;
142         }
143         
144         
145     }
146 
147     /***
148      * @return Returns the fGameName.
149      */
150     public String getFGameName() {
151         return fGameName;
152     }
153 
154     /***
155      * @param gameName The fGameName to set.
156      */
157     public void setFGameName(String gameName) {
158         fGameName = gameName;
159     }
160 
161     /***
162      * @return Returns the fMaxHandCardsUsed.
163      */
164     public int getFMaxHandCardsUsed() {
165         return fMaxHandCardsUsed;
166     }
167 
168     /***
169      * @param maxHandCardsUsed The fMaxHandCardsUsed to set.
170      */
171     public void setFMaxHandCardsUsed(int maxHandCardsUsed) {
172         fMaxHandCardsUsed = maxHandCardsUsed;
173     }
174 
175     /***
176      * @return Returns the fMinHandCardsUsed.
177      */
178     public int getFMinHandCardsUsed() {
179         return fMinHandCardsUsed;
180     }
181 
182     /***
183      * @param minHandCardsUsed The fMinHandCardsUsed to set.
184      */
185     public void setFMinHandCardsUsed(int minHandCardsUsed) {
186         fMinHandCardsUsed = minHandCardsUsed;
187     }
188 
189     /***
190      * @return Returns the fNumCommunityCards.
191      */
192     public int getFNumCommunityCards() {
193         return fNumCommunityCards;
194     }
195 
196     /***
197      * @param numCommunityCards The fNumCommunityCards to set.
198      */
199     public void setFNumCommunityCards(int numCommunityCards) {
200         fNumCommunityCards = numCommunityCards;
201     }
202 
203     /***
204      * @return Returns the fNumPlayerCards.
205      */
206     public int getFNumPlayerCards() {
207         return fNumPlayerCards;
208     }
209 
210     /***
211      * @param numPlayerCards The fNumPlayerCards to set.
212      */
213     public void setFNumPlayerCards(int numPlayerCards) {
214         fNumPlayerCards = numPlayerCards;
215     }
216 
217     /***
218      * @return Returns the fHandRanks.
219      */
220     public SortedSet getFHandRanks() {
221         return fHandRanks;
222     }
223 
224     /***
225      * @param handRanks The fHandRanks to set.
226      */
227     public void setFHandRanks(SortedSet handRanks) {
228         fHandRanks = handRanks;
229     }
230 
231 }