Browse Source

Initial import


git-svn-id: http://chris.smith.name/svn/japoker/trunk@1 b8598caf-53df-4c1b-98b8-507a84a220
tags/v12
Chris Smith 16 years ago
commit
7e71af5755
100 changed files with 5832 additions and 0 deletions
  1. 69
    0
      build.xml
  2. 33
    0
      dist/README.TXT
  3. 31
    0
      dist/readme.txt
  4. 3
    0
      manifest.mf
  5. 627
    0
      nbproject/build-impl.xml
  6. 8
    0
      nbproject/genfiles.properties
  7. 0
    0
      nbproject/private/config.properties
  8. 4
    0
      nbproject/private/private.properties
  9. 4
    0
      nbproject/private/private.xml
  10. 63
    0
      nbproject/project.properties
  11. 17
    0
      nbproject/project.xml
  12. 31
    0
      src/com/md87/cardgame/Achievement.java
  13. 124
    0
      src/com/md87/cardgame/Card.java
  14. 140
    0
      src/com/md87/cardgame/Deck.java
  15. 29
    0
      src/com/md87/cardgame/Main.java
  16. 176
    0
      src/com/md87/cardgame/Player.java
  17. 103
    0
      src/com/md87/cardgame/RaiseWindow.java
  18. 73
    0
      src/com/md87/cardgame/Rank.java
  19. 22
    0
      src/com/md87/cardgame/Suit.java
  20. 127
    0
      src/com/md87/cardgame/config/BettingPanel.java
  21. 128
    0
      src/com/md87/cardgame/config/ConfigScreen.java
  22. 80
    0
      src/com/md87/cardgame/config/GamePanel.java
  23. 139
    0
      src/com/md87/cardgame/config/PlayerPanel.java
  24. 32
    0
      src/com/md87/cardgame/config/controllers/ConservativeOpenerInfo.java
  25. 37
    0
      src/com/md87/cardgame/config/controllers/ControllerInfo.java
  26. 32
    0
      src/com/md87/cardgame/config/controllers/EndGameInfo.java
  27. 32
    0
      src/com/md87/cardgame/config/controllers/HumanPlayerInfo.java
  28. 32
    0
      src/com/md87/cardgame/config/controllers/RandomPlayerInfo.java
  29. 39
    0
      src/com/md87/cardgame/config/games/AsianFiveCardStudInfo.java
  30. 39
    0
      src/com/md87/cardgame/config/games/CourchevelInfo.java
  31. 39
    0
      src/com/md87/cardgame/config/games/CrazyPineappleInfo.java
  32. 44
    0
      src/com/md87/cardgame/config/games/FiveCardDrawInfo.java
  33. 39
    0
      src/com/md87/cardgame/config/games/FiveCardStudInfo.java
  34. 52
    0
      src/com/md87/cardgame/config/games/GameInfo.java
  35. 39
    0
      src/com/md87/cardgame/config/games/OmahaHighLowInfo.java
  36. 39
    0
      src/com/md87/cardgame/config/games/OmahaHoldEmInfo.java
  37. 39
    0
      src/com/md87/cardgame/config/games/PineappleInfo.java
  38. 39
    0
      src/com/md87/cardgame/config/games/RoyalHoldEmInfo.java
  39. 39
    0
      src/com/md87/cardgame/config/games/SevenCardStudInfo.java
  40. 39
    0
      src/com/md87/cardgame/config/games/SuperHoldEmInfo.java
  41. 39
    0
      src/com/md87/cardgame/config/games/TexasHoldEmInfo.java
  42. 33
    0
      src/com/md87/cardgame/controllers/ConservativeOpener.java
  43. 182
    0
      src/com/md87/cardgame/controllers/EndGameAI.java
  44. 232
    0
      src/com/md87/cardgame/controllers/HumanPlayer.java
  45. 160
    0
      src/com/md87/cardgame/controllers/NetworkPlayer.java
  46. 72
    0
      src/com/md87/cardgame/controllers/RandomPlayer.java
  47. 757
    0
      src/com/md87/cardgame/games/AbstractGame.java
  48. 41
    0
      src/com/md87/cardgame/games/AsianFiveCardStud.java
  49. 38
    0
      src/com/md87/cardgame/games/Courchevel.java
  50. 92
    0
      src/com/md87/cardgame/games/CrazyPineapple.java
  51. 77
    0
      src/com/md87/cardgame/games/FiveCardDraw.java
  52. 86
    0
      src/com/md87/cardgame/games/FiveCardStud.java
  53. 132
    0
      src/com/md87/cardgame/games/OmahaHighLow.java
  54. 132
    0
      src/com/md87/cardgame/games/OmahaHoldEm.java
  55. 35
    0
      src/com/md87/cardgame/games/Pineapple.java
  56. 54
    0
      src/com/md87/cardgame/games/RoyalHoldEm.java
  57. 100
    0
      src/com/md87/cardgame/games/SevenCardStud.java
  58. 33
    0
      src/com/md87/cardgame/games/SuperHoldEm.java
  59. 116
    0
      src/com/md87/cardgame/games/TexasHoldEm.java
  60. 222
    0
      src/com/md87/cardgame/hands/AbstractHand.java
  61. 87
    0
      src/com/md87/cardgame/hands/AceFiveLowHand.java
  62. 127
    0
      src/com/md87/cardgame/hands/StandardHand.java
  63. 145
    0
      src/com/md87/cardgame/interfaces/Game.java
  64. 53
    0
      src/com/md87/cardgame/interfaces/GameObserver.java
  65. 22
    0
      src/com/md87/cardgame/interfaces/Hand.java
  66. 83
    0
      src/com/md87/cardgame/interfaces/PlayerController.java
  67. BIN
      src/com/md87/cardgame/res/Thumbs.db
  68. BIN
      src/com/md87/cardgame/res/back1.png
  69. BIN
      src/com/md87/cardgame/res/back2.png
  70. BIN
      src/com/md87/cardgame/res/cace.png
  71. BIN
      src/com/md87/cardgame/res/cdeuce.png
  72. BIN
      src/com/md87/cardgame/res/ceight.png
  73. BIN
      src/com/md87/cardgame/res/cfive.png
  74. BIN
      src/com/md87/cardgame/res/cfour.png
  75. BIN
      src/com/md87/cardgame/res/chip.pdn
  76. BIN
      src/com/md87/cardgame/res/chip1.png
  77. BIN
      src/com/md87/cardgame/res/cjack.png
  78. BIN
      src/com/md87/cardgame/res/cking.png
  79. BIN
      src/com/md87/cardgame/res/cnine.png
  80. BIN
      src/com/md87/cardgame/res/cqueen.png
  81. BIN
      src/com/md87/cardgame/res/cseven.png
  82. BIN
      src/com/md87/cardgame/res/csix.png
  83. BIN
      src/com/md87/cardgame/res/cten.png
  84. BIN
      src/com/md87/cardgame/res/cthree.png
  85. BIN
      src/com/md87/cardgame/res/dace.png
  86. BIN
      src/com/md87/cardgame/res/ddeuce.png
  87. BIN
      src/com/md87/cardgame/res/deight.png
  88. BIN
      src/com/md87/cardgame/res/dfive.png
  89. BIN
      src/com/md87/cardgame/res/dfour.png
  90. BIN
      src/com/md87/cardgame/res/djack.png
  91. BIN
      src/com/md87/cardgame/res/dking.png
  92. BIN
      src/com/md87/cardgame/res/dnine.png
  93. BIN
      src/com/md87/cardgame/res/dqueen.png
  94. BIN
      src/com/md87/cardgame/res/dseven.png
  95. BIN
      src/com/md87/cardgame/res/dsix.png
  96. BIN
      src/com/md87/cardgame/res/dten.png
  97. BIN
      src/com/md87/cardgame/res/dthree.png
  98. BIN
      src/com/md87/cardgame/res/hace.png
  99. BIN
      src/com/md87/cardgame/res/hdeuce.png
  100. 0
    0
      src/com/md87/cardgame/res/height.png

+ 69
- 0
build.xml View File

@@ -0,0 +1,69 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<!-- You may freely edit this file. See commented blocks below for -->
3
+<!-- some examples of how to customize the build. -->
4
+<!-- (If you delete it and reopen the project it will be recreated.) -->
5
+<project name="CardGame" default="default" basedir=".">
6
+    <description>Builds, tests, and runs the project CardGame.</description>
7
+    <import file="nbproject/build-impl.xml"/>
8
+    <!--
9
+
10
+    There exist several targets which are by default empty and which can be 
11
+    used for execution of your tasks. These targets are usually executed 
12
+    before and after some main targets. They are: 
13
+
14
+      -pre-init:                 called before initialization of project properties
15
+      -post-init:                called after initialization of project properties
16
+      -pre-compile:              called before javac compilation
17
+      -post-compile:             called after javac compilation
18
+      -pre-compile-single:       called before javac compilation of single file
19
+      -post-compile-single:      called after javac compilation of single file
20
+      -pre-compile-test:         called before javac compilation of JUnit tests
21
+      -post-compile-test:        called after javac compilation of JUnit tests
22
+      -pre-compile-test-single:  called before javac compilation of single JUnit test
23
+      -post-compile-test-single: called after javac compilation of single JUunit test
24
+      -pre-jar:                  called before JAR building
25
+      -post-jar:                 called after JAR building
26
+      -post-clean:               called after cleaning build products
27
+
28
+    (Targets beginning with '-' are not intended to be called on their own.)
29
+
30
+    Example of inserting an obfuscator after compilation could look like this:
31
+
32
+        <target name="-post-compile">
33
+            <obfuscate>
34
+                <fileset dir="${build.classes.dir}"/>
35
+            </obfuscate>
36
+        </target>
37
+
38
+    For list of available properties check the imported 
39
+    nbproject/build-impl.xml file. 
40
+
41
+
42
+    Another way to customize the build is by overriding existing main targets.
43
+    The targets of interest are: 
44
+
45
+      -init-macrodef-javac:     defines macro for javac compilation
46
+      -init-macrodef-junit:     defines macro for junit execution
47
+      -init-macrodef-debug:     defines macro for class debugging
48
+      -init-macrodef-java:      defines macro for class execution
49
+      -do-jar-with-manifest:    JAR building (if you are using a manifest)
50
+      -do-jar-without-manifest: JAR building (if you are not using a manifest)
51
+      run:                      execution of project 
52
+      -javadoc-build:           Javadoc generation
53
+      test-report:              JUnit report generation
54
+
55
+    An example of overriding the target for project execution could look like this:
56
+
57
+        <target name="run" depends="CardGame-impl.jar">
58
+            <exec dir="bin" executable="launcher.exe">
59
+                <arg file="${dist.jar}"/>
60
+            </exec>
61
+        </target>
62
+
63
+    Notice that the overridden target depends on the jar target and not only on 
64
+    the compile target as the regular run target does. Again, for a list of available 
65
+    properties which you can use, check the target you are overriding in the
66
+    nbproject/build-impl.xml file. 
67
+
68
+    -->
69
+</project>

+ 33
- 0
dist/README.TXT View File

@@ -0,0 +1,33 @@
1
+========================
2
+BUILD OUTPUT DESCRIPTION
3
+========================
4
+
5
+When you build an Java application project that has a main class, the IDE
6
+automatically copies all of the JAR
7
+files on the projects classpath to your projects dist/lib folder. The IDE
8
+also adds each of the JAR files to the Class-Path element in the application
9
+JAR files manifest file (MANIFEST.MF).
10
+
11
+To run the project from the command line, go to the dist folder and
12
+type the following:
13
+
14
+java -jar "CardGame.jar" 
15
+
16
+To distribute this project, zip up the dist folder (including the lib folder)
17
+and distribute the ZIP file.
18
+
19
+Notes:
20
+
21
+* If two JAR files on the project classpath have the same name, only the first
22
+JAR file is copied to the lib folder.
23
+* Only JAR files are copied to the lib folder.
24
+If the classpath contains other types of files or folders, none of the
25
+classpath elements are copied to the lib folder. In such a case,
26
+you need to copy the classpath elements to the lib folder manually after the build.
27
+* If a library on the projects classpath also has a Class-Path element
28
+specified in the manifest,the content of the Class-Path element has to be on
29
+the projects runtime path.
30
+* To set a main class in a standard Java project, right-click the project node
31
+in the Projects window and choose Properties. Then click Run and enter the
32
+class name in the Main Class field. Alternatively, you can manually type the
33
+class name in the manifest Main-Class element.

+ 31
- 0
dist/readme.txt View File

@@ -0,0 +1,31 @@
1
+========================
2
+BUILD OUTPUT DESCRIPTION
3
+========================
4
+
5
+When you build an Java application project that has a main class, the IDE
6
+automatically copies all of the JAR
7
+files on the projects classpath to your projects dist/lib folder. The IDE
8
+also adds each of the JAR files to the Class-Path element in the application
9
+JAR files manifest file (MANIFEST.MF).
10
+
11
+To run the project from the command line, go to the dist folder and
12
+type the following:
13
+
14
+java -jar "CardGame.jar" 
15
+
16
+To distribute this project, zip up the dist folder (including the lib folder)
17
+and distribute the ZIP file.
18
+
19
+Notes:
20
+
21
+* If two JAR files on the project classpath have the same name, only the first
22
+JAR file is copied to the lib folder.
23
+* If the classpath contains a folder of classes or resources, none of the
24
+classpath elements are copied to the dist folder.
25
+* If a library on the projects classpath also has a Class-Path element
26
+specified in the manifest,the content of the Class-Path element has to be on
27
+the projects runtime path.
28
+* To set a main class in a standard Java project, right-click the project node
29
+in the Projects window and choose Properties. Then click Run and enter the
30
+class name in the Main Class field. Alternatively, you can manually type the
31
+class name in the manifest Main-Class element.

+ 3
- 0
manifest.mf View File

@@ -0,0 +1,3 @@
1
+Manifest-Version: 1.0
2
+X-COMMENT: Main-Class will be added automatically by build
3
+

+ 627
- 0
nbproject/build-impl.xml View File

@@ -0,0 +1,627 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<!--
3
+*** GENERATED FROM project.xml - DO NOT EDIT  ***
4
+***         EDIT ../build.xml INSTEAD         ***
5
+
6
+For the purpose of easier reading the script
7
+is divided into following sections:
8
+
9
+  - initialization
10
+  - compilation
11
+  - jar
12
+  - execution
13
+  - debugging
14
+  - javadoc
15
+  - junit compilation
16
+  - junit execution
17
+  - junit debugging
18
+  - applet
19
+  - cleanup
20
+
21
+        -->
22
+<project xmlns:j2seproject1="http://www.netbeans.org/ns/j2se-project/1" xmlns:j2seproject2="http://www.netbeans.org/ns/j2se-project/2" xmlns:j2seproject3="http://www.netbeans.org/ns/j2se-project/3" xmlns:jaxrpc="http://www.netbeans.org/ns/j2se-project/jax-rpc" basedir=".." default="default" name="CardGame-impl">
23
+    <target depends="test,jar,javadoc" description="Build and test whole project." name="default"/>
24
+    <!-- 
25
+                ======================
26
+                INITIALIZATION SECTION 
27
+                ======================
28
+            -->
29
+    <target name="-pre-init">
30
+        <!-- Empty placeholder for easier customization. -->
31
+        <!-- You can override this target in the ../build.xml file. -->
32
+    </target>
33
+    <target depends="-pre-init" name="-init-private">
34
+        <property file="nbproject/private/config.properties"/>
35
+        <property file="nbproject/private/configs/${config}.properties"/>
36
+        <property file="nbproject/private/private.properties"/>
37
+    </target>
38
+    <target depends="-pre-init,-init-private" name="-init-user">
39
+        <property file="${user.properties.file}"/>
40
+        <!-- The two properties below are usually overridden -->
41
+        <!-- by the active platform. Just a fallback. -->
42
+        <property name="default.javac.source" value="1.4"/>
43
+        <property name="default.javac.target" value="1.4"/>
44
+    </target>
45
+    <target depends="-pre-init,-init-private,-init-user" name="-init-project">
46
+        <property file="nbproject/configs/${config}.properties"/>
47
+        <property file="nbproject/project.properties"/>
48
+    </target>
49
+    <target depends="-pre-init,-init-private,-init-user,-init-project,-init-macrodef-property" name="-do-init">
50
+        <available file="${manifest.file}" property="manifest.available"/>
51
+        <condition property="manifest.available+main.class">
52
+            <and>
53
+                <isset property="manifest.available"/>
54
+                <isset property="main.class"/>
55
+                <not>
56
+                    <equals arg1="${main.class}" arg2="" trim="true"/>
57
+                </not>
58
+            </and>
59
+        </condition>
60
+        <condition property="manifest.available+main.class+mkdist.available">
61
+            <and>
62
+                <istrue value="${manifest.available+main.class}"/>
63
+                <isset property="libs.CopyLibs.classpath"/>
64
+            </and>
65
+        </condition>
66
+        <condition property="have.tests">
67
+            <or>
68
+                <available file="${test.src.dir}"/>
69
+            </or>
70
+        </condition>
71
+        <condition property="have.sources">
72
+            <or>
73
+                <available file="${src.dir}"/>
74
+            </or>
75
+        </condition>
76
+        <condition property="netbeans.home+have.tests">
77
+            <and>
78
+                <isset property="netbeans.home"/>
79
+                <isset property="have.tests"/>
80
+            </and>
81
+        </condition>
82
+        <condition property="no.javadoc.preview">
83
+            <and>
84
+                <isset property="javadoc.preview"/>
85
+                <isfalse value="${javadoc.preview}"/>
86
+            </and>
87
+        </condition>
88
+        <property name="run.jvmargs" value=""/>
89
+        <property name="javac.compilerargs" value=""/>
90
+        <property name="work.dir" value="${basedir}"/>
91
+        <condition property="no.deps">
92
+            <and>
93
+                <istrue value="${no.dependencies}"/>
94
+            </and>
95
+        </condition>
96
+        <property name="javac.debug" value="true"/>
97
+        <property name="javadoc.preview" value="true"/>
98
+        <property name="application.args" value=""/>
99
+        <property name="source.encoding" value="${file.encoding}"/>
100
+        <condition property="javadoc.encoding.used" value="${javadoc.encoding}">
101
+            <and>
102
+                <isset property="javadoc.encoding"/>
103
+                <not>
104
+                    <equals arg1="${javadoc.encoding}" arg2=""/>
105
+                </not>
106
+            </and>
107
+        </condition>
108
+        <property name="javadoc.encoding.used" value="${source.encoding}"/>
109
+        <property name="includes" value="**"/>
110
+        <property name="excludes" value=""/>
111
+        <property name="do.depend" value="false"/>
112
+        <condition property="do.depend.true">
113
+            <istrue value="${do.depend}"/>
114
+        </condition>
115
+        <condition else="" property="javac.compilerargs.jaxws" value="-Djava.endorsed.dirs='${jaxws.endorsed.dir}'">
116
+            <and>
117
+                <isset property="jaxws.endorsed.dir"/>
118
+                <available file="nbproject/jaxws-build.xml"/>
119
+            </and>
120
+        </condition>
121
+    </target>
122
+    <target name="-post-init">
123
+        <!-- Empty placeholder for easier customization. -->
124
+        <!-- You can override this target in the ../build.xml file. -->
125
+    </target>
126
+    <target depends="-pre-init,-init-private,-init-user,-init-project,-do-init" name="-init-check">
127
+        <fail unless="src.dir">Must set src.dir</fail>
128
+        <fail unless="test.src.dir">Must set test.src.dir</fail>
129
+        <fail unless="build.dir">Must set build.dir</fail>
130
+        <fail unless="dist.dir">Must set dist.dir</fail>
131
+        <fail unless="build.classes.dir">Must set build.classes.dir</fail>
132
+        <fail unless="dist.javadoc.dir">Must set dist.javadoc.dir</fail>
133
+        <fail unless="build.test.classes.dir">Must set build.test.classes.dir</fail>
134
+        <fail unless="build.test.results.dir">Must set build.test.results.dir</fail>
135
+        <fail unless="build.classes.excludes">Must set build.classes.excludes</fail>
136
+        <fail unless="dist.jar">Must set dist.jar</fail>
137
+    </target>
138
+    <target name="-init-macrodef-property">
139
+        <macrodef name="property" uri="http://www.netbeans.org/ns/j2se-project/1">
140
+            <attribute name="name"/>
141
+            <attribute name="value"/>
142
+            <sequential>
143
+                <property name="@{name}" value="${@{value}}"/>
144
+            </sequential>
145
+        </macrodef>
146
+    </target>
147
+    <target name="-init-macrodef-javac">
148
+        <macrodef name="javac" uri="http://www.netbeans.org/ns/j2se-project/3">
149
+            <attribute default="${src.dir}" name="srcdir"/>
150
+            <attribute default="${build.classes.dir}" name="destdir"/>
151
+            <attribute default="${javac.classpath}" name="classpath"/>
152
+            <attribute default="${includes}" name="includes"/>
153
+            <attribute default="${excludes}" name="excludes"/>
154
+            <attribute default="${javac.debug}" name="debug"/>
155
+            <attribute default="" name="sourcepath"/>
156
+            <element name="customize" optional="true"/>
157
+            <sequential>
158
+                <javac debug="@{debug}" deprecation="${javac.deprecation}" destdir="@{destdir}" encoding="${source.encoding}" excludes="@{excludes}" includeantruntime="false" includes="@{includes}" source="${javac.source}" sourcepath="@{sourcepath}" srcdir="@{srcdir}" target="${javac.target}">
159
+                    <classpath>
160
+                        <path path="@{classpath}"/>
161
+                    </classpath>
162
+                    <compilerarg line="${javac.compilerargs} ${javac.compilerargs.jaxws}"/>
163
+                    <customize/>
164
+                </javac>
165
+            </sequential>
166
+        </macrodef>
167
+        <macrodef name="depend" uri="http://www.netbeans.org/ns/j2se-project/3">
168
+            <attribute default="${src.dir}" name="srcdir"/>
169
+            <attribute default="${build.classes.dir}" name="destdir"/>
170
+            <attribute default="${javac.classpath}" name="classpath"/>
171
+            <sequential>
172
+                <depend cache="${build.dir}/depcache" destdir="@{destdir}" excludes="${excludes}" includes="${includes}" srcdir="@{srcdir}">
173
+                    <classpath>
174
+                        <path path="@{classpath}"/>
175
+                    </classpath>
176
+                </depend>
177
+            </sequential>
178
+        </macrodef>
179
+        <macrodef name="force-recompile" uri="http://www.netbeans.org/ns/j2se-project/3">
180
+            <attribute default="${build.classes.dir}" name="destdir"/>
181
+            <sequential>
182
+                <fail unless="javac.includes">Must set javac.includes</fail>
183
+                <pathconvert pathsep="," property="javac.includes.binary">
184
+                    <path>
185
+                        <filelist dir="@{destdir}" files="${javac.includes}"/>
186
+                    </path>
187
+                    <globmapper from="*.java" to="*.class"/>
188
+                </pathconvert>
189
+                <delete>
190
+                    <files includes="${javac.includes.binary}"/>
191
+                </delete>
192
+            </sequential>
193
+        </macrodef>
194
+    </target>
195
+    <target name="-init-macrodef-junit">
196
+        <macrodef name="junit" uri="http://www.netbeans.org/ns/j2se-project/3">
197
+            <attribute default="${includes}" name="includes"/>
198
+            <attribute default="${excludes}" name="excludes"/>
199
+            <attribute default="**" name="testincludes"/>
200
+            <sequential>
201
+                <junit dir="${work.dir}" errorproperty="tests.failed" failureproperty="tests.failed" fork="true" showoutput="true">
202
+                    <batchtest todir="${build.test.results.dir}">
203
+                        <fileset dir="${test.src.dir}" excludes="@{excludes},${excludes}" includes="@{includes}">
204
+                            <filename name="@{testincludes}"/>
205
+                        </fileset>
206
+                    </batchtest>
207
+                    <classpath>
208
+                        <path path="${run.test.classpath}"/>
209
+                    </classpath>
210
+                    <syspropertyset>
211
+                        <propertyref prefix="test-sys-prop."/>
212
+                        <mapper from="test-sys-prop.*" to="*" type="glob"/>
213
+                    </syspropertyset>
214
+                    <formatter type="brief" usefile="false"/>
215
+                    <formatter type="xml"/>
216
+                    <jvmarg line="${run.jvmargs}"/>
217
+                </junit>
218
+            </sequential>
219
+        </macrodef>
220
+    </target>
221
+    <target name="-init-macrodef-nbjpda">
222
+        <macrodef name="nbjpdastart" uri="http://www.netbeans.org/ns/j2se-project/1">
223
+            <attribute default="${main.class}" name="name"/>
224
+            <attribute default="${debug.classpath}" name="classpath"/>
225
+            <attribute default="" name="stopclassname"/>
226
+            <sequential>
227
+                <nbjpdastart addressproperty="jpda.address" name="@{name}" stopclassname="@{stopclassname}" transport="dt_socket">
228
+                    <classpath>
229
+                        <path path="@{classpath}"/>
230
+                    </classpath>
231
+                </nbjpdastart>
232
+            </sequential>
233
+        </macrodef>
234
+        <macrodef name="nbjpdareload" uri="http://www.netbeans.org/ns/j2se-project/1">
235
+            <attribute default="${build.classes.dir}" name="dir"/>
236
+            <sequential>
237
+                <nbjpdareload>
238
+                    <fileset dir="@{dir}" includes="${fix.includes}*.class"/>
239
+                </nbjpdareload>
240
+            </sequential>
241
+        </macrodef>
242
+    </target>
243
+    <target name="-init-debug-args">
244
+        <property name="version-output" value="java version &quot;${ant.java.version}"/>
245
+        <condition property="have-jdk-older-than-1.4">
246
+            <or>
247
+                <contains string="${version-output}" substring="java version &quot;1.0"/>
248
+                <contains string="${version-output}" substring="java version &quot;1.1"/>
249
+                <contains string="${version-output}" substring="java version &quot;1.2"/>
250
+                <contains string="${version-output}" substring="java version &quot;1.3"/>
251
+            </or>
252
+        </condition>
253
+        <condition else="-Xdebug" property="debug-args-line" value="-Xdebug -Xnoagent -Djava.compiler=none">
254
+            <istrue value="${have-jdk-older-than-1.4}"/>
255
+        </condition>
256
+    </target>
257
+    <target depends="-init-debug-args" name="-init-macrodef-debug">
258
+        <macrodef name="debug" uri="http://www.netbeans.org/ns/j2se-project/3">
259
+            <attribute default="${main.class}" name="classname"/>
260
+            <attribute default="${debug.classpath}" name="classpath"/>
261
+            <element name="customize" optional="true"/>
262
+            <sequential>
263
+                <java classname="@{classname}" dir="${work.dir}" fork="true">
264
+                    <jvmarg line="${debug-args-line}"/>
265
+                    <jvmarg value="-Xrunjdwp:transport=dt_socket,address=${jpda.address}"/>
266
+                    <jvmarg line="${run.jvmargs}"/>
267
+                    <classpath>
268
+                        <path path="@{classpath}"/>
269
+                    </classpath>
270
+                    <syspropertyset>
271
+                        <propertyref prefix="run-sys-prop."/>
272
+                        <mapper from="run-sys-prop.*" to="*" type="glob"/>
273
+                    </syspropertyset>
274
+                    <customize/>
275
+                </java>
276
+            </sequential>
277
+        </macrodef>
278
+    </target>
279
+    <target name="-init-macrodef-java">
280
+        <macrodef name="java" uri="http://www.netbeans.org/ns/j2se-project/1">
281
+            <attribute default="${main.class}" name="classname"/>
282
+            <element name="customize" optional="true"/>
283
+            <sequential>
284
+                <java classname="@{classname}" dir="${work.dir}" fork="true">
285
+                    <jvmarg line="${run.jvmargs}"/>
286
+                    <classpath>
287
+                        <path path="${run.classpath}"/>
288
+                    </classpath>
289
+                    <syspropertyset>
290
+                        <propertyref prefix="run-sys-prop."/>
291
+                        <mapper from="run-sys-prop.*" to="*" type="glob"/>
292
+                    </syspropertyset>
293
+                    <customize/>
294
+                </java>
295
+            </sequential>
296
+        </macrodef>
297
+    </target>
298
+    <target name="-init-presetdef-jar">
299
+        <presetdef name="jar" uri="http://www.netbeans.org/ns/j2se-project/1">
300
+            <jar compress="${jar.compress}" jarfile="${dist.jar}">
301
+                <j2seproject1:fileset dir="${build.classes.dir}"/>
302
+            </jar>
303
+        </presetdef>
304
+    </target>
305
+    <target depends="-pre-init,-init-private,-init-user,-init-project,-do-init,-post-init,-init-check,-init-macrodef-property,-init-macrodef-javac,-init-macrodef-junit,-init-macrodef-nbjpda,-init-macrodef-debug,-init-macrodef-java,-init-presetdef-jar" name="init"/>
306
+    <!--
307
+                ===================
308
+                COMPILATION SECTION
309
+                ===================
310
+            -->
311
+    <target depends="init" name="deps-jar" unless="no.deps"/>
312
+    <target depends="init,deps-jar" name="-pre-pre-compile">
313
+        <mkdir dir="${build.classes.dir}"/>
314
+    </target>
315
+    <target name="-pre-compile">
316
+        <!-- Empty placeholder for easier customization. -->
317
+        <!-- You can override this target in the ../build.xml file. -->
318
+    </target>
319
+    <target if="do.depend.true" name="-compile-depend">
320
+        <j2seproject3:depend/>
321
+    </target>
322
+    <target depends="init,deps-jar,-pre-pre-compile,-pre-compile,-compile-depend" if="have.sources" name="-do-compile">
323
+        <j2seproject3:javac/>
324
+        <copy todir="${build.classes.dir}">
325
+            <fileset dir="${src.dir}" excludes="${build.classes.excludes},${excludes}" includes="${includes}"/>
326
+        </copy>
327
+    </target>
328
+    <target name="-post-compile">
329
+        <!-- Empty placeholder for easier customization. -->
330
+        <!-- You can override this target in the ../build.xml file. -->
331
+    </target>
332
+    <target depends="init,deps-jar,-pre-pre-compile,-pre-compile,-do-compile,-post-compile" description="Compile project." name="compile"/>
333
+    <target name="-pre-compile-single">
334
+        <!-- Empty placeholder for easier customization. -->
335
+        <!-- You can override this target in the ../build.xml file. -->
336
+    </target>
337
+    <target depends="init,deps-jar,-pre-pre-compile" name="-do-compile-single">
338
+        <fail unless="javac.includes">Must select some files in the IDE or set javac.includes</fail>
339
+        <j2seproject3:force-recompile/>
340
+        <j2seproject3:javac excludes="" includes="${javac.includes}" sourcepath="${src.dir}"/>
341
+    </target>
342
+    <target name="-post-compile-single">
343
+        <!-- Empty placeholder for easier customization. -->
344
+        <!-- You can override this target in the ../build.xml file. -->
345
+    </target>
346
+    <target depends="init,deps-jar,-pre-pre-compile,-pre-compile-single,-do-compile-single,-post-compile-single" name="compile-single"/>
347
+    <!--
348
+                ====================
349
+                JAR BUILDING SECTION
350
+                ====================
351
+            -->
352
+    <target depends="init" name="-pre-pre-jar">
353
+        <dirname file="${dist.jar}" property="dist.jar.dir"/>
354
+        <mkdir dir="${dist.jar.dir}"/>
355
+    </target>
356
+    <target name="-pre-jar">
357
+        <!-- Empty placeholder for easier customization. -->
358
+        <!-- You can override this target in the ../build.xml file. -->
359
+    </target>
360
+    <target depends="init,compile,-pre-pre-jar,-pre-jar" name="-do-jar-without-manifest" unless="manifest.available">
361
+        <j2seproject1:jar/>
362
+    </target>
363
+    <target depends="init,compile,-pre-pre-jar,-pre-jar" if="manifest.available" name="-do-jar-with-manifest" unless="manifest.available+main.class">
364
+        <j2seproject1:jar manifest="${manifest.file}"/>
365
+    </target>
366
+    <target depends="init,compile,-pre-pre-jar,-pre-jar" if="manifest.available+main.class" name="-do-jar-with-mainclass" unless="manifest.available+main.class+mkdist.available">
367
+        <j2seproject1:jar manifest="${manifest.file}">
368
+            <j2seproject1:manifest>
369
+                <j2seproject1:attribute name="Main-Class" value="${main.class}"/>
370
+            </j2seproject1:manifest>
371
+        </j2seproject1:jar>
372
+        <echo>To run this application from the command line without Ant, try:</echo>
373
+        <property location="${build.classes.dir}" name="build.classes.dir.resolved"/>
374
+        <property location="${dist.jar}" name="dist.jar.resolved"/>
375
+        <pathconvert property="run.classpath.with.dist.jar">
376
+            <path path="${run.classpath}"/>
377
+            <map from="${build.classes.dir.resolved}" to="${dist.jar.resolved}"/>
378
+        </pathconvert>
379
+        <echo>java -cp "${run.classpath.with.dist.jar}" ${main.class}</echo>
380
+    </target>
381
+    <target depends="init,compile,-pre-pre-jar,-pre-jar" if="manifest.available+main.class+mkdist.available" name="-do-jar-with-libraries">
382
+        <property location="${build.classes.dir}" name="build.classes.dir.resolved"/>
383
+        <pathconvert property="run.classpath.without.build.classes.dir">
384
+            <path path="${run.classpath}"/>
385
+            <map from="${build.classes.dir.resolved}" to=""/>
386
+        </pathconvert>
387
+        <pathconvert pathsep=" " property="jar.classpath">
388
+            <path path="${run.classpath.without.build.classes.dir}"/>
389
+            <chainedmapper>
390
+                <flattenmapper/>
391
+                <globmapper from="*" to="lib/*"/>
392
+            </chainedmapper>
393
+        </pathconvert>
394
+        <taskdef classname="org.netbeans.modules.java.j2seproject.copylibstask.CopyLibs" classpath="${libs.CopyLibs.classpath}" name="copylibs"/>
395
+        <copylibs compress="${jar.compress}" jarfile="${dist.jar}" manifest="${manifest.file}" runtimeclasspath="${run.classpath.without.build.classes.dir}">
396
+            <fileset dir="${build.classes.dir}"/>
397
+            <manifest>
398
+                <attribute name="Main-Class" value="${main.class}"/>
399
+                <attribute name="Class-Path" value="${jar.classpath}"/>
400
+            </manifest>
401
+        </copylibs>
402
+        <echo>To run this application from the command line without Ant, try:</echo>
403
+        <property location="${dist.jar}" name="dist.jar.resolved"/>
404
+        <echo>java -jar "${dist.jar.resolved}"</echo>
405
+    </target>
406
+    <target name="-post-jar">
407
+        <!-- Empty placeholder for easier customization. -->
408
+        <!-- You can override this target in the ../build.xml file. -->
409
+    </target>
410
+    <target depends="init,compile,-pre-jar,-do-jar-with-manifest,-do-jar-without-manifest,-do-jar-with-mainclass,-do-jar-with-libraries,-post-jar" description="Build JAR." name="jar"/>
411
+    <!--
412
+                =================
413
+                EXECUTION SECTION
414
+                =================
415
+            -->
416
+    <target depends="init,compile" description="Run a main class." name="run">
417
+        <j2seproject1:java>
418
+            <customize>
419
+                <arg line="${application.args}"/>
420
+            </customize>
421
+        </j2seproject1:java>
422
+    </target>
423
+    <target name="-do-not-recompile">
424
+        <property name="javac.includes.binary" value=""/>
425
+    </target>
426
+    <target depends="init,-do-not-recompile,compile-single" name="run-single">
427
+        <fail unless="run.class">Must select one file in the IDE or set run.class</fail>
428
+        <j2seproject1:java classname="${run.class}"/>
429
+    </target>
430
+    <!--
431
+                =================
432
+                DEBUGGING SECTION
433
+                =================
434
+            -->
435
+    <target depends="init" if="netbeans.home" name="-debug-start-debugger">
436
+        <j2seproject1:nbjpdastart name="${debug.class}"/>
437
+    </target>
438
+    <target depends="init,compile" name="-debug-start-debuggee">
439
+        <j2seproject3:debug>
440
+            <customize>
441
+                <arg line="${application.args}"/>
442
+            </customize>
443
+        </j2seproject3:debug>
444
+    </target>
445
+    <target depends="init,compile,-debug-start-debugger,-debug-start-debuggee" description="Debug project in IDE." if="netbeans.home" name="debug"/>
446
+    <target depends="init" if="netbeans.home" name="-debug-start-debugger-stepinto">
447
+        <j2seproject1:nbjpdastart stopclassname="${main.class}"/>
448
+    </target>
449
+    <target depends="init,compile,-debug-start-debugger-stepinto,-debug-start-debuggee" if="netbeans.home" name="debug-stepinto"/>
450
+    <target depends="init,compile-single" if="netbeans.home" name="-debug-start-debuggee-single">
451
+        <fail unless="debug.class">Must select one file in the IDE or set debug.class</fail>
452
+        <j2seproject3:debug classname="${debug.class}"/>
453
+    </target>
454
+    <target depends="init,-do-not-recompile,compile-single,-debug-start-debugger,-debug-start-debuggee-single" if="netbeans.home" name="debug-single"/>
455
+    <target depends="init" name="-pre-debug-fix">
456
+        <fail unless="fix.includes">Must set fix.includes</fail>
457
+        <property name="javac.includes" value="${fix.includes}.java"/>
458
+    </target>
459
+    <target depends="init,-pre-debug-fix,compile-single" if="netbeans.home" name="-do-debug-fix">
460
+        <j2seproject1:nbjpdareload/>
461
+    </target>
462
+    <target depends="init,-pre-debug-fix,-do-debug-fix" if="netbeans.home" name="debug-fix"/>
463
+    <!--
464
+                ===============
465
+                JAVADOC SECTION
466
+                ===============
467
+            -->
468
+    <target depends="init" name="-javadoc-build">
469
+        <mkdir dir="${dist.javadoc.dir}"/>
470
+        <javadoc additionalparam="${javadoc.additionalparam}" author="${javadoc.author}" charset="UTF-8" destdir="${dist.javadoc.dir}" docencoding="UTF-8" encoding="${javadoc.encoding.used}" failonerror="true" noindex="${javadoc.noindex}" nonavbar="${javadoc.nonavbar}" notree="${javadoc.notree}" private="${javadoc.private}" source="${javac.source}" splitindex="${javadoc.splitindex}" use="${javadoc.use}" useexternalfile="true" version="${javadoc.version}" windowtitle="${javadoc.windowtitle}">
471
+            <classpath>
472
+                <path path="${javac.classpath}"/>
473
+            </classpath>
474
+            <fileset dir="${src.dir}" excludes="${excludes}" includes="${includes}">
475
+                <filename name="**/*.java"/>
476
+            </fileset>
477
+        </javadoc>
478
+    </target>
479
+    <target depends="init,-javadoc-build" if="netbeans.home" name="-javadoc-browse" unless="no.javadoc.preview">
480
+        <nbbrowse file="${dist.javadoc.dir}/index.html"/>
481
+    </target>
482
+    <target depends="init,-javadoc-build,-javadoc-browse" description="Build Javadoc." name="javadoc"/>
483
+    <!--
484
+                =========================
485
+                JUNIT COMPILATION SECTION
486
+                =========================
487
+            -->
488
+    <target depends="init,compile" if="have.tests" name="-pre-pre-compile-test">
489
+        <mkdir dir="${build.test.classes.dir}"/>
490
+    </target>
491
+    <target name="-pre-compile-test">
492
+        <!-- Empty placeholder for easier customization. -->
493
+        <!-- You can override this target in the ../build.xml file. -->
494
+    </target>
495
+    <target if="do.depend.true" name="-compile-test-depend">
496
+        <j2seproject3:depend classpath="${javac.test.classpath}" destdir="${build.test.classes.dir}" srcdir="${test.src.dir}"/>
497
+    </target>
498
+    <target depends="init,compile,-pre-pre-compile-test,-pre-compile-test,-compile-test-depend" if="have.tests" name="-do-compile-test">
499
+        <j2seproject3:javac classpath="${javac.test.classpath}" debug="true" destdir="${build.test.classes.dir}" srcdir="${test.src.dir}"/>
500
+        <copy todir="${build.test.classes.dir}">
501
+            <fileset dir="${test.src.dir}" excludes="${build.classes.excludes},${excludes}" includes="${includes}"/>
502
+        </copy>
503
+    </target>
504
+    <target name="-post-compile-test">
505
+        <!-- Empty placeholder for easier customization. -->
506
+        <!-- You can override this target in the ../build.xml file. -->
507
+    </target>
508
+    <target depends="init,compile,-pre-pre-compile-test,-pre-compile-test,-do-compile-test,-post-compile-test" name="compile-test"/>
509
+    <target name="-pre-compile-test-single">
510
+        <!-- Empty placeholder for easier customization. -->
511
+        <!-- You can override this target in the ../build.xml file. -->
512
+    </target>
513
+    <target depends="init,compile,-pre-pre-compile-test,-pre-compile-test-single" if="have.tests" name="-do-compile-test-single">
514
+        <fail unless="javac.includes">Must select some files in the IDE or set javac.includes</fail>
515
+        <j2seproject3:force-recompile destdir="${build.test.classes.dir}"/>
516
+        <j2seproject3:javac classpath="${javac.test.classpath}" debug="true" destdir="${build.test.classes.dir}" excludes="" includes="${javac.includes}" sourcepath="${test.src.dir}" srcdir="${test.src.dir}"/>
517
+        <copy todir="${build.test.classes.dir}">
518
+            <fileset dir="${test.src.dir}" excludes="${build.classes.excludes},${excludes}" includes="${includes}"/>
519
+        </copy>
520
+    </target>
521
+    <target name="-post-compile-test-single">
522
+        <!-- Empty placeholder for easier customization. -->
523
+        <!-- You can override this target in the ../build.xml file. -->
524
+    </target>
525
+    <target depends="init,compile,-pre-pre-compile-test,-pre-compile-test-single,-do-compile-test-single,-post-compile-test-single" name="compile-test-single"/>
526
+    <!--
527
+                =======================
528
+                JUNIT EXECUTION SECTION
529
+                =======================
530
+            -->
531
+    <target depends="init" if="have.tests" name="-pre-test-run">
532
+        <mkdir dir="${build.test.results.dir}"/>
533
+    </target>
534
+    <target depends="init,compile-test,-pre-test-run" if="have.tests" name="-do-test-run">
535
+        <j2seproject3:junit testincludes="**/*Test.java"/>
536
+    </target>
537
+    <target depends="init,compile-test,-pre-test-run,-do-test-run" if="have.tests" name="-post-test-run">
538
+        <fail if="tests.failed">Some tests failed; see details above.</fail>
539
+    </target>
540
+    <target depends="init" if="have.tests" name="test-report"/>
541
+    <target depends="init" if="netbeans.home+have.tests" name="-test-browse"/>
542
+    <target depends="init,compile-test,-pre-test-run,-do-test-run,test-report,-post-test-run,-test-browse" description="Run unit tests." name="test"/>
543
+    <target depends="init" if="have.tests" name="-pre-test-run-single">
544
+        <mkdir dir="${build.test.results.dir}"/>
545
+    </target>
546
+    <target depends="init,compile-test-single,-pre-test-run-single" if="have.tests" name="-do-test-run-single">
547
+        <fail unless="test.includes">Must select some files in the IDE or set test.includes</fail>
548
+        <j2seproject3:junit excludes="" includes="${test.includes}"/>
549
+    </target>
550
+    <target depends="init,compile-test-single,-pre-test-run-single,-do-test-run-single" if="have.tests" name="-post-test-run-single">
551
+        <fail if="tests.failed">Some tests failed; see details above.</fail>
552
+    </target>
553
+    <target depends="init,-do-not-recompile,compile-test-single,-pre-test-run-single,-do-test-run-single,-post-test-run-single" description="Run single unit test." name="test-single"/>
554
+    <!--
555
+                =======================
556
+                JUNIT DEBUGGING SECTION
557
+                =======================
558
+            -->
559
+    <target depends="init,compile-test" if="have.tests" name="-debug-start-debuggee-test">
560
+        <fail unless="test.class">Must select one file in the IDE or set test.class</fail>
561
+        <property location="${build.test.results.dir}/TEST-${test.class}.xml" name="test.report.file"/>
562
+        <delete file="${test.report.file}"/>
563
+        <mkdir dir="${build.test.results.dir}"/>
564
+        <j2seproject3:debug classname="org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner" classpath="${ant.home}/lib/ant.jar:${ant.home}/lib/ant-junit.jar:${debug.test.classpath}">
565
+            <customize>
566
+                <syspropertyset>
567
+                    <propertyref prefix="test-sys-prop."/>
568
+                    <mapper from="test-sys-prop.*" to="*" type="glob"/>
569
+                </syspropertyset>
570
+                <arg value="${test.class}"/>
571
+                <arg value="showoutput=true"/>
572
+                <arg value="formatter=org.apache.tools.ant.taskdefs.optional.junit.BriefJUnitResultFormatter"/>
573
+                <arg value="formatter=org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter,${test.report.file}"/>
574
+            </customize>
575
+        </j2seproject3:debug>
576
+    </target>
577
+    <target depends="init,compile-test" if="netbeans.home+have.tests" name="-debug-start-debugger-test">
578
+        <j2seproject1:nbjpdastart classpath="${debug.test.classpath}" name="${test.class}"/>
579
+    </target>
580
+    <target depends="init,-do-not-recompile,compile-test-single,-debug-start-debugger-test,-debug-start-debuggee-test" name="debug-test"/>
581
+    <target depends="init,-pre-debug-fix,compile-test-single" if="netbeans.home" name="-do-debug-fix-test">
582
+        <j2seproject1:nbjpdareload dir="${build.test.classes.dir}"/>
583
+    </target>
584
+    <target depends="init,-pre-debug-fix,-do-debug-fix-test" if="netbeans.home" name="debug-fix-test"/>
585
+    <!--
586
+                =========================
587
+                APPLET EXECUTION SECTION
588
+                =========================
589
+            -->
590
+    <target depends="init,compile-single" name="run-applet">
591
+        <fail unless="applet.url">Must select one file in the IDE or set applet.url</fail>
592
+        <j2seproject1:java classname="sun.applet.AppletViewer">
593
+            <customize>
594
+                <arg value="${applet.url}"/>
595
+            </customize>
596
+        </j2seproject1:java>
597
+    </target>
598
+    <!--
599
+                =========================
600
+                APPLET DEBUGGING  SECTION
601
+                =========================
602
+            -->
603
+    <target depends="init,compile-single" if="netbeans.home" name="-debug-start-debuggee-applet">
604
+        <fail unless="applet.url">Must select one file in the IDE or set applet.url</fail>
605
+        <j2seproject3:debug classname="sun.applet.AppletViewer">
606
+            <customize>
607
+                <arg value="${applet.url}"/>
608
+            </customize>
609
+        </j2seproject3:debug>
610
+    </target>
611
+    <target depends="init,compile-single,-debug-start-debugger,-debug-start-debuggee-applet" if="netbeans.home" name="debug-applet"/>
612
+    <!--
613
+                ===============
614
+                CLEANUP SECTION
615
+                ===============
616
+            -->
617
+    <target depends="init" name="deps-clean" unless="no.deps"/>
618
+    <target depends="init" name="-do-clean">
619
+        <delete dir="${build.dir}"/>
620
+        <delete dir="${dist.dir}"/>
621
+    </target>
622
+    <target name="-post-clean">
623
+        <!-- Empty placeholder for easier customization. -->
624
+        <!-- You can override this target in the ../build.xml file. -->
625
+    </target>
626
+    <target depends="init,deps-clean,-do-clean,-post-clean" description="Clean build products." name="clean"/>
627
+</project>

+ 8
- 0
nbproject/genfiles.properties View File

@@ -0,0 +1,8 @@
1
+build.xml.data.CRC32=f0848ad5
2
+build.xml.script.CRC32=e8f6e476
3
+build.xml.stylesheet.CRC32=be360661
4
+# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
5
+# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
6
+nbproject/build-impl.xml.data.CRC32=f0848ad5
7
+nbproject/build-impl.xml.script.CRC32=8ae13691
8
+nbproject/build-impl.xml.stylesheet.CRC32=f1d9da08

+ 0
- 0
nbproject/private/config.properties View File


+ 4
- 0
nbproject/private/private.properties View File

@@ -0,0 +1,4 @@
1
+javac.debug=true
2
+javadoc.preview=true
3
+jaxws.endorsed.dir=/usr/local/netbeans-6.0/java1/modules/ext/jaxws21/api
4
+user.properties.file=/home/chris/.netbeans/6.0/build.properties

+ 4
- 0
nbproject/private/private.xml View File

@@ -0,0 +1,4 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<project-private xmlns="http://www.netbeans.org/ns/project-private/1">
3
+    <editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/1"/>
4
+</project-private>

+ 63
- 0
nbproject/project.properties View File

@@ -0,0 +1,63 @@
1
+application.title=CardGame
2
+application.vendor=Chris
3
+build.classes.dir=${build.dir}/classes
4
+build.classes.excludes=**/*.java,**/*.form
5
+# This directory is removed when the project is cleaned:
6
+build.dir=build
7
+build.generated.dir=${build.dir}/generated
8
+# Only compile against the classpath explicitly listed here:
9
+build.sysclasspath=ignore
10
+build.test.classes.dir=${build.dir}/test/classes
11
+build.test.results.dir=${build.dir}/test/results
12
+debug.classpath=\
13
+    ${run.classpath}
14
+debug.test.classpath=\
15
+    ${run.test.classpath}
16
+# This directory is removed when the project is cleaned:
17
+dist.dir=dist
18
+dist.jar=${dist.dir}/CardGame.jar
19
+dist.javadoc.dir=${dist.dir}/javadoc
20
+excludes=
21
+includes=**
22
+jar.compress=true
23
+javac.classpath=
24
+# Space-separated list of extra javac options
25
+javac.compilerargs=-Xlint:all
26
+javac.deprecation=false
27
+javac.source=1.5
28
+javac.target=1.5
29
+javac.test.classpath=\
30
+    ${javac.classpath}:\
31
+    ${build.classes.dir}:\
32
+    ${libs.junit_4.classpath}
33
+javadoc.additionalparam=
34
+javadoc.author=false
35
+javadoc.encoding=
36
+javadoc.noindex=false
37
+javadoc.nonavbar=false
38
+javadoc.notree=false
39
+javadoc.private=false
40
+javadoc.splitindex=true
41
+javadoc.use=true
42
+javadoc.version=false
43
+javadoc.windowtitle=
44
+# Property libs.junit_4.classpath is set here just to make sharing of project simpler.
45
+# The library definition has always preference over this property.
46
+libs.junit_4.classpath=../../netbeans-6.0beta1/java1/modules/ext/junit-4.1.jar
47
+main.class=com.md87.cardgame.Main
48
+manifest.file=manifest.mf
49
+meta.inf.dir=${src.dir}/META-INF
50
+platform.active=default_platform
51
+run.classpath=\
52
+    ${javac.classpath}:\
53
+    ${build.classes.dir}
54
+# Space-separated list of JVM arguments used when running the project
55
+# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value
56
+# or test-sys-prop.name=value to set system properties for unit tests):
57
+run.jvmargs=
58
+run.test.classpath=\
59
+    ${javac.test.classpath}:\
60
+    ${build.test.classes.dir}
61
+source.encoding=UTF-8
62
+src.dir=src
63
+test.src.dir=test

+ 17
- 0
nbproject/project.xml View File

@@ -0,0 +1,17 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<project xmlns="http://www.netbeans.org/ns/project/1">
3
+    <type>org.netbeans.modules.java.j2seproject</type>
4
+    <configuration>
5
+        <data xmlns="http://www.netbeans.org/ns/j2se-project/3">
6
+            <name>CardGame</name>
7
+            <minimum-ant-version>1.6.5</minimum-ant-version>
8
+            <source-roots>
9
+                <root id="src.dir"/>
10
+            </source-roots>
11
+            <test-roots>
12
+                <root id="test.src.dir"/>
13
+            </test-roots>
14
+        </data>
15
+        <junit-version xmlns="http://www.netbeans.org/ns/junit/1" value="junit4"/>
16
+    </configuration>
17
+</project>

+ 31
- 0
src/com/md87/cardgame/Achievement.java View File

@@ -0,0 +1,31 @@
1
+/*
2
+ * Copyright (c) Chris 'MD87' Smith, 2007. All rights reserved.
3
+ *
4
+ * This code may not be redistributed without prior permission from the
5
+ * aforementioned copyright holder(s).
6
+ */
7
+
8
+package com.md87.cardgame;
9
+
10
+/**
11
+ *
12
+ * @author chris
13
+ */
14
+public enum Achievement {
15
+    
16
+    ALL_IN_WIN("All in", "Go all in and win the hand"),
17
+    TOURNAMENT_WIN("Winner", "Beat at least three other players to win a tournament"),
18
+    FLUSH("Flushed", "Make a five-card flush"),
19
+    HIGH_LOW("High/low", "Win both the high and low pots in a game of Omaha High/Low"),
20
+    STREAK("Winning streak", "Win five consecutive hands in a tournament")
21
+    ;
22
+    
23
+    protected String name;
24
+    protected String desc;
25
+    
26
+    Achievement(final String name, final String desc) {
27
+        this.name = name;
28
+        this.desc = desc;
29
+    }
30
+
31
+}

+ 124
- 0
src/com/md87/cardgame/Card.java View File

@@ -0,0 +1,124 @@
1
+/*
2
+ * Copyright (c) Chris 'MD87' Smith, 2007. All rights reserved.
3
+ *
4
+ * This code may not be redistributed without prior permission from the
5
+ * aforementioned copyright holder(s).
6
+ */
7
+
8
+package com.md87.cardgame;
9
+
10
+/**
11
+ * Represents a single card, consisting of a rank and suit combination.
12
+ * 
13
+ * @author Chris
14
+ */
15
+public class Card implements Comparable<Card> {
16
+   
17
+    /** The suit of this card. */
18
+    private final Suit suit;
19
+    
20
+    /** The rank of this card. */
21
+    private final Rank rank;
22
+    
23
+    /** Whether or not this card is public. */
24
+    private boolean isPublic = false;
25
+
26
+    /**
27
+     * Creates a new instance of Card.
28
+     * 
29
+     * @param suit The suit of this card
30
+     * @param rank The rank of this card
31
+     */
32
+    public Card(final Suit suit, final Rank rank) {
33
+        this.suit = suit;
34
+        this.rank = rank;
35
+    }
36
+    
37
+    /**
38
+     * Sets the "public" property of this card. Public cards are displayed
39
+     * to all players.
40
+     * 
41
+     * @param isPublic The new public property of this card
42
+     */
43
+    public void setPublic(final boolean isPublic) {
44
+        this.isPublic = isPublic;
45
+    }
46
+    
47
+    /**
48
+     * Determines if this card is public or not.
49
+     * 
50
+     * @return True if the card is public, false otherwise
51
+     */
52
+    public boolean isPublic() {
53
+        return isPublic;
54
+    }
55
+    
56
+    /**
57
+     * Retrieves the rank of this card.
58
+     * 
59
+     * @return This card's rank
60
+     */
61
+    public Rank getRank() {
62
+        return rank;
63
+    }
64
+    
65
+    /**
66
+     * Retrieves the suit of this card.
67
+     * 
68
+     * @return This card's suit
69
+     */
70
+    public Suit getSuit() {
71
+        return suit;
72
+    }
73
+    
74
+    /**
75
+     * Retrieves the file name used to display this card.
76
+     * 
77
+     * @return The file name used to display this card
78
+     */
79
+    public String getFileName() {
80
+        return (suit.toString().charAt(0) + rank.toString()).toLowerCase();
81
+    }
82
+
83
+    /** {@inheritDoc} */
84
+    public int compareTo(Card o) {
85
+        return compareTo(o, false);
86
+    }
87
+    
88
+    public int compareTo(Card o, boolean acesLow) {
89
+        return -1 * rank.compareTo(o.getRank(), acesLow);
90
+    }
91
+    
92
+    /** {@inheritDoc} */
93
+    @Override
94
+    public String toString() {
95
+        return rank.toString() + "/" + suit.toString().charAt(0);
96
+    }
97
+
98
+    @Override
99
+    public boolean equals(Object obj) {
100
+        if (obj == null) {
101
+            return false;
102
+        }
103
+        if (getClass() != obj.getClass()) {
104
+            return false;
105
+        }
106
+        final Card other = (Card) obj;
107
+        if (this.suit != other.suit) {
108
+            return false;
109
+        }
110
+        if (this.rank != other.rank) {
111
+            return false;
112
+        }
113
+        return true;
114
+    }
115
+
116
+    @Override
117
+    public int hashCode() {
118
+        int hash = 3;
119
+        hash = 89 * hash + (this.suit != null ? this.suit.hashCode() : 0);
120
+        hash = 89 * hash + (this.rank != null ? this.rank.hashCode() : 0);
121
+        return hash;
122
+    }
123
+
124
+}

+ 140
- 0
src/com/md87/cardgame/Deck.java View File

@@ -0,0 +1,140 @@
1
+/*
2
+ * Copyright (c) Chris 'MD87' Smith, 2007. All rights reserved.
3
+ *
4
+ * This code may not be redistributed without prior permission from the
5
+ * aforementioned copyright holder(s).
6
+ */
7
+
8
+package com.md87.cardgame;
9
+
10
+import java.util.ArrayList;
11
+import java.util.Collections;
12
+import java.util.List;
13
+
14
+/**
15
+ *
16
+ * @author Chris
17
+ */
18
+public class Deck extends ArrayList<Card> implements Comparable<Deck> {
19
+    
20
+    private static final long serialVersionUID = 1;
21
+    
22
+    public Deck() {
23
+        super();
24
+    }
25
+    
26
+    public Deck(final List<Card> parent) {
27
+        super(parent);
28
+    }
29
+    
30
+    public Deck(final Card ... cards) {
31
+        super();
32
+        
33
+        for (Card card : cards) {
34
+            add(card);
35
+        }
36
+    }
37
+    
38
+    public Deck getSuit(final Suit suit) {
39
+        final Deck res = new Deck();
40
+        
41
+        for (Card card : this) {
42
+            if (card.getSuit() == suit) {
43
+                res.add(card);
44
+            }
45
+        }
46
+        
47
+        return res;
48
+    }
49
+    
50
+    public Deck getRank(final Rank rank) {
51
+        final Deck res = new Deck();
52
+        
53
+        for (Card card : this) {
54
+            if (card.getRank() == rank) {
55
+                res.add(card);
56
+            }
57
+        }
58
+        
59
+        return res;
60
+    }
61
+    
62
+    public void removeByRank(final Rank rank, final int count) {
63
+        final Deck newDeck = new Deck();
64
+        int remaining = count;
65
+        
66
+        for (Card card : this) {
67
+            if (card.getRank().equals(rank) && remaining > 0) {
68
+                remaining--;
69
+            } else {
70
+                newDeck.add(card);
71
+            }
72
+        }
73
+        
74
+        clear();
75
+        addAll(newDeck);
76
+    }
77
+    
78
+    public Card deal() {
79
+        final Card res = get(0);
80
+        
81
+        remove(0);
82
+        
83
+        return res;
84
+    }
85
+    
86
+    public void limitTo(final int number) {
87
+        Collections.sort(this);
88
+        
89
+        while (size() > number) {
90
+            remove(0);
91
+        }
92
+    }
93
+    
94
+    public void reverseLimitTo(final int number) {
95
+        Collections.sort(this);
96
+        
97
+        while (size() > number) {
98
+            remove(size() - 1);
99
+        }
100
+    }    
101
+    
102
+    public int compareTo(Deck o) {
103
+        return compareTo(o, false);
104
+    }
105
+    
106
+    public int compareTo(Deck o, boolean acesLow) {
107
+        Collections.sort(this);
108
+        Collections.sort(o);
109
+        
110
+        if (size() != o.size()) {
111
+            System.err.println("Warning: Deck.compareTo() called with different sized deck:");
112
+            System.err.println("   Me: " + this);
113
+            System.err.println(" Them: " + o);
114
+            new Exception().printStackTrace();
115
+        }
116
+        
117
+        for (int i = Math.min(this.size(), o.size()) - 1; i >= 0; i--) {
118
+            int res = this.get(i).compareTo(o.get(i), acesLow);
119
+            
120
+            if (res != 0) {
121
+                return res;
122
+            }
123
+        }
124
+        
125
+        return 0;
126
+    }
127
+    
128
+    @Override
129
+    public String toString() {
130
+        final StringBuilder builder = new StringBuilder();
131
+        
132
+        for (Card card : this) {
133
+            builder.append(' ');
134
+            builder.append(card.toString());
135
+        }
136
+        
137
+        return builder.length() == 0 ? "" : builder.substring(1);
138
+    }
139
+    
140
+}

+ 29
- 0
src/com/md87/cardgame/Main.java View File

@@ -0,0 +1,29 @@
1
+/*
2
+ * Copyright (c) Chris 'MD87' Smith, 2007. All rights reserved.
3
+ *
4
+ * This code may not be redistributed without prior permission from the
5
+ * aforementioned copyright holder(s).
6
+ */
7
+
8
+package com.md87.cardgame;
9
+
10
+import com.md87.cardgame.config.ConfigScreen;
11
+
12
+/**
13
+ *
14
+ * @author Chris
15
+ */
16
+public class Main {
17
+    
18
+    /** Creates a new instance of Main */
19
+    public Main() {
20
+    }
21
+    
22
+    /**
23
+     * @param args the command line arguments
24
+     */
25
+    public static void main(String[] args) {
26
+        new ConfigScreen();
27
+    }
28
+    
29
+}

+ 176
- 0
src/com/md87/cardgame/Player.java View File

@@ -0,0 +1,176 @@
1
+/*
2
+ * Copyright (c) Chris 'MD87' Smith, 2007. All rights reserved.
3
+ *
4
+ * This code may not be redistributed without prior permission from the
5
+ * aforementioned copyright holder(s).
6
+ */
7
+
8
+package com.md87.cardgame;
9
+
10
+import com.md87.cardgame.interfaces.Game;
11
+import com.md87.cardgame.interfaces.PlayerController;
12
+
13
+/**
14
+ *
15
+ * @author Chris
16
+ */
17
+public class Player implements Comparable<Player> {
18
+    
19
+    public static enum OpenCheck {OPEN, CHECK};
20
+    public static enum CallRaiseFold {CALL, RAISE, FOLD};
21
+    
22
+    private String name;
23
+    private Game game;
24
+    
25
+    private int cash;
26
+    private int bet;
27
+    
28
+    private PlayerController controller;
29
+    
30
+    private final Deck cards = new Deck();
31
+    private Deck bestDeck = null;
32
+    
33
+    private boolean hasFolded = false;
34
+    private boolean isOut = false;
35
+    private boolean isAllIn = false;
36
+    
37
+    public Player(final Game game, final String name, final int cash, final PlayerController controller) {
38
+        this.name = name;
39
+        this.cash = cash;
40
+        this.game = game;
41
+        
42
+        this.controller = controller;
43
+        controller.setPlayer(this);
44
+        controller.setGame(game);
45
+    }
46
+    
47
+    public Deck getCards() {
48
+        return cards;
49
+    }
50
+    
51
+    public Deck getBestDeck() {
52
+        calculateBestDeck();
53
+        
54
+        return bestDeck;
55
+    }
56
+    
57
+    public Deck doCardDiscard(int min, int max) {
58
+        return controller.discardCards(min, max);
59
+    }
60
+    
61
+    public void calculateBestDeck() {
62
+        bestDeck = game.getBestDeck(cards);
63
+    }
64
+    
65
+    public OpenCheck doOpenCheck() {
66
+        OpenCheck res = controller.doOpenCheck();
67
+        
68
+        if (cash <= 0 && res == OpenCheck.OPEN) {
69
+            res = OpenCheck.CHECK;
70
+        }
71
+        
72
+        return res;
73
+    }
74
+    
75
+    public CallRaiseFold doCallRaiseFold(final int callAmount, boolean canRaise) {
76
+        CallRaiseFold res = controller.doCallRaiseFold(callAmount, canRaise);
77
+        
78
+        if (cash - callAmount <= 0 && res == CallRaiseFold.RAISE) {
79
+            res = Player.CallRaiseFold.CALL;
80
+        }
81
+        
82
+        return res;
83
+    }
84
+    
85
+    public boolean shouldShowCards() {
86
+        return controller.shouldShowCards();
87
+    }
88
+    
89
+    public void forceBet(final int blind) {
90
+        int size = Math.min(cash, blind);
91
+        
92
+        bet += size;
93
+        cash -= size;
94
+        
95
+        if (cash == 0) {
96
+            isAllIn = true;
97
+        }
98
+    }
99
+    
100
+    public void resetBet() {
101
+        this.bet = 0;
102
+    }
103
+    
104
+    public void addCash(final int amount) {
105
+        cash += amount;
106
+    }
107
+    
108
+    public void setOut() {
109
+        isOut = true;
110
+    }
111
+    
112
+    public String getName() {
113
+        return name + " (" + (isAllIn ? "all in" : cash) + ")";
114
+    }
115
+    
116
+    public void setFold() {
117
+        hasFolded = true;
118
+    }
119
+    
120
+    public void dealCard(final Card card) {
121
+        cards.add(card);
122
+    }
123
+    
124
+    public void removeCard(final Card card) {
125
+        cards.remove(card);
126
+    }
127
+    
128
+    public void discardCards() {
129
+        synchronized(cards) {
130
+            cards.clear();
131
+        }
132
+        
133
+        bet = 0;
134
+        hasFolded = false;
135
+        isOut = cash <= 0;
136
+        isAllIn = false;
137
+        bestDeck = null;
138
+    }
139
+    
140
+    public int getCash() {
141
+        return cash;
142
+    }
143
+    
144
+    public int getBet() {
145
+        return bet;
146
+    }
147
+    
148
+    public boolean hasFolded() {
149
+        return hasFolded;
150
+    }
151
+    
152
+    public boolean isOut() {
153
+        return isOut;
154
+    }
155
+    
156
+    public boolean isAllIn() {
157
+        return isAllIn;
158
+    }
159
+    
160
+    public int getRaiseAmount(final int minimum) {
161
+        if (minimum > cash) {
162
+            return cash;
163
+        } else {
164
+            return controller.getRaise(minimum);
165
+        }
166
+    }
167
+    
168
+    public int compareTo(Player o) {
169
+        return -1 * game.getHand(getBestDeck()).compareTo(game.getHand(o.getBestDeck()));
170
+    }
171
+    
172
+    public boolean isLocalHuman() {
173
+        return controller.isLocalHuman();
174
+    }
175
+    
176
+}

+ 103
- 0
src/com/md87/cardgame/RaiseWindow.java View File

@@ -0,0 +1,103 @@
1
+/*
2
+ * Copyright (c) Chris 'MD87' Smith, 2007. All rights reserved.
3
+ * 
4
+ * This code may not be redistributed without prior permission from the
5
+ * aforementioned copyright holder(s).
6
+ */
7
+
8
+package com.md87.cardgame;
9
+
10
+import com.md87.cardgame.controllers.HumanPlayer;
11
+
12
+import java.awt.BorderLayout;
13
+import java.awt.Dimension;
14
+import java.awt.event.ActionEvent;
15
+import java.awt.event.ActionListener;
16
+import java.awt.event.KeyEvent;
17
+import java.awt.event.KeyListener;
18
+import javax.swing.JButton;
19
+
20
+import javax.swing.JDialog;
21
+import javax.swing.JLabel;
22
+import javax.swing.JSpinner;
23
+import javax.swing.SpinnerNumberModel;
24
+import javax.swing.border.EmptyBorder;
25
+
26
+/**
27
+ *
28
+ * @author Chris
29
+ */
30
+public class RaiseWindow extends JDialog implements ActionListener, KeyListener {
31
+    
32
+    private static final long serialVersionUID = 1;
33
+    
34
+    private final HumanPlayer player;
35
+    
36
+    private JSpinner raise;
37
+    
38
+    public RaiseWindow(final HumanPlayer player, final int minimum) {
39
+        super();
40
+        
41
+        this.player = player;
42
+        
43
+        setTitle("Enter amount to raise");
44
+        
45
+        setLayout(new BorderLayout(5, 5));
46
+        
47
+        JLabel label = new JLabel("Minimum: " + minimum + "; Maximum: " + player.getPlayer().getCash());
48
+        label.setPreferredSize(new Dimension(300, 20));
49
+        label.setBorder(new EmptyBorder(5, 5, 5, 5));
50
+        add(label, BorderLayout.NORTH);
51
+        
52
+        raise = new JSpinner(new SpinnerNumberModel(minimum, minimum, player.getPlayer().getCash(), 10));
53
+        raise.setPreferredSize(new Dimension(300, 20));
54
+        raise.addKeyListener(this);
55
+        add(raise);
56
+        
57
+        JButton button = new JButton("Raise");
58
+        button.addActionListener(this);
59
+        button.setPreferredSize(new Dimension(300, 25));
60
+        button.setDefaultCapable(true);
61
+        add(button, BorderLayout.SOUTH);
62
+        
63
+        getRootPane().setDefaultButton(button);
64
+        
65
+        pack();
66
+        
67
+        setLocationRelativeTo(player.getWindow());
68
+        
69
+        setVisible(true);
70
+        setResizable(false);
71
+        
72
+        addKeyListener(this);
73
+    }
74
+    
75
+    public void actionPerformed(ActionEvent e) {
76
+        synchronized(player) {
77
+            player.bet = (Integer) raise.getValue();
78
+            player.notify();
79
+        }
80
+        
81
+        this.dispose();
82
+    }
83
+    
84
+    public void keyTyped(KeyEvent e) {
85
+        // Do nothing
86
+    }
87
+    
88
+    public void keyPressed(KeyEvent e) {
89
+        if (e.getKeyCode() == KeyEvent.VK_ENTER) {
90
+            synchronized(player) {
91
+                player.bet = (Integer) raise.getValue();
92
+                player.notify();
93
+            }
94
+            
95
+            this.dispose();
96
+        }
97
+    }
98
+    
99
+    public void keyReleased(KeyEvent e) {
100
+        // Do nothing
101
+    }
102
+    
103
+}

+ 73
- 0
src/com/md87/cardgame/Rank.java View File

@@ -0,0 +1,73 @@
1
+/*
2
+ * Copyright (c) Chris 'MD87' Smith, 2007. All rights reserved.
3
+ *
4
+ * This code may not be redistributed without prior permission from the
5
+ * aforementioned copyright holder(s).
6
+ */
7
+
8
+package com.md87.cardgame;
9
+
10
+/**
11
+ * Defines the standard ranks in a pack of cards.
12
+ * 
13
+ * @author Chris
14
+ */
15
+public enum Rank {
16
+    
17
+    ACE,
18
+    KING,
19
+    QUEEN,
20
+    JACK,
21
+    TEN,
22
+    NINE,
23
+    EIGHT,
24
+    SEVEN,
25
+    SIX,
26
+    FIVE,
27
+    FOUR,
28
+    THREE,
29
+    DEUCE;
30
+   
31
+    /**
32
+     * Retrieves the rank that is one lower than this one, or null if this is
33
+     * the lowest rank (deuce).
34
+     * 
35
+     * @return The next lower rank
36
+     */
37
+    public Rank getLower() {
38
+        for (Rank target : values()) {
39
+            if (target.compareTo(this) == 1) {
40
+                return target;
41
+            }
42
+        }
43
+        
44
+        return null;
45
+    }
46
+    
47
+    /**
48
+     * Returns a nicely capitalised version of this rank's name.
49
+     * 
50
+     * @return A capitalised version of this rank's name
51
+     */
52
+    public String capitalise() {
53
+        return this.toString().substring(0, 1) + this.toString().substring(1).toLowerCase();
54
+    }
55
+
56
+    public int compareTo(final Rank o, final boolean acesLow) {
57
+        // ^ is the XOR operator
58
+        if (acesLow && (this == ACE ^ o == ACE)) {
59
+            int thisPos = ordinal();
60
+            int thatPos = o.ordinal();
61
+            
62
+            if (this == ACE) {
63
+                thisPos = DEUCE.ordinal() + 1;
64
+            } else if (o == ACE) {
65
+                thatPos = DEUCE.ordinal() + 1;
66
+            }
67
+            
68
+            return thisPos - thatPos;
69
+        } else {
70
+            return compareTo(o);
71
+        }
72
+    }
73
+}

+ 22
- 0
src/com/md87/cardgame/Suit.java View File

@@ -0,0 +1,22 @@
1
+/*
2
+ * Copyright (c) Chris 'MD87' Smith, 2007. All rights reserved.
3
+ *
4
+ * This code may not be redistributed without prior permission from the
5
+ * aforementioned copyright holder(s).
6
+ */
7
+
8
+package com.md87.cardgame;
9
+
10
+/**
11
+ * Defines the standard suits used in a pack of cards.
12
+ * 
13
+ * @author Chris
14
+ */
15
+public enum Suit {
16
+    
17
+    CLUBS,
18
+    SPADES,
19
+    DIAMONDS,
20
+    HEARTS;
21
+
22
+}

+ 127
- 0
src/com/md87/cardgame/config/BettingPanel.java View File

@@ -0,0 +1,127 @@
1
+/*
2
+ * Copyright (c) Chris 'MD87' Smith, 2007. All rights reserved.
3
+ *
4
+ * This code may not be redistributed without prior permission from the
5
+ * aforementioned copyright holder(s).
6
+ */
7
+
8
+package com.md87.cardgame.config;
9
+
10
+import java.awt.event.ActionEvent;
11
+import java.awt.event.ActionListener;
12
+import java.util.ArrayList;
13
+import java.util.List;
14
+import javax.swing.BorderFactory;
15
+import javax.swing.JLabel;
16
+import javax.swing.JPanel;
17
+import javax.swing.JRadioButton;
18
+import javax.swing.JSpinner;
19
+import javax.swing.SpinnerNumberModel;
20
+import javax.swing.SwingConstants;
21
+
22
+import net.miginfocom.swing.MigLayout;
23
+
24
+/**
25
+ *
26
+ * @author Chris
27
+ */
28
+public class BettingPanel extends JPanel implements ActionListener {
29
+
30
+    private static final long serialVersionUID = 1;
31
+
32
+    private final JPanel panel1 = new JPanel();
33
+    private final JPanel panel2 = new JPanel();
34
+    private final JPanel panel3 = new JPanel();
35
+
36
+    private final List<JRadioButton> types = new ArrayList<JRadioButton>();
37
+
38
+    private final JSpinner ante = new JSpinner(new SpinnerNumberModel(0, 0, 100000, 10));
39
+    private final JSpinner bringin = new JSpinner(new SpinnerNumberModel(0, 0, 100000, 10));
40
+    private final JSpinner bigblind = new JSpinner(new SpinnerNumberModel(100, 0, 100000, 10));
41
+    private final JSpinner smallblind = new JSpinner(new SpinnerNumberModel(50, 0, 100000, 10));
42
+
43
+    private final JSpinner raises = new JSpinner(new SpinnerNumberModel(4, -1, 100, 1));
44
+
45
+    public BettingPanel() {
46
+        panel1.setBorder(BorderFactory.createTitledBorder(" Limit type "));
47
+        panel1.setLayout(new MigLayout("fillx"));
48
+
49
+        JRadioButton limitType;
50
+
51
+        limitType = new JRadioButton("Fixed limit", false);
52
+        limitType.addActionListener(this);
53
+        limitType.setEnabled(false);
54
+        types.add(limitType);
55
+        panel1.add(limitType, "wrap, growx");
56
+
57
+        limitType = new JRadioButton("No limit", true);
58
+        limitType.addActionListener(this);
59
+        limitType.setEnabled(false);
60
+        types.add(limitType);
61
+        panel1.add(limitType, "wrap, growx");
62
+
63
+        limitType = new JRadioButton("Pot limit", false);
64
+        limitType.addActionListener(this);
65
+        limitType.setEnabled(false);
66
+        types.add(limitType);
67
+        panel1.add(limitType, "wrap, growx");
68
+
69
+        limitType = new JRadioButton("Spread limit", false);
70
+        limitType.addActionListener(this);
71
+        limitType.setEnabled(false);
72
+        types.add(limitType);
73
+        panel1.add(limitType, "wrap, growx");
74
+
75
+        panel2.setBorder(BorderFactory.createTitledBorder(" Options "));
76
+        panel2.setLayout(new MigLayout("fillx"));
77
+
78
+        panel2.add(new JLabel("Max raises:", SwingConstants.RIGHT), "growx");
79
+        panel2.add(raises, "wrap, growx");
80
+
81
+        panel3.setBorder(BorderFactory.createTitledBorder(" Forced bets "));
82
+        panel3.setLayout(new MigLayout("fillx"));
83
+
84
+        panel3.add(new JLabel("Big blind:", SwingConstants.RIGHT), "growx");
85
+        panel3.add(bigblind, "wrap, growx");
86
+
87
+        smallblind.setEnabled(false);
88
+        panel3.add(new JLabel("Small blind:", SwingConstants.RIGHT), "growx");
89
+        panel3.add(smallblind, "wrap, growx");
90
+        
91
+        panel3.add(new JLabel("Ante:", SwingConstants.RIGHT), "growx");
92
+        panel3.add(ante, "wrap, growx");        
93
+        
94
+        bringin.setEnabled(false);
95
+        panel3.add(new JLabel("Bring-in:", SwingConstants.RIGHT), "growx");
96
+        panel3.add(bringin, "wrap, growx");                
97
+
98
+        setLayout(new MigLayout("gap 10 10, fill"));
99
+
100
+        add(panel1, "grow, width 50%");
101
+        add(panel2, "grow, width 50%, spany 2, wrap");
102
+        add(panel3, "grow, width 50%");
103
+    }
104
+
105
+    public int getAnte() {
106
+        return (Integer) ante.getValue();
107
+    }
108
+
109
+    public int getBigBlind() {
110
+        return (Integer) bigblind.getValue();
111
+    }
112
+
113
+    public int getRaises() {
114
+        return (Integer) raises.getValue();
115
+    }
116
+
117
+    public void actionPerformed(ActionEvent e) {
118
+        for (JRadioButton button : types) {
119
+            if (button.equals(e.getSource())) {
120
+                button.setSelected(true);
121
+            } else {
122
+                button.setSelected(false);
123
+            }
124
+        }
125
+    }
126
+
127
+}

+ 128
- 0
src/com/md87/cardgame/config/ConfigScreen.java View File

@@ -0,0 +1,128 @@
1
+/*
2
+ * Copyright (c) Chris 'MD87' Smith, 2007. All rights reserved.
3
+ *
4
+ * This code may not be redistributed without prior permission from the
5
+ * aforementioned copyright holder(s).
6
+ */
7
+
8
+package com.md87.cardgame.config;
9
+
10
+import com.md87.cardgame.ui.GameWindow;
11
+import com.md87.cardgame.Player;
12
+import com.md87.cardgame.config.games.GameInfo;
13
+import com.md87.cardgame.interfaces.Game;
14
+
15
+import java.awt.BorderLayout;
16
+import java.awt.Image;
17
+import java.awt.event.ActionEvent;
18
+import java.awt.event.ActionListener;
19
+import java.io.IOException;
20
+
21
+import javax.imageio.ImageIO;
22
+import javax.swing.BorderFactory;
23
+import javax.swing.ImageIcon;
24
+import javax.swing.JButton;
25
+import javax.swing.JDialog;
26
+import javax.swing.JPanel;
27
+import javax.swing.JTabbedPane;
28
+import javax.swing.WindowConstants;
29
+
30
+/**
31
+ *
32
+ * @author Chris
33
+ */
34
+public class ConfigScreen extends JDialog {
35
+    
36
+    private static final long serialVersionUID = 1;
37
+    
38
+    private final JTabbedPane tabbedPane = new JTabbedPane();
39
+    private final PlayerPanel playerPanel = new PlayerPanel();
40
+    private final GamePanel gamePanel = new GamePanel(this);
41
+    private final BettingPanel bettingPanel = new BettingPanel();
42
+    private final JPanel savePanel = new JPanel();
43
+    
44
+    private GameInfo game;
45
+
46
+    public ConfigScreen() {
47
+        super();
48
+        
49
+        Image gameIcon = null;
50
+        Image playerIcon = null;
51
+        Image moneyIcon = null;
52
+        Image saveIcon = null;
53
+        
54
+        try {
55
+            gameIcon = ImageIO.read(getClass().getResource("/com/md87/cardgame/res/icon.png"));
56
+            playerIcon = ImageIO.read(getClass().getResource("/com/md87/cardgame/res/user.png"));
57
+            moneyIcon = ImageIO.read(getClass().getResource("/com/md87/cardgame/res/money.png"));
58
+            saveIcon = ImageIO.read(getClass().getResource("/com/md87/cardgame/res/save.png"));
59
+        } catch (IOException ex) {
60
+            System.err.println("Unable to load icons");
61
+        }   
62
+        
63
+        setIconImage(gameIcon);
64
+        
65
+        setTitle("JaPoker: Game configuration");
66
+        
67
+        tabbedPane.addTab("Game type", new ImageIcon(gameIcon), gamePanel);
68
+        tabbedPane.addTab("Players", new ImageIcon(playerIcon), playerPanel);
69
+        tabbedPane.addTab("Betting", new ImageIcon(moneyIcon), bettingPanel);
70
+        tabbedPane.addTab("Save/Load", new ImageIcon(saveIcon), savePanel);
71
+        
72
+        tabbedPane.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
73
+        
74
+        setLayout(new BorderLayout());
75
+        add(tabbedPane, BorderLayout.NORTH);
76
+        
77
+        final JButton netButton = new JButton("Join Network Game");
78
+        netButton.setEnabled(false);
79
+        JPanel buttonPanel = new JPanel();
80
+        buttonPanel.setBorder(BorderFactory.createEmptyBorder(0, 20, 20, 20));
81
+        buttonPanel.add(netButton);
82
+        add(buttonPanel, BorderLayout.WEST);
83
+        
84
+        final JButton startButton = new JButton("Start Game");
85
+        buttonPanel = new JPanel();
86
+        buttonPanel.setBorder(BorderFactory.createEmptyBorder(0, 20, 20, 20));
87
+        buttonPanel.add(startButton);        
88
+        add(buttonPanel, BorderLayout.EAST);
89
+        
90
+        startButton.addActionListener(new ActionListener() {
91
+            @Override
92
+            public void actionPerformed(ActionEvent e) {
93
+                startGame();
94
+            }
95
+        });
96
+        
97
+        pack();
98
+        setVisible(true);
99
+        setResizable(false);
100
+        
101
+        setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
102
+    }
103
+    
104
+    public void setGame(final GameInfo newGame) {
105
+        game = newGame;
106
+        
107
+        playerPanel.setMaxPlayers(game.getNumPlayers());
108
+    }
109
+    
110
+    public GameInfo getGame() {
111
+        return game;
112
+    }
113
+    
114
+    private void startGame() {
115
+        final Game myGame = game.getGame(playerPanel.getNumPlayers(), 
116
+                bettingPanel.getBigBlind(), bettingPanel.getAnte(), 
117
+                bettingPanel.getRaises());
118
+        final GameWindow window = new GameWindow(myGame);
119
+        
120
+        for (Player player : playerPanel.getPlayers(myGame, window)) {
121
+            myGame.addPlayer(player);
122
+        }
123
+        
124
+        myGame.startTournament();
125
+        dispose();
126
+    }
127
+
128
+}

+ 80
- 0
src/com/md87/cardgame/config/GamePanel.java View File

@@ -0,0 +1,80 @@
1
+/*
2
+ * Copyright (c) Chris 'MD87' Smith, 2007. All rights reserved.
3
+ *
4
+ * This code may not be redistributed without prior permission from the
5
+ * aforementioned copyright holder(s).
6
+ */
7
+
8
+package com.md87.cardgame.config;
9
+
10
+import com.md87.cardgame.config.games.GameInfo;
11
+import java.awt.event.ActionEvent;
12
+import java.awt.event.ActionListener;
13
+import java.util.HashMap;
14
+import java.util.Map;
15
+import java.util.Map;
16
+
17
+import javax.swing.JPanel;
18
+import javax.swing.JRadioButton;
19
+import javax.swing.JSeparator;
20
+
21
+import net.miginfocom.swing.MigLayout;
22
+
23
+/**
24
+ *
25
+ * @author Chris
26
+ */
27
+public class GamePanel extends JPanel implements ActionListener {
28
+    
29
+    private static final long serialVersionUID = 1;
30
+
31
+    private final Map<GameInfo, JRadioButton> games = new HashMap<GameInfo, JRadioButton>();
32
+    
33
+    private final ConfigScreen owner;
34
+    
35
+    public GamePanel(final ConfigScreen owner) {
36
+        this.owner = owner;
37
+        
38
+        setLayout(new MigLayout("flowy, fill"));
39
+        
40
+        GameInfo.GameType type = GameInfo.GameType.HOLDEM;
41
+        
42
+        for (GameInfo game : GameInfo.getGames()) {
43
+            JRadioButton button = buildButton(game);
44
+            
45
+            if (type != game.getGameType()) {
46
+                type = game.getGameType();
47
+                
48
+                add(new JSeparator(), "growx");
49
+            }
50
+            
51
+            add(button);
52
+        }
53
+    }
54
+    
55
+    private JRadioButton buildButton(final GameInfo game) {
56
+        final JRadioButton res = new JRadioButton(game.getName());
57
+
58
+        if (games.size() == 0) {
59
+            res.setSelected(true);
60
+            owner.setGame(game);
61
+        }
62
+        
63
+        res.addActionListener(this);
64
+        games.put(game, res);
65
+        
66
+        return res;
67
+    }
68
+    
69
+    public void actionPerformed(ActionEvent e) {
70
+        for (Map.Entry<GameInfo, JRadioButton> entry : games.entrySet()) {
71
+            if (entry.getValue().equals(e.getSource())) {
72
+                owner.setGame(entry.getKey());
73
+                entry.getValue().setSelected(true);
74
+            } else {
75
+                entry.getValue().setSelected(false);
76
+            }
77
+        }
78
+    }
79
+    
80
+}

+ 139
- 0
src/com/md87/cardgame/config/PlayerPanel.java View File

@@ -0,0 +1,139 @@
1
+/*
2
+ * Copyright (c) Chris 'MD87' Smith, 2007. All rights reserved.
3
+ *
4
+ * This code may not be redistributed without prior permission from the
5
+ * aforementioned copyright holder(s).
6
+ */
7
+
8
+package com.md87.cardgame.config;
9
+
10
+import com.md87.cardgame.ui.GameWindow;
11
+import com.md87.cardgame.Player;
12
+import com.md87.cardgame.config.controllers.ControllerInfo;
13
+import com.md87.cardgame.interfaces.Game;
14
+
15
+import java.awt.Dimension;
16
+import java.awt.GridBagConstraints;
17
+import java.awt.GridBagLayout;
18
+import java.util.ArrayList;
19
+import java.util.List;
20
+
21
+import javax.swing.BorderFactory;
22
+import javax.swing.JCheckBox;
23
+import javax.swing.JComboBox;
24
+import javax.swing.JPanel;
25
+import javax.swing.JSpinner;
26
+import javax.swing.JTextField;
27
+import javax.swing.SpinnerNumberModel;
28
+
29
+/**
30
+ *
31
+ * @author Chris
32
+ */
33
+public class PlayerPanel extends JPanel {
34
+    
35
+    private static final int MAXPLAYERS = 14;
36
+    
37
+    private final JPanel innerPanel = new JPanel();
38
+    
39
+    private final List<JCheckBox> checkBoxes = new ArrayList<JCheckBox>();
40
+    private final List<JTextField> textFields = new ArrayList<JTextField>();
41
+    private final List<JSpinner> spinners = new ArrayList<JSpinner>();
42
+    private final List<JComboBox> comboBoxes = new ArrayList<JComboBox>();
43
+    
44
+    public PlayerPanel() {
45
+        super();
46
+        
47
+        innerPanel.setLayout(new GridBagLayout());
48
+        
49
+        final GridBagConstraints constraints = new GridBagConstraints();
50
+        constraints.insets.set(3, 3, 3, 3);
51
+        
52
+        for (int i = 0; i < MAXPLAYERS; i++) {
53
+            final JCheckBox cb = new JCheckBox();
54
+            if (i < 4) {
55
+                cb.setSelected(true);
56
+                if (i < 2) {
57
+                    cb.setEnabled(false);
58
+                }
59
+            }
60
+            
61
+            final JTextField tf = new JTextField();
62
+            tf.setText("Player " + (i + 1));
63
+            tf.setPreferredSize(new Dimension(130, 20));
64
+            
65
+            final JSpinner sp = new JSpinner(new SpinnerNumberModel(1500, 100, 1000000000, 100));
66
+            sp.setPreferredSize(new Dimension(100, 20));
67
+            
68
+            final JComboBox co = new JComboBox(ControllerInfo.getControllers());
69
+            co.setPreferredSize(new Dimension(160, 20));
70
+            
71
+            if (i > 0) {
72
+                co.setSelectedIndex(3);
73
+            }
74
+            
75
+            checkBoxes.add(cb);
76
+            textFields.add(tf);
77
+            spinners.add(sp);
78
+            comboBoxes.add(co);
79
+            
80
+            constraints.gridy = i;
81
+            constraints.gridx = 0;
82
+            innerPanel.add(cb, constraints);
83
+            constraints.gridx++;
84
+            innerPanel.add(tf, constraints);
85
+            constraints.gridx++;
86
+            innerPanel.add(sp, constraints);
87
+            constraints.gridx++;
88
+            innerPanel.add(co, constraints);
89
+        }
90
+        
91
+        innerPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
92
+        
93
+        add(innerPanel);
94
+    }
95
+    
96
+    public void setMaxPlayers(final int maxPlayers) {
97
+        for (int i = 2; i < MAXPLAYERS; i++) {
98
+            if (i < maxPlayers) {
99
+                checkBoxes.get(i).setEnabled(true);
100
+                textFields.get(i).setEnabled(true);
101
+                spinners.get(i).setEnabled(true);
102
+                comboBoxes.get(i).setEnabled(true);
103
+            } else {
104
+                checkBoxes.get(i).setSelected(false);
105
+                checkBoxes.get(i).setEnabled(false);
106
+                textFields.get(i).setEnabled(false);
107
+                spinners.get(i).setEnabled(false);
108
+                comboBoxes.get(i).setEnabled(false);                
109
+            }
110
+        }
111
+    }
112
+    
113
+    public int getNumPlayers() {
114
+        int res = 0;
115
+        
116
+        for (int i = 0; i < MAXPLAYERS; i++) {
117
+            if (checkBoxes.get(i).isSelected()) {
118
+                res++;
119
+            }
120
+        }
121
+        
122
+        return res;
123
+    }
124
+    
125
+    public List<Player> getPlayers(final Game game, final GameWindow window) {
126
+        final List<Player> res = new ArrayList<Player>();
127
+        
128
+        for (int i = 0; i < MAXPLAYERS; i++) {
129
+            if (checkBoxes.get(i).isSelected()) {
130
+                res.add(new Player(game, textFields.get(i).getText(), 
131
+                        (Integer) spinners.get(i).getValue(),
132
+                        ((ControllerInfo) comboBoxes.get(i).getSelectedItem())
133
+                        .getController(game, window)));
134
+            }
135
+        }
136
+        
137
+        return res;
138
+    }
139
+}

+ 32
- 0
src/com/md87/cardgame/config/controllers/ConservativeOpenerInfo.java View File

@@ -0,0 +1,32 @@
1
+/*
2
+ * Copyright (c) Chris 'MD87' Smith, 2007. All rights reserved.
3
+ *
4
+ * This code may not be redistributed without prior permission from the
5
+ * aforementioned copyright holder(s).
6
+ */
7
+
8
+package com.md87.cardgame.config.controllers;
9
+
10
+import com.md87.cardgame.ui.GameWindow;
11
+import com.md87.cardgame.controllers.ConservativeOpener;
12
+import com.md87.cardgame.interfaces.Game;
13
+import com.md87.cardgame.interfaces.PlayerController;
14
+
15
+/**
16
+ *
17
+ * @author Chris
18
+ */
19
+public class ConservativeOpenerInfo extends ControllerInfo {
20
+
21
+    public ConservativeOpenerInfo() {
22
+    }
23
+
24
+    public String getName() {
25
+        return "AI: Conservative Opener";
26
+    }
27
+
28
+    public PlayerController getController(final Game game, final GameWindow gameWindow) {
29
+        return new ConservativeOpener();
30
+    }
31
+
32
+}

+ 37
- 0
src/com/md87/cardgame/config/controllers/ControllerInfo.java View File

@@ -0,0 +1,37 @@
1
+/*
2
+ * Copyright (c) Chris 'MD87' Smith, 2007. All rights reserved.
3
+ *
4
+ * This code may not be redistributed without prior permission from the
5
+ * aforementioned copyright holder(s).
6
+ */
7
+
8
+package com.md87.cardgame.config.controllers;
9
+
10
+import com.md87.cardgame.ui.GameWindow;
11
+import com.md87.cardgame.interfaces.Game;
12
+import com.md87.cardgame.interfaces.PlayerController;
13
+
14
+/**
15
+ *
16
+ * @author Chris
17
+ */
18
+public abstract class ControllerInfo {
19
+
20
+    public abstract String getName();
21
+    
22
+    public abstract PlayerController getController(final Game game, final GameWindow gameWindow);
23
+    
24
+    public String toString() {
25
+        return getName();
26
+    }
27
+    
28
+    public static ControllerInfo[] getControllers() {
29
+        return new ControllerInfo[]{
30
+            new HumanPlayerInfo(),
31
+            new ConservativeOpenerInfo(),
32
+            new EndGameInfo(),
33
+            new RandomPlayerInfo()
34
+        };
35
+    }
36
+
37
+}

+ 32
- 0
src/com/md87/cardgame/config/controllers/EndGameInfo.java View File

@@ -0,0 +1,32 @@
1
+/*
2
+ * Copyright (c) Chris 'MD87' Smith, 2007. All rights reserved.
3
+ *
4
+ * This code may not be redistributed without prior permission from the
5
+ * aforementioned copyright holder(s).
6
+ */
7
+
8
+package com.md87.cardgame.config.controllers;
9
+
10
+import com.md87.cardgame.ui.GameWindow;
11
+import com.md87.cardgame.controllers.EndGameAI;
12
+import com.md87.cardgame.interfaces.Game;
13
+import com.md87.cardgame.interfaces.PlayerController;
14
+
15
+/**
16
+ *
17
+ * @author Chris
18
+ */
19
+public class EndGameInfo extends ControllerInfo {
20
+    
21
+    public EndGameInfo() {
22
+    }
23
+    
24
+    public String getName() {
25
+        return "AI: End Gamer";
26
+    }
27
+    
28
+    public PlayerController getController(final Game game, final GameWindow gameWindow) {
29
+        return new EndGameAI(game);
30
+    }
31
+    
32
+}

+ 32
- 0
src/com/md87/cardgame/config/controllers/HumanPlayerInfo.java View File

@@ -0,0 +1,32 @@
1
+/*
2
+ * Copyright (c) Chris 'MD87' Smith, 2007. All rights reserved.
3
+ *
4
+ * This code may not be redistributed without prior permission from the
5
+ * aforementioned copyright holder(s).
6
+ */
7
+
8
+package com.md87.cardgame.config.controllers;
9
+
10
+import com.md87.cardgame.ui.GameWindow;
11
+import com.md87.cardgame.controllers.HumanPlayer;
12
+import com.md87.cardgame.interfaces.Game;
13
+import com.md87.cardgame.interfaces.PlayerController;
14
+
15
+/**
16
+ *
17
+ * @author Chris
18
+ */
19
+public class HumanPlayerInfo extends ControllerInfo {
20
+    
21
+    public HumanPlayerInfo() {
22
+    }
23
+    
24
+    public String getName() {
25
+        return "Human: Local Player";
26
+    }
27
+    
28
+    public PlayerController getController(final Game game, final GameWindow gameWindow) {
29
+        return new HumanPlayer(gameWindow);
30
+    }
31
+
32
+}

+ 32
- 0
src/com/md87/cardgame/config/controllers/RandomPlayerInfo.java View File

@@ -0,0 +1,32 @@
1
+/*
2
+ * Copyright (c) Chris 'MD87' Smith, 2007. All rights reserved.
3
+ *
4
+ * This code may not be redistributed without prior permission from the
5
+ * aforementioned copyright holder(s).
6
+ */
7
+
8
+package com.md87.cardgame.config.controllers;
9
+
10
+import com.md87.cardgame.ui.GameWindow;
11
+import com.md87.cardgame.controllers.RandomPlayer;
12
+import com.md87.cardgame.interfaces.Game;
13
+import com.md87.cardgame.interfaces.PlayerController;
14
+
15
+/**
16
+ *
17
+ * @author Chris
18
+ */
19
+public class RandomPlayerInfo extends ControllerInfo {
20
+    
21
+    public RandomPlayerInfo() {
22
+    }
23
+    
24
+    public String getName() {
25
+        return "AI: Random Player";
26
+    }
27
+    
28
+    public PlayerController getController(final Game game, final GameWindow gameWindow) {
29
+        return new RandomPlayer();
30
+    }
31
+    
32
+}

+ 39
- 0
src/com/md87/cardgame/config/games/AsianFiveCardStudInfo.java View File

@@ -0,0 +1,39 @@
1
+/*
2
+ * Copyright (c) Chris 'MD87' Smith, 2007. All rights reserved.
3
+ *
4
+ * This code may not be redistributed without prior permission from the
5
+ * aforementioned copyright holder(s).
6
+ */
7
+
8
+package com.md87.cardgame.config.games;
9
+
10
+import com.md87.cardgame.games.AsianFiveCardStud;
11
+import com.md87.cardgame.interfaces.Game;
12
+
13
+/**
14
+ *
15
+ * @author Chris
16
+ */
17
+public class AsianFiveCardStudInfo extends GameInfo {
18
+
19
+    public String getName() {
20
+        return "Asian 5-Card Stud";
21
+    }
22
+
23
+    public GameType getGameType() {
24
+        return GameInfo.GameType.STUD;
25
+    }
26
+
27
+    public int getNumPlayers() {
28
+        return 6;
29
+    }
30
+
31
+    public boolean usesBringIns() {
32
+        return true;
33
+    }
34
+
35
+    public Game getGame(int numplayers, int bigblind, int ante, int raises) {
36
+        return new AsianFiveCardStud(numplayers, bigblind, ante, raises);
37
+    }
38
+
39
+}

+ 39
- 0
src/com/md87/cardgame/config/games/CourchevelInfo.java View File

@@ -0,0 +1,39 @@
1
+/*
2
+ * Copyright (c) Chris 'MD87' Smith, 2007. All rights reserved.
3
+ *
4
+ * This code may not be redistributed without prior permission from the
5
+ * aforementioned copyright holder(s).
6
+ */
7
+
8
+package com.md87.cardgame.config.games;
9
+
10
+import com.md87.cardgame.games.Courchevel;
11
+import com.md87.cardgame.interfaces.Game;
12
+
13
+/**
14
+ *
15
+ * @author Chris
16
+ */
17
+public class CourchevelInfo extends GameInfo {
18
+
19
+    public String getName() {
20
+        return "Courchevel";
21
+    }
22
+
23
+    public GameType getGameType() {
24
+        return GameInfo.GameType.HOLDEM;
25
+    }
26
+
27
+    public int getNumPlayers() {
28
+        return 10;
29
+    }
30
+
31
+    public boolean usesBringIns() {
32
+        return false;
33
+    }
34
+
35
+    public Game getGame(int numplayers, int bigblind, int ante, int raises) {
36
+        return new Courchevel(numplayers, bigblind, ante, raises);
37
+    }
38
+
39
+}

+ 39
- 0
src/com/md87/cardgame/config/games/CrazyPineappleInfo.java View File

@@ -0,0 +1,39 @@
1
+/*
2
+ * Copyright (c) Chris 'MD87' Smith, 2007. All rights reserved.
3
+ *
4
+ * This code may not be redistributed without prior permission from the
5
+ * aforementioned copyright holder(s).
6
+ */
7
+
8
+package com.md87.cardgame.config.games;
9
+
10
+import com.md87.cardgame.games.CrazyPineapple;
11
+import com.md87.cardgame.interfaces.Game;
12
+
13
+/**
14
+ *
15
+ * @author Chris
16
+ */
17
+public class CrazyPineappleInfo extends GameInfo {
18
+
19
+    public String getName() {
20
+        return "Crazy Pineapple";
21
+    }
22
+
23
+    public GameType getGameType() {
24
+        return GameInfo.GameType.HOLDEM;
25
+    }
26
+
27
+    public int getNumPlayers() {
28
+        return 14;
29
+    }
30
+
31
+    public boolean usesBringIns() {
32
+        return false;
33
+    }
34
+
35
+    public Game getGame(int numplayers, int bigblind, int ante, int raises) {
36
+        return new CrazyPineapple(numplayers, bigblind, ante, raises);
37
+    }
38
+
39
+}

+ 44
- 0
src/com/md87/cardgame/config/games/FiveCardDrawInfo.java View File

@@ -0,0 +1,44 @@
1
+/*
2
+ * Copyright (c) Chris 'MD87' Smith, 2007. All rights reserved.
3
+ *
4
+ * This code may not be redistributed without prior permission from the
5
+ * aforementioned copyright holder(s).
6
+ */
7
+
8
+package com.md87.cardgame.config.games;
9
+
10
+import com.md87.cardgame.games.FiveCardDraw;
11
+import com.md87.cardgame.interfaces.Game;
12
+
13
+/**
14
+ *
15
+ * @author chris
16
+ */
17
+public class FiveCardDrawInfo extends GameInfo {
18
+
19
+    @Override
20
+    public String getName() {
21
+        return "Five Card Draw";
22
+    }
23
+
24
+    @Override
25
+    public GameType getGameType() {
26
+        return GameInfo.GameType.DRAW;
27
+    }
28
+
29
+    @Override
30
+    public int getNumPlayers() {
31
+        return 10;
32
+    }
33
+
34
+    @Override
35
+    public boolean usesBringIns() {
36
+        return false;
37
+    }
38
+
39
+    @Override
40
+    public Game getGame(int numplayers, int bigblind, int ante, int raises) {
41
+        return new FiveCardDraw(numplayers, bigblind, ante, raises);
42
+    }
43
+
44
+}

+ 39
- 0
src/com/md87/cardgame/config/games/FiveCardStudInfo.java View File

@@ -0,0 +1,39 @@
1
+/*
2
+ * Copyright (c) Chris 'MD87' Smith, 2007. All rights reserved.
3
+ *
4
+ * This code may not be redistributed without prior permission from the
5
+ * aforementioned copyright holder(s).
6
+ */
7
+
8
+package com.md87.cardgame.config.games;
9
+
10
+import com.md87.cardgame.games.FiveCardStud;
11
+import com.md87.cardgame.interfaces.Game;
12
+
13
+/**
14
+ *
15
+ * @author Chris
16
+ */
17
+public class FiveCardStudInfo extends GameInfo {
18
+
19
+    public String getName() {
20
+        return "5-Card Stud";
21
+    }
22
+
23
+    public GameType getGameType() {
24
+        return GameInfo.GameType.STUD;
25
+    }
26
+
27
+    public int getNumPlayers() {
28
+        return 10;
29
+    }
30
+
31
+    public boolean usesBringIns() {
32
+        return true;
33
+    }
34
+
35
+    public Game getGame(int numplayers, int bigblind, int ante, int raises) {
36
+        return new FiveCardStud(numplayers, bigblind, ante, raises);
37
+    }
38
+
39
+}

+ 52
- 0
src/com/md87/cardgame/config/games/GameInfo.java View File

@@ -0,0 +1,52 @@
1
+/*
2
+ * Copyright (c) Chris 'MD87' Smith, 2007. All rights reserved.
3
+ *
4
+ * This code may not be redistributed without prior permission from the
5
+ * aforementioned copyright holder(s).
6
+ */
7
+
8
+package com.md87.cardgame.config.games;
9
+
10
+import com.md87.cardgame.interfaces.Game;
11
+
12
+/**
13
+ *
14
+ * @author Chris
15
+ */
16
+public abstract class GameInfo {
17
+    
18
+    public static enum GameType  {
19
+        STUD, DRAW, HOLDEM
20
+    };
21
+    
22
+    public abstract String getName();
23
+    
24
+    public abstract GameType getGameType();
25
+    
26
+    public abstract int getNumPlayers();
27
+    
28
+    public abstract boolean usesBringIns();
29
+    
30
+    public abstract Game getGame(final int numplayers, final int bigblind, final int ante,
31
+            final int raises);
32
+    
33
+    public static GameInfo[] getGames() {
34
+        return new GameInfo[]{
35
+            new TexasHoldEmInfo(),
36
+            new PineappleInfo(),
37
+            new CrazyPineappleInfo(),
38
+            new RoyalHoldEmInfo(),
39
+            new SuperHoldEmInfo(),
40
+            new OmahaHoldEmInfo(),
41
+            new OmahaHighLowInfo(),
42
+            new CourchevelInfo(),
43
+            
44
+            new FiveCardDrawInfo(),
45
+
46
+            new FiveCardStudInfo(),            
47
+            new SevenCardStudInfo(),
48
+            new AsianFiveCardStudInfo(),
49
+        };
50
+    }
51
+    
52
+}

+ 39
- 0
src/com/md87/cardgame/config/games/OmahaHighLowInfo.java View File

@@ -0,0 +1,39 @@
1
+/*
2
+ * Copyright (c) Chris 'MD87' Smith, 2007. All rights reserved.
3
+ *
4
+ * This code may not be redistributed without prior permission from the
5
+ * aforementioned copyright holder(s).
6
+ */
7
+
8
+package com.md87.cardgame.config.games;
9
+
10
+import com.md87.cardgame.games.OmahaHighLow;
11
+import com.md87.cardgame.interfaces.Game;
12
+
13
+/**
14
+ *
15
+ * @author Chris
16
+ */
17
+public class OmahaHighLowInfo extends GameInfo {
18
+
19
+    public String getName() {
20
+        return "Omaha High/Low";
21
+    }
22
+
23
+    public GameType getGameType() {
24
+        return GameInfo.GameType.HOLDEM;
25
+    }
26
+
27
+    public int getNumPlayers() {
28
+        return 10;
29
+    }
30
+
31
+    public boolean usesBringIns() {
32
+        return false;
33
+    }
34
+
35
+    public Game getGame(int numplayers, int bigblind, int ante, int raises) {
36
+        return new OmahaHighLow(numplayers, bigblind, ante, raises);
37
+    }
38
+
39
+}

+ 39
- 0
src/com/md87/cardgame/config/games/OmahaHoldEmInfo.java View File

@@ -0,0 +1,39 @@
1
+/*
2
+ * Copyright (c) Chris 'MD87' Smith, 2007. All rights reserved.
3
+ *
4
+ * This code may not be redistributed without prior permission from the
5
+ * aforementioned copyright holder(s).
6
+ */
7
+
8
+package com.md87.cardgame.config.games;
9
+
10
+import com.md87.cardgame.games.OmahaHoldEm;
11
+import com.md87.cardgame.interfaces.Game;
12
+
13
+/**
14
+ *
15
+ * @author Chris
16
+ */
17
+public class OmahaHoldEmInfo extends GameInfo {
18
+
19
+    public String getName() {
20
+        return "Omaha Hold'Em";
21
+    }
22
+
23
+    public GameType getGameType() {
24
+        return GameInfo.GameType.HOLDEM;
25
+    }
26
+
27
+    public int getNumPlayers() {
28
+        return 10;
29
+    }
30
+
31
+    public boolean usesBringIns() {
32
+        return false;
33
+    }
34
+
35
+    public Game getGame(int numplayers, int bigblind, int ante, int raises) {
36
+        return new OmahaHoldEm(numplayers, bigblind, ante, raises);
37
+    }
38
+
39
+}

+ 39
- 0
src/com/md87/cardgame/config/games/PineappleInfo.java View File

@@ -0,0 +1,39 @@
1
+/*
2
+ * Copyright (c) Chris 'MD87' Smith, 2007. All rights reserved.
3
+ *
4
+ * This code may not be redistributed without prior permission from the
5
+ * aforementioned copyright holder(s).
6
+ */
7
+
8
+package com.md87.cardgame.config.games;
9
+
10
+import com.md87.cardgame.games.Pineapple;
11
+import com.md87.cardgame.interfaces.Game;
12
+
13
+/**
14
+ *
15
+ * @author Chris
16
+ */
17
+public class PineappleInfo extends GameInfo {
18
+
19
+    public String getName() {
20
+        return "Pineapple";
21
+    }
22
+
23
+    public GameType getGameType() {
24
+        return GameInfo.GameType.HOLDEM;
25
+    }
26
+
27
+    public int getNumPlayers() {
28
+        return 14;
29
+    }
30
+
31
+    public boolean usesBringIns() {
32
+        return false;
33
+    }
34
+
35
+    public Game getGame(int numplayers, int bigblind, int ante, int raises) {
36
+        return new Pineapple(numplayers, bigblind, ante, raises);
37
+    }
38
+
39
+}

+ 39
- 0
src/com/md87/cardgame/config/games/RoyalHoldEmInfo.java View File

@@ -0,0 +1,39 @@
1
+/*
2
+ * Copyright (c) Chris 'MD87' Smith, 2007. All rights reserved.
3
+ *
4
+ * This code may not be redistributed without prior permission from the
5
+ * aforementioned copyright holder(s).
6
+ */
7
+
8
+package com.md87.cardgame.config.games;
9
+
10
+import com.md87.cardgame.games.RoyalHoldEm;
11
+import com.md87.cardgame.interfaces.Game;
12
+
13
+/**
14
+ *
15
+ * @author Chris
16
+ */
17
+public class RoyalHoldEmInfo extends GameInfo {
18
+
19
+    public String getName() {
20
+        return "Royal Hold'Em";
21
+    }
22
+
23
+    public GameType getGameType() {
24
+        return GameInfo.GameType.HOLDEM;
25
+    }
26
+
27
+    public int getNumPlayers() {
28
+        return 6;
29
+    }
30
+
31
+    public boolean usesBringIns() {
32
+        return false;
33
+    }
34
+
35
+    public Game getGame(int numplayers, int bigblind, int ante, int raises) {
36
+        return new RoyalHoldEm(numplayers, bigblind, ante, raises);
37
+    }
38
+
39
+}

+ 39
- 0
src/com/md87/cardgame/config/games/SevenCardStudInfo.java View File

@@ -0,0 +1,39 @@
1
+/*
2
+ * Copyright (c) Chris 'MD87' Smith, 2007. All rights reserved.
3
+ *
4
+ * This code may not be redistributed without prior permission from the
5
+ * aforementioned copyright holder(s).
6
+ */
7
+
8
+package com.md87.cardgame.config.games;
9
+
10
+import com.md87.cardgame.games.SevenCardStud;
11
+import com.md87.cardgame.interfaces.Game;
12
+
13
+/**
14
+ *
15
+ * @author Chris
16
+ */
17
+public class SevenCardStudInfo extends GameInfo {
18
+
19
+    public String getName() {
20
+        return "7-Card Stud";
21
+    }
22
+
23
+    public GameType getGameType() {
24
+        return GameInfo.GameType.STUD;
25
+    }
26
+
27
+    public int getNumPlayers() {
28
+        return 8;
29
+    }
30
+
31
+    public boolean usesBringIns() {
32
+        return true;
33
+    }
34
+
35
+    public Game getGame(int numplayers, int bigblind, int ante, int raises) {
36
+        return new SevenCardStud(numplayers, bigblind, ante, raises);
37
+    }
38
+
39
+}

+ 39
- 0
src/com/md87/cardgame/config/games/SuperHoldEmInfo.java View File

@@ -0,0 +1,39 @@
1
+/*
2
+ * Copyright (c) Chris 'MD87' Smith, 2007. All rights reserved.
3
+ *
4
+ * This code may not be redistributed without prior permission from the
5
+ * aforementioned copyright holder(s).
6
+ */
7
+
8
+package com.md87.cardgame.config.games;
9
+
10
+import com.md87.cardgame.games.SuperHoldEm;
11
+import com.md87.cardgame.interfaces.Game;
12
+
13
+/**
14
+ *
15
+ * @author Chris
16
+ */
17
+public class SuperHoldEmInfo extends GameInfo {
18
+
19
+    public String getName() {
20
+        return "Super Hold'Em";
21
+    }
22
+
23
+    public GameType getGameType() {
24
+        return GameInfo.GameType.HOLDEM;
25
+    }
26
+
27
+    public int getNumPlayers() {
28
+        return 14;
29
+    }
30
+
31
+    public boolean usesBringIns() {
32
+        return false;
33
+    }
34
+
35
+    public Game getGame(int numplayers, int bigblind, int ante, int raises) {
36
+        return new SuperHoldEm(numplayers, bigblind, ante, raises);
37
+    }
38
+
39
+}

+ 39
- 0
src/com/md87/cardgame/config/games/TexasHoldEmInfo.java View File

@@ -0,0 +1,39 @@
1
+/*
2
+ * Copyright (c) Chris 'MD87' Smith, 2007. All rights reserved.
3
+ *
4
+ * This code may not be redistributed without prior permission from the
5
+ * aforementioned copyright holder(s).
6
+ */
7
+
8
+package com.md87.cardgame.config.games;
9
+
10
+import com.md87.cardgame.games.TexasHoldEm;
11
+import com.md87.cardgame.interfaces.Game;
12
+
13
+/**
14
+ *
15
+ * @author Chris
16
+ */
17
+public class TexasHoldEmInfo extends GameInfo {
18
+
19
+    public String getName() {
20
+        return "Texas Hold'Em";
21
+    }
22
+
23
+    public GameType getGameType() {
24
+        return GameInfo.GameType.HOLDEM;
25
+    }
26
+
27
+    public int getNumPlayers() {
28
+        return 14;
29
+    }
30
+
31
+    public boolean usesBringIns() {
32
+        return false;
33
+    }
34
+
35
+    public Game getGame(int numplayers, int bigblind, int ante, int raises) {
36
+        return new TexasHoldEm(numplayers, bigblind, ante, raises);
37
+    }
38
+
39
+}

+ 33
- 0
src/com/md87/cardgame/controllers/ConservativeOpener.java View File

@@ -0,0 +1,33 @@
1
+/*
2
+ * Copyright (c) Chris 'MD87' Smith, 2007. All rights reserved.
3
+ *
4
+ * This code may not be redistributed without prior permission from the
5
+ * aforementioned copyright holder(s).
6
+ */
7
+
8
+package com.md87.cardgame.controllers;
9
+
10
+import com.md87.cardgame.Card;
11
+import com.md87.cardgame.Player.CallRaiseFold;
12
+
13
+/**
14
+ *
15
+ * @author Chris
16
+ */
17
+public class ConservativeOpener extends RandomPlayer {
18
+    
19
+    @Override
20
+    public CallRaiseFold doCallRaiseFold(int callAmount, boolean canRaise) {
21
+        Card c1 = player.getCards().get(0);
22
+        Card c2 = player.getCards().get(1);
23
+        
24
+        if (c1.getSuit() == c2.getSuit() || Math.abs(c1.getRank().compareTo(c2.getRank())) < 2) {
25
+            return super.doCallRaiseFold(callAmount, canRaise);
26
+        } else {
27
+            return CallRaiseFold.FOLD;
28
+        }
29
+    }
30
+    
31
+    
32
+    
33
+}

+ 182
- 0
src/com/md87/cardgame/controllers/EndGameAI.java View File

@@ -0,0 +1,182 @@
1
+/*
2
+ * Copyright (c) Chris 'MD87' Smith, 2007. All rights reserved.
3
+ *
4
+ * This code may not be redistributed without prior permission from the
5
+ * aforementioned copyright holder(s).
6
+ */
7
+
8
+package com.md87.cardgame.controllers;
9
+
10
+import com.md87.cardgame.Card;
11
+import com.md87.cardgame.Deck;
12
+import com.md87.cardgame.interfaces.GameObserver;
13
+import com.md87.cardgame.hands.StandardHand;
14
+import com.md87.cardgame.Player;
15
+import com.md87.cardgame.Player.CallRaiseFold;
16
+import com.md87.cardgame.Player.OpenCheck;
17
+import com.md87.cardgame.interfaces.Game;
18
+import java.util.HashMap;
19
+import java.util.Map;
20
+
21
+/**
22
+ *
23
+ * @author Chris
24
+ */
25
+public class EndGameAI extends ConservativeOpener implements GameObserver {
26
+    
27
+    private boolean shouldBluff;
28
+    private boolean shouldFold;
29
+    private boolean endGame = false;
30
+    private StandardHand bestHand;
31
+    
32
+    private Deck communityCards = null;
33
+    
34
+    private double myLevel = 0;
35
+    
36
+    private final Map<StandardHand.Ranking, Integer> handRanks = new HashMap<StandardHand.Ranking, Integer>();
37
+    
38
+    public EndGameAI(final Game game) {
39
+        game.registerObserver(this);
40
+        
41
+        handRanks.put(StandardHand.Ranking.FLUSH, 4047644);
42
+        handRanks.put(StandardHand.Ranking.FOUR_OF_A_KIND, 224848);
43
+        handRanks.put(StandardHand.Ranking.FULL_HOUSE, 3473184);
44
+        handRanks.put(StandardHand.Ranking.NO_PAIR, 23294460);
45
+        handRanks.put(StandardHand.Ranking.ONE_PAIR, 58627800);
46
+        handRanks.put(StandardHand.Ranking.STRAIGHT, 6180020);
47
+        handRanks.put(StandardHand.Ranking.STRAIGHT_FLUSH, 41584);
48
+        handRanks.put(StandardHand.Ranking.THREE_OF_A_KIND, 6461620);
49
+        handRanks.put(StandardHand.Ranking.TWO_PAIR, 31433400);
50
+    }
51
+    
52
+    @Override
53
+    public CallRaiseFold doCallRaiseFold(int callAmount, boolean canRaise) {
54
+        if (endGame) {
55
+            if (canRaise && (shouldBluff || (!shouldFold && Math.random() > 0.5))) {
56
+                return CallRaiseFold.RAISE;
57
+            } else if (shouldFold) {
58
+                return CallRaiseFold.FOLD;
59
+            } else {
60
+                return CallRaiseFold.CALL;
61
+            }
62
+        } else {
63
+            return super.doCallRaiseFold(callAmount, canRaise);
64
+        }
65
+    }
66
+    
67
+    @Override
68
+    public OpenCheck doOpenCheck() {
69
+        return super.doOpenCheck();
70
+    }
71
+    
72
+    @Override
73
+    public int getRaise(int minimum) {
74
+        if (endGame) {
75
+            if (shouldBluff) {
76
+                return minimum + (int) (Math.random() * (player.getCash() - minimum)/2);
77
+            } else {
78
+                return minimum + (int) (Math.random() * (player.getCash() - minimum));
79
+            }
80
+        } else {
81
+            return super.getRaise(minimum);
82
+        }
83
+    }
84
+    
85
+    public void communityCardsUpdated() {
86
+        communityCards = game.getCommunityCards();
87
+        communityCards.addAll(player.getCards());
88
+        
89
+        bestHand = new StandardHand(communityCards);
90
+        
91
+        if (communityCards.size() == 7) {
92
+            endGame = true;
93
+            shouldFold = false;
94
+            
95
+            final int myFreq = handRanks.get(bestHand.getBestRank());
96
+            double betterFreq = 0;
97
+            double totalFreq = 0;
98
+            
99
+            for (StandardHand.Ranking ranking : StandardHand.Ranking.values()) {
100
+                if (ranking.ordinal() < bestHand.getBestRank().ordinal()) {
101
+                    betterFreq += handRanks.get(ranking);
102
+                }
103
+                
104
+                totalFreq += handRanks.get(ranking);
105
+            }
106
+            
107
+            // 0 <= score < 1
108
+            // Lower the better
109
+            double score = betterFreq / totalFreq;
110
+            
111
+            if (score > myLevel) {
112
+                shouldFold = true;
113
+            }
114
+        }
115
+    }
116
+    
117
+    public void playersTurn(Player player) {
118
+        // Do nothing
119
+    }
120
+    
121
+    public void newPlayer(Player player) {
122
+        // Do nothing
123
+    }
124
+    
125
+    public void newGame() {
126
+        shouldBluff = Math.random() > 0.7;
127
+        myLevel = Math.random();
128
+        endGame = false;
129
+    }
130
+    
131
+    public void endGame() {
132
+        // Do nothing
133
+    }
134
+    
135
+    public void setDealer(Player player) {
136
+        // Do nothing
137
+    }
138
+    
139
+    public void placeBlind(Player player, int blind, String name) {
140
+        // Do nothing
141
+    }
142
+    
143
+    public void raise(Player player, int amount) {
144
+        // Do nothing
145
+    }
146
+    
147
+    public void fold(Player player) {
148
+        // Do nothing
149
+    }
150
+    
151
+    public void call(Player player) {
152
+        // Do nothing
153
+    }
154
+    
155
+    public void check(Player player) {
156
+        // Do nothing
157
+    }
158
+    
159
+    public void open(Player player, int amount) {
160
+        // Do nothing
161
+    }
162
+    
163
+    public void winner(Player players) {
164
+        // Do nothing
165
+    }
166
+    
167
+    public void showdown() {
168
+        // Do nothing
169
+    }
170
+    
171
+    public void playerCardsUpdated() {
172
+        // Do nothing
173
+    }
174
+
175
+    public void discards(Player player, int number) {
176
+        // Do nothing
177
+    }
178
+
179
+    public void cardDealt(Player player, Card card) {
180
+        // Do nothing
181
+    }
182
+}

+ 232
- 0
src/com/md87/cardgame/controllers/HumanPlayer.java View File

@@ -0,0 +1,232 @@
1
+/*
2
+ * Copyright (c) Chris 'MD87' Smith, 2007. All rights reserved.
3
+ *
4
+ * This code may not be redistributed without prior permission from the
5
+ * aforementioned copyright holder(s).
6
+ */
7
+
8
+package com.md87.cardgame.controllers;
9
+
10
+import com.md87.cardgame.Card;
11
+import com.md87.cardgame.Deck;
12
+import com.md87.cardgame.interfaces.GameObserver;
13
+import com.md87.cardgame.ui.GameWindow;
14
+import com.md87.cardgame.Player;
15
+import com.md87.cardgame.Player.CallRaiseFold;
16
+import com.md87.cardgame.Player.OpenCheck;
17
+import com.md87.cardgame.interfaces.Game;
18
+import com.md87.cardgame.interfaces.PlayerController;
19
+import com.md87.cardgame.RaiseWindow;
20
+import com.md87.cardgame.interfaces.Game;
21
+
22
+/**
23
+ *
24
+ * @author Chris
25
+ */
26
+public class HumanPlayer implements PlayerController, GameObserver {
27
+    
28
+    public int move = -1;
29
+    public int bet = -1;
30
+    public Deck discards = null;
31
+    
32
+    private Game game;
33
+    private Player player;
34
+    
35
+    private GameWindow window;
36
+    
37
+    public HumanPlayer(final GameWindow window) {
38
+        this.window = window;
39
+    }
40
+    
41
+    public CallRaiseFold doCallRaiseFold(int callAmount, boolean canRaise) {
42
+        move = -1;
43
+        
44
+        window.setHumanPlayer(this, true, canRaise);
45
+        
46
+        synchronized(this) {
47
+            while (move == -1) {
48
+                try {
49
+                    wait();
50
+                } catch (InterruptedException ex) {
51
+                    // Do nothing
52
+                }
53
+            }
54
+        }
55
+        
56
+        if (move == 0) {
57
+            return CallRaiseFold.CALL;
58
+        } else if (move == 1) {
59
+            return CallRaiseFold.RAISE;
60
+        } else {
61
+            return CallRaiseFold.FOLD;
62
+        }
63
+    }
64
+    
65
+    public OpenCheck doOpenCheck() {
66
+        move = -1;
67
+        
68
+        window.setHumanPlayer(this, false, true);
69
+        
70
+        synchronized(this) {
71
+            while (move == -1) {
72
+                try {
73
+                    wait();
74
+                } catch (InterruptedException ex) {
75
+                    // Do nothing
76
+                }
77
+            }
78
+        }
79
+        
80
+        if (move == 0) {
81
+            return OpenCheck.CHECK;
82
+        } else {
83
+            return OpenCheck.OPEN;
84
+        }
85
+    }
86
+    
87
+    public boolean shouldShowCards() {
88
+        return true;
89
+    }
90
+    
91
+    public void setPlayer(Player player) {
92
+        this.player = player;
93
+    }
94
+    
95
+    public void setGame(Game game) {
96
+        this.game = game;
97
+        game.registerObserver(this);
98
+    }
99
+    
100
+    public int getRaise(int minimum) {
101
+        bet = -1;
102
+        
103
+        new RaiseWindow(this, minimum);
104
+        
105
+        synchronized(this) {
106
+            while (bet == -1) {
107
+                try {
108
+                    wait();
109
+                } catch (InterruptedException ex) {
110
+                    // Do nothing
111
+                }
112
+            }
113
+        }
114
+        
115
+        return bet;
116
+    }
117
+    
118
+    public Player getPlayer() {
119
+        return player;
120
+    }
121
+    
122
+    public GameWindow getWindow() {
123
+        return window;
124
+    }
125
+    
126
+    public void communityCardsUpdated() {
127
+        // Do nothing
128
+    }
129
+    
130
+    public void playerCardsUpdated() {
131
+        // Do nothing
132
+    }
133
+    
134
+    public void playersTurn(Player player) {
135
+        // Do nothing
136
+    }
137
+    
138
+    public void newPlayer(Player player) {
139
+        // Do nothing
140
+    }
141
+    
142
+    public void newGame() {
143
+        // Do nothing
144
+    }
145
+    
146
+    public void endGame() {
147
+        window.setWaitPlayer(this);
148
+        
149
+        boolean cont = false;
150
+        
151
+        synchronized(this) {
152
+            do {
153
+                cont = false;
154
+                
155
+                try {
156
+                    wait();
157
+                } catch (InterruptedException ex) {
158
+                    cont = true;
159
+                }
160
+            } while (cont);
161
+        }
162
+    }
163
+    
164
+    public void setDealer(Player player) {
165
+        // Do nothing
166
+    }
167
+    
168
+    public void placeBlind(Player player, int blind, String name) {
169
+        // Do nothing
170
+    }
171
+    
172
+    public void raise(Player player, int amount) {
173
+        // Do nothing
174
+    }
175
+    
176
+    public void fold(Player player) {
177
+        // Do nothing
178
+    }
179
+    
180
+    public void call(Player player) {
181
+        // Do nothing
182
+    }
183
+    
184
+    public void check(Player player) {
185
+        // Do nothing
186
+    }
187
+    
188
+    public void open(Player player, int amount) {
189
+        // Do nothing
190
+    }
191
+    
192
+    public void winner(Player players) {
193
+        // Do nothing
194
+    }
195
+    
196
+    public void showdown() {
197
+        // Do nothing
198
+    }
199
+    
200
+    /** {@inheritDoc} */
201
+    public boolean isLocalHuman() {
202
+        return true;
203
+    }    
204
+    
205
+    /** {@inheritDoc} */
206
+    public Deck discardCards(final int minimum, final int maximum) {
207
+        discards = null;
208
+        
209
+        window.setDiscardPlayer(this, minimum, maximum);        
210
+        
211
+        synchronized(this) {
212
+            while (discards == null) {
213
+                try {
214
+                    wait();
215
+                } catch (InterruptedException ex) {
216
+                    // Do nothing
217
+                }
218
+            }
219
+        }
220
+        
221
+        return discards;
222
+    }
223
+
224
+    public void discards(Player player, int number) {
225
+        // Do nothing
226
+    }
227
+
228
+    public void cardDealt(Player player, Card card) {
229
+        // Do nothing
230
+    }
231
+    
232
+}

+ 160
- 0
src/com/md87/cardgame/controllers/NetworkPlayer.java View File

@@ -0,0 +1,160 @@
1
+/*
2
+ * Copyright (c) Chris 'MD87' Smith, 2007. All rights reserved.
3
+ *
4
+ * This code may not be redistributed without prior permission from the
5
+ * aforementioned copyright holder(s).
6
+ */
7
+
8
+package com.md87.cardgame.controllers;
9
+
10
+import com.md87.cardgame.Card;
11
+import com.md87.cardgame.Deck;
12
+import com.md87.cardgame.interfaces.GameObserver;
13
+import com.md87.cardgame.Player;
14
+import com.md87.cardgame.Player.CallRaiseFold;
15
+import com.md87.cardgame.Player.OpenCheck;
16
+import com.md87.cardgame.interfaces.Game;
17
+import com.md87.cardgame.interfaces.PlayerController;
18
+
19
+/**
20
+ * Provides the server-side interface for network games. Each network player
21
+ * listens on its own port, waiting for connections to come in.
22
+ * 
23
+ * @author Chris
24
+ */
25
+public class NetworkPlayer implements PlayerController, GameObserver {
26
+
27
+    /**
28
+     * Creates a new instance of NetworkPlayer.
29
+     */
30
+    public NetworkPlayer() {
31
+    }
32
+
33
+    /** {@inheritDoc} */
34
+    public CallRaiseFold doCallRaiseFold(int callAmount, boolean canRaise) {
35
+        return CallRaiseFold.CALL;
36
+        // Do nothing
37
+    }
38
+
39
+    /** {@inheritDoc} */
40
+    public OpenCheck doOpenCheck() {
41
+        return OpenCheck.CHECK;
42
+        // Do nothing
43
+    }
44
+
45
+    /** {@inheritDoc} */
46
+    public boolean shouldShowCards() {
47
+        return false;
48
+        // Do nothing
49
+    }
50
+
51
+    /** {@inheritDoc} */
52
+    public void setPlayer(Player player) {
53
+        // Do nothing
54
+    }
55
+
56
+    /** {@inheritDoc} */
57
+    public void setGame(Game game) {
58
+        game.registerObserver(this);
59
+    }
60
+
61
+    /** {@inheritDoc} */
62
+    public int getRaise(int minimum) {
63
+        return minimum;
64
+        // Do nothing
65
+    }
66
+
67
+    /** {@inheritDoc} */
68
+    public void communityCardsUpdated() {
69
+        // Do nothing
70
+    }
71
+
72
+    /** {@inheritDoc} */
73
+    public void playerCardsUpdated() {
74
+        // Do nothing
75
+    }
76
+
77
+    /** {@inheritDoc} */
78
+    public void playersTurn(Player player) {
79
+        // Do nothing
80
+    }
81
+
82
+    /** {@inheritDoc} */
83
+    public void newPlayer(Player player) {
84
+        // Do nothing
85
+    }
86
+
87
+    /** {@inheritDoc} */
88
+    public void newGame() {
89
+        // Do nothing
90
+    }
91
+
92
+    /** {@inheritDoc} */
93
+    public void endGame() {
94
+        // Do nothing
95
+    }
96
+
97
+    /** {@inheritDoc} */
98
+    public void setDealer(Player player) {
99
+        // Do nothing
100
+    }
101
+
102
+    /** {@inheritDoc} */
103
+    public void placeBlind(Player player, int blind, String name) {
104
+        // Do nothing
105
+    }
106
+
107
+    /** {@inheritDoc} */
108
+    public void raise(Player player, int amount) {
109
+        // Do nothing
110
+    }
111
+
112
+    /** {@inheritDoc} */
113
+    public void fold(Player player) {
114
+        // Do nothing
115
+    }
116
+
117
+    /** {@inheritDoc} */
118
+    public void call(Player player) {
119
+        // Do nothing
120
+    }
121
+
122
+    /** {@inheritDoc} */
123
+    public void check(Player player) {
124
+        // Do nothing
125
+    }
126
+
127
+    /** {@inheritDoc} */
128
+    public void open(Player player, int amount) {
129
+        // Do nothing
130
+    }
131
+
132
+    /** {@inheritDoc} */
133
+    public void winner(Player players) {
134
+        // Do nothing
135
+    }
136
+
137
+    /** {@inheritDoc} */
138
+    public void showdown() {
139
+        // Do nothing
140
+    }
141
+
142
+    /** {@inheritDoc} */
143
+    public boolean isLocalHuman() {
144
+        return false;
145
+    }
146
+    
147
+    /** {@inheritDoc} */
148
+    public Deck discardCards(final int minimum, final int maximum) {
149
+        return new Deck();
150
+    }
151
+
152
+    public void discards(Player player, int number) {
153
+        // Do nothing
154
+    }
155
+
156
+    public void cardDealt(Player player, Card card) {
157
+        // Do nothing
158
+    }
159
+
160
+}

+ 72
- 0
src/com/md87/cardgame/controllers/RandomPlayer.java View File

@@ -0,0 +1,72 @@
1
+/*
2
+ * Copyright (c) Chris 'MD87' Smith, 2007. All rights reserved.
3
+ *
4
+ * This code may not be redistributed without prior permission from the
5
+ * aforementioned copyright holder(s).
6
+ */
7
+
8
+package com.md87.cardgame.controllers;
9
+
10
+import com.md87.cardgame.Deck;
11
+import com.md87.cardgame.Player;
12
+import com.md87.cardgame.Player.CallRaiseFold;
13
+import com.md87.cardgame.Player.OpenCheck;
14
+import com.md87.cardgame.interfaces.Game;
15
+import com.md87.cardgame.interfaces.PlayerController;
16
+
17
+/**
18
+ *
19
+ * @author Chris
20
+ */
21
+public class RandomPlayer implements PlayerController {
22
+    
23
+    protected Player player;
24
+    protected Game game;
25
+
26
+    public CallRaiseFold doCallRaiseFold(int callAmount, boolean canRaise) {
27
+        if (Math.random() < 0.3) {
28
+            if (player.getCash() - callAmount < game.getBigBlind() || !canRaise) {
29
+                return CallRaiseFold.FOLD;
30
+            } else {
31
+                return CallRaiseFold.RAISE;
32
+            }
33
+        } else {
34
+            return CallRaiseFold.CALL;
35
+        }
36
+    }
37
+
38
+    public OpenCheck doOpenCheck() {
39
+        if (Math.random() < 0.5 || player.getCash() < game.getBigBlind()) {
40
+            return OpenCheck.CHECK;
41
+        } else {
42
+            return OpenCheck.OPEN;
43
+        }
44
+    }
45
+
46
+    public boolean shouldShowCards() {
47
+        return false;
48
+    }
49
+
50
+    public void setPlayer(Player player) {
51
+        this.player = player;
52
+    }
53
+    
54
+    public void setGame(Game game) {
55
+        this.game = game;
56
+    }
57
+
58
+    public int getRaise(int minimum) {
59
+        return minimum;
60
+    }
61
+    
62
+    /** {@inheritDoc} */
63
+    public boolean isLocalHuman() {
64
+        return false;
65
+    }
66
+
67
+    /** {@inheritDoc} */
68
+    public Deck discardCards(final int minimum, final int maximum) {
69
+        return new Deck(player.getCards().subList(0, minimum));
70
+    }
71
+
72
+}

+ 757
- 0
src/com/md87/cardgame/games/AbstractGame.java View File

@@ -0,0 +1,757 @@
1
+/*
2
+ * Copyright (c) Chris 'MD87' Smith, 2007. All rights reserved.
3
+ *
4
+ * This code may not be redistributed without prior permission from the
5
+ * aforementioned copyright holder(s).
6
+ */
7
+
8
+package com.md87.cardgame.games;
9
+
10
+import com.md87.cardgame.Card;
11
+import com.md87.cardgame.Deck;
12
+import com.md87.cardgame.Player;
13
+import com.md87.cardgame.Rank;
14
+import com.md87.cardgame.Suit;
15
+import com.md87.cardgame.hands.StandardHand;
16
+import com.md87.cardgame.interfaces.Game;
17
+import com.md87.cardgame.interfaces.GameObserver;
18
+import com.md87.cardgame.interfaces.Hand;
19
+import com.md87.cardgame.interfaces.PlayerController;
20
+
21
+import java.util.ArrayList;
22
+import java.util.Collections;
23
+import java.util.HashMap;
24
+import java.util.List;
25
+import java.util.Map;
26
+
27
+/**
28
+ * Implements some basic functions that may be used by a game.
29
+ *
30
+ * @author Chris
31
+ */
32
+public abstract class AbstractGame implements Game, Runnable {
33
+    
34
+    /** The maximum number of players this game will contain. */
35
+    protected int numplayers = 0;
36
+    
37
+    protected int bigblind = 0;
38
+    protected int ante = 0;
39
+    protected int raises = 4;
40
+    
41
+    protected int raisesLeft;
42
+    
43
+    protected int dealer = 0;
44
+    protected int player = 0;
45
+    
46
+    /** A list of players who're playing in this game. */
47
+    protected final List<Player> players = new ArrayList<Player>();
48
+    
49
+    /** The deck used for this game. */
50
+    protected final Deck deck = new Deck();
51
+    
52
+    /** A list of observers registered for this game. */
53
+    private final List<GameObserver> observers = new ArrayList<GameObserver>();
54
+    
55
+    public AbstractGame(final int numplayers, final int bigblind, final int ante,
56
+            final int raises) {
57
+        
58
+        this.numplayers = numplayers;
59
+        this.bigblind = bigblind;
60
+        this.ante = ante;
61
+        this.raises = raises;
62
+        
63
+        dealer = (int) Math.round(Math.random() * (numplayers - 1));
64
+    }
65
+    
66
+    /** {@inheritDoc} */
67
+    public void addPlayer(final String name, final int cash,
68
+            final PlayerController controller) {
69
+        
70
+        if (numplayers <= players.size()) {
71
+            return;
72
+        }
73
+        
74
+        final Player player = new Player(this, name, cash, controller);
75
+        
76
+        addPlayer(player);
77
+    }
78
+    
79
+    /** {@inheritDoc} */
80
+    public void addPlayer(final Player player) {
81
+        players.add(player);
82
+        
83
+        notifyNewPlayer(player);
84
+    }
85
+    
86
+    /** {@inheritDoc} */
87
+    public Player getDealer() {
88
+        if (players.size() > dealer) {
89
+            return players.get(dealer);
90
+        } else {
91
+            return null;
92
+        }
93
+    }
94
+    
95
+    /** {@inheritDoc} */
96
+    public int getBigBlind() {
97
+        return bigblind;
98
+    }
99
+    
100
+    /** {@inheritDoc} */
101
+    public int getCurrentPot() {
102
+        int pot = 0;
103
+        
104
+        for (Player player : players) {
105
+            pot += player.getBet();
106
+        }
107
+        
108
+        return pot;
109
+    }
110
+    
111
+    /** {@inheritDoc} */
112
+    public int getMaxBet() {
113
+        int max = 0;
114
+        
115
+        for (Player player : players) {
116
+            if (player.getBet() > max) {
117
+                max = player.getBet();
118
+            }
119
+        }
120
+        
121
+        return max;
122
+    }
123
+    
124
+    /** {@inheritDoc} */
125
+    public int getNumPlayers() {
126
+        return numplayers;
127
+    }
128
+    
129
+    /**
130
+     * Clears and rebuilds the deck used for this game.
131
+     */
132
+    protected void shuffle() {
133
+        deck.clear();
134
+        for (Suit suit : Suit.values()) {
135
+            for (Rank rank : Rank.values()) {
136
+                deck.add(new Card(suit, rank));
137
+            }
138
+        }
139
+        
140
+        Collections.shuffle(deck);
141
+    }
142
+    
143
+    /**
144
+     * Clears all player cards.
145
+     */
146
+    protected void discardCards() {
147
+        for (Player player : players) {
148
+            player.discardCards();
149
+        }
150
+    }
151
+    
152
+    /**
153
+     * Deals a single card to each active player, starting with the
154
+     * specified player, and working clockwise.
155
+     *
156
+     * @param start The player to start dealing with
157
+     * @param isPublic Whether the card is a public card or not
158
+     */
159
+    protected void dealCard(final Player start, final boolean isPublic) {
160
+        int i = players.indexOf(start);
161
+        for (int x = 0; x < numplayers; x++) {
162
+            final Player player = players.get((i + x) % numplayers);
163
+            
164
+            if (!player.isOut() && !player.hasFolded()) {
165
+                final Card card = deck.deal();
166
+                card.setPublic(isPublic);
167
+                
168
+                player.dealCard(card);
169
+                notifyCardDealt(player, card);
170
+                notifyPlayerCardsUpdated();
171
+            }
172
+        }
173
+    }
174
+    
175
+    protected void doDrawRound(final Player start, final int min, final int max, boolean replace) {
176
+        int i = players.indexOf(start);
177
+        for (int x = 0; x < numplayers; x++) {
178
+            final Player player = players.get((i + x) % numplayers);
179
+            
180
+            if (!player.isOut() && !player.hasFolded()) {
181
+                notifyPlayersTurn(player);
182
+                
183
+                final Deck discarded = player.doCardDiscard(min, max);
184
+                
185
+                for (Card card : discarded) {
186
+                    player.removeCard(card);
187
+                    if (replace) {
188
+                        player.dealCard(deck.deal());
189
+                    }
190
+                }
191
+                
192
+                notifyDiscards(player, discarded.size());
193
+            }
194
+        }
195
+    }    
196
+    
197
+    /**
198
+     * Counts the number of players with the specified properties.
199
+     *
200
+     * @param mustBeIn Whether or not the players must be in
201
+     * @param mustNotFolded Whether or not the players must not have folded to be in
202
+     * @param mustNotAllIn Whether or not the players must not be all in
203
+     * @return The number of players matching the properties specified
204
+     */
205
+    public int countPlayers(final boolean mustBeIn,
206
+            final boolean mustNotFolded, final boolean mustNotAllIn) {
207
+        int count = 0;
208
+        
209
+        for (Player player : players) {
210
+            if ((!mustBeIn || !player.isOut())
211
+                    && (!mustNotFolded || !player.hasFolded())
212
+                    && (!mustNotAllIn || !player.isAllIn())) {
213
+                count++;
214
+            }
215
+        }
216
+        
217
+        return count;
218
+    }
219
+    
220
+    /** {@inheritDoc} */
221
+    public List<Player> getPlayers() {
222
+        return players;
223
+    }
224
+    
225
+    /** {@inheritDoc} */
226
+    public void startTournament() {
227
+        new Thread(this).start();
228
+    }
229
+    
230
+    /** {@inheritDoc} */
231
+    public void run() {
232
+        while (countPlayers(true, false, false) > 1) {
233
+            startGame();
234
+        }
235
+    }
236
+    
237
+    protected abstract void startGame();
238
+    
239
+    protected void doAntes() {
240
+        if (ante > 0) {
241
+            for (Player player : players) {
242
+                if (!player.isOut()) {
243
+                    player.forceBet(ante);
244
+                    
245
+                    notifyPlaceBlind(player, ante, "ante");
246
+                }
247
+            }
248
+        }
249
+    }
250
+    
251
+    protected void doBlinds() {
252
+        if (countPlayers(true, false, false) > 2) {
253
+            if (!players.get((dealer + 1) % numplayers).isOut()) {
254
+                doSmallBlind(players.get((dealer + 1) % numplayers));
255
+            }
256
+            
257
+            doBigBlind(players.get((dealer + 2) % numplayers));
258
+            
259
+            player = (dealer + 2) % numplayers;
260
+        } else {
261
+            Player big = null;
262
+            Player small = null;
263
+            
264
+            for (Player player : players) {
265
+                if (!player.isOut()) {
266
+                    if (player == players.get(dealer)) {
267
+                        small = player;
268
+                    } else {
269
+                        big = player;
270
+                    }
271
+                }
272
+            }
273
+            
274
+            doSmallBlind(small);
275
+            doBigBlind(big);
276
+            
277
+            player = players.indexOf(big);
278
+        }
279
+    }
280
+    
281
+    protected void doSmallBlind(final Player player) {
282
+        player.forceBet(bigblind / 2);
283
+        
284
+        notifyPlaceBlind(player, bigblind / 2, "small blind");
285
+    }
286
+    
287
+    protected void doBigBlind(final Player player) {
288
+        player.forceBet(bigblind);
289
+        
290
+        notifyPlaceBlind(player, bigblind / 2, "big blind");
291
+    }
292
+    
293
+    @SuppressWarnings("fallthrough")
294
+    protected void waitForBets() {
295
+        int maxbet = getMaxBet();
296
+        int endPlayer = player;
297
+        boolean reachedEnd = false;
298
+        raisesLeft = raises;
299
+        Player myPlayer;
300
+        
301
+        do {
302
+            player = (player + 1) % numplayers;
303
+            myPlayer = players.get(player);
304
+            
305
+            if (!myPlayer.hasFolded() && !myPlayer.isAllIn() && !myPlayer.isOut()) {
306
+                notifyPlayersTurn(myPlayer);
307
+                
308
+                if (playersHaveBet(maxbet)) {
309
+                    // He can check or open
310
+                    switch (myPlayer.doOpenCheck()) {
311
+                    case CHECK:
312
+                        // Do nothing
313
+                        
314
+                        notifyCheck(myPlayer);
315
+                        break;
316
+                    case OPEN:
317
+                        int raiseAmount = myPlayer.getRaiseAmount(bigblind);
318
+                        
319
+                        myPlayer.forceBet(raiseAmount);
320
+                        maxbet += raiseAmount;
321
+                        
322
+                        notifyOpen(myPlayer, raiseAmount);
323
+                        break;
324
+                    }
325
+                } else {
326
+                    final boolean canRaise = raisesLeft != 0;
327
+                    
328
+                    // He can call, raise or fold
329
+                    switch (myPlayer.doCallRaiseFold(maxbet - myPlayer.getBet(), canRaise)) {
330
+                    case RAISE:
331
+                        if (canRaise) {
332
+                            myPlayer.forceBet(maxbet - myPlayer.getBet());
333
+                            
334
+                            int raiseAmount = myPlayer.getRaiseAmount(bigblind);
335
+                            myPlayer.forceBet(raiseAmount);
336
+                            maxbet += raiseAmount;
337
+                            
338
+                            notifyRaise(myPlayer, raiseAmount);
339
+                            
340
+                            raisesLeft--;
341
+                            
342
+                            break;
343
+                        } // Fall through: call instead
344
+                    case CALL:
345
+                        myPlayer.forceBet(maxbet - myPlayer.getBet());
346
+                        
347
+                        notifyCall(myPlayer);
348
+                        break;
349
+                    case FOLD:
350
+                        myPlayer.setFold();
351
+                        
352
+                        notifyFold(myPlayer);
353
+                        break;
354
+                    }
355
+                }
356
+            }
357
+            
358
+            if (player == endPlayer) {
359
+                reachedEnd = true;
360
+            }
361
+            
362
+        } while (!playersHaveBet(maxbet) || (!reachedEnd && countPlayers(true, true, true) > 1));
363
+    }
364
+    
365
+    protected void doDealerAdvance() {
366
+        if (countPlayers(true, false, false) > 2) {
367
+            do {
368
+                dealer = (dealer + 1) % numplayers;
369
+            } while (players.get((dealer + 2) % numplayers).isOut());
370
+        } else if (countPlayers(true, false, false) == 2) {
371
+            do {
372
+                dealer = (dealer + 1) % numplayers;
373
+            } while (players.get(dealer).isOut());
374
+        }
375
+    }
376
+    
377
+    protected void doBettingRound() {
378
+        notifyCommunityCardsUpdated();
379
+        
380
+        player = dealer;
381
+        waitForBets();
382
+    }
383
+    
384
+    protected boolean playersHaveBet(final int bet) {
385
+        for (Player player : players) {
386
+            if (!player.isOut() && !player.hasFolded() && !player.isAllIn()) {
387
+                if (player.getBet() < bet) {
388
+                    return false;
389
+                }
390
+            }
391
+        }
392
+        
393
+        return true;
394
+    }
395
+    
396
+    protected void doShowDown() {
397
+        for (Player player : players) {
398
+            if (!player.isOut()) {
399
+                player.calculateBestDeck();
400
+            }
401
+        }
402
+        
403
+        notifyShowdown();
404
+        
405
+        doWinner();
406
+        
407
+        for (Player player : players) {
408
+            player.resetBet();
409
+        }
410
+    }
411
+    
412
+    protected void doWinner() {
413
+        doWinner(false);
414
+    }
415
+    
416
+    protected void doWinner(final boolean doHalf) {
417
+        if (countPlayers(true, true, false) == 1) {
418
+            int pot = 0;
419
+            Player winner = null;
420
+            
421
+            for (Player player : players) {
422
+                if (!player.isOut()) {
423
+                    
424
+                    if (!player.hasFolded()) {
425
+                        winner = player;
426
+                    }
427
+                    
428
+                    if (doHalf) {
429
+                        pot += player.getBet() / 2;
430
+                    } else {
431
+                        pot += player.getBet();
432
+                    }
433
+                }
434
+            }
435
+            
436
+            winner.addCash(pot);
437
+            notifyWinner(winner);
438
+            
439
+            return;
440
+        }
441
+        
442
+        // tempPlayers is a list of everyone involved in the round
443
+        List<Player> tempPlayers = new ArrayList<Player>();
444
+        Map<Player, Integer> playerBets = new HashMap<Player, Integer>();
445
+        
446
+        for (Player player : players) {
447
+            if (!player.isOut()) {
448
+                tempPlayers.add(player);
449
+                
450
+                if (doHalf) {
451
+                    playerBets.put(player, player.getBet() / 2);
452
+                } else {
453
+                    playerBets.put(player, player.getBet());
454
+                }
455
+            }
456
+        }
457
+        
458
+        int maxbet = 0;
459
+        for (Integer bet : playerBets.values()) {
460
+            if (bet > maxbet) {
461
+                maxbet = bet;
462
+            }
463
+        }
464
+        
465
+        while (maxbet > 0 && tempPlayers.size() > 0) {
466
+            int minbet = maxbet;
467
+            
468
+            for (Player player : tempPlayers) {
469
+                if (playerBets.get(player) < minbet) {
470
+                    minbet = playerBets.get(player);
471
+                }
472
+            }
473
+            
474
+            int potsize = minbet * tempPlayers.size();
475
+            
476
+            List<Player> minPlayers = new ArrayList<Player>();
477
+            
478
+            for (Player player : tempPlayers) {
479
+                if (playerBets.get(player) == minbet) {
480
+                    minPlayers.add(player);
481
+                }
482
+                playerBets.put(player, playerBets.get(player) - minbet);
483
+            }
484
+            
485
+            List<Player> possibleWinners = new ArrayList<Player>();
486
+            
487
+            for (Player player : tempPlayers) {
488
+                if (!player.hasFolded() && !player.isOut()) {
489
+                    possibleWinners.add(player);
490
+                }
491
+            }
492
+            
493
+            List<Player> theseWinners = getWinners(possibleWinners);
494
+            
495
+            potsize = potsize / theseWinners.size();
496
+            
497
+            if (potsize != 0) {
498
+                
499
+                for (Player player : theseWinners) {
500
+                    player.addCash(potsize);
501
+                    
502
+                    notifyWinner(player);
503
+                }
504
+                
505
+            }
506
+            
507
+            tempPlayers.removeAll(minPlayers);
508
+            
509
+            maxbet = 0;
510
+            for (Integer bet : playerBets.values()) {
511
+                if (bet > maxbet) {
512
+                    maxbet = bet;
513
+                }
514
+            }
515
+        }
516
+        
517
+    }
518
+    
519
+    /** {@inheritDoc} */
520
+    public Deck getBestDeck(final Deck cards) {
521
+        final Deck res = new Deck();
522
+        res.addAll(cards);
523
+        res.addAll(getCommunityCards());
524
+        
525
+        return res;
526
+    }
527
+    
528
+    /** {@inheritDoc} */
529
+    public boolean hasActiveHuman() {
530
+        for (Player player : players) {
531
+            if (player.isLocalHuman() && !player.isOut() && !player.hasFolded()) {
532
+                return true;
533
+            }
534
+        }
535
+        
536
+        return false;
537
+    }
538
+    
539
+    /** {@inheritDoc} */
540
+    public Hand getHand(final Deck deck) {
541
+        return new StandardHand(deck);
542
+    }
543
+    
544
+    /** {@inheritDoc} */
545
+    public String getHandText(final Player player) {
546
+        String[] parts = getHand(player.getBestDeck()).getFriendlyName().split(": ");
547
+        
548
+        String res = "";
549
+        for (String part : parts) {
550
+            res = res + "\n" + part;
551
+        }
552
+        
553
+        return res.substring(1);
554
+    }
555
+    
556
+    protected List<Player> getWinners(final List<Player> winners) {
557
+        final List<Player> res = new ArrayList<Player>();
558
+        
559
+        Collections.sort(winners);
560
+        
561
+        res.add(winners.get(0));
562
+        
563
+        for (int i = 1; i < winners.size(); i++) {
564
+            if (winners.get(i).compareTo(winners.get(0)) == 0) {
565
+                res.add(winners.get(i));
566
+            }
567
+        }
568
+        
569
+        return res;
570
+    }
571
+    
572
+    protected abstract boolean canDoBringIns();
573
+    
574
+    /** {@inheritDoc} */
575
+    public void registerObserver(final GameObserver observer) {
576
+        observers.add(observer);
577
+    }
578
+    
579
+    /** {@inheritDoc} */
580
+    public void unregisterObserver(final GameObserver observer) {
581
+        observers.remove(observer);
582
+    }
583
+    
584
+    /**
585
+     * Notifies all observers that the community cards have been upated.
586
+     */
587
+    protected void notifyCommunityCardsUpdated() {
588
+        for (GameObserver observer : observers) {
589
+            observer.communityCardsUpdated();
590
+        }
591
+    }
592
+    
593
+    /**
594
+     * Notifies all observers that the player cards have been updated.
595
+     */
596
+    protected void notifyPlayerCardsUpdated() {
597
+        for (GameObserver observer : observers)  {
598
+            observer.playerCardsUpdated();
599
+        }
600
+    }
601
+    
602
+    protected void notifyCardDealt(final Player player, final Card card) {
603
+        for (GameObserver observer : observers) {
604
+            observer.cardDealt(player, card);
605
+        }
606
+    }
607
+    
608
+    /**
609
+     * Notifies all observers that it is the specified player's turn.
610
+     *
611
+     * @param player The player whose turn it is
612
+     */
613
+    protected void notifyPlayersTurn(final Player player) {
614
+        for (GameObserver observer : observers)  {
615
+            observer.playersTurn(player);
616
+        }
617
+    }
618
+    
619
+    /**
620
+     * Notifies all observers that a new player has joined.
621
+     *
622
+     * @param player The player who has joined
623
+     */
624
+    protected void notifyNewPlayer(final Player player) {
625
+        for (GameObserver observer : observers)  {
626
+            observer.newPlayer(player);
627
+        }
628
+    }
629
+    
630
+    /**
631
+     * Notifies all observers that a new game has started.
632
+     */
633
+    protected void notifyNewGame() {
634
+        for (GameObserver observer : observers)  {
635
+            observer.newGame();
636
+        }
637
+    }
638
+    
639
+    /**
640
+     * Notifies all observers that a game has ended.
641
+     */
642
+    protected void notifyEndGame() {
643
+        for (GameObserver observer : observers)  {
644
+            observer.endGame();
645
+        }
646
+    }
647
+    
648
+    /**
649
+     * Notifies all observers that the specified player is now the dealer.
650
+     *
651
+     * @param player The player who is now the dealer
652
+     */
653
+    protected void notifySetDealer(final Player player) {
654
+        for (GameObserver observer : observers)  {
655
+            observer.setDealer(player);
656
+        }
657
+    }
658
+    
659
+    /**
660
+     * Notifies all observers that the specified player has payed the specified
661
+     * blind.
662
+     *
663
+     * @param player The player who's paying the blind
664
+     * @param blind The value of the blind
665
+     * @param name The name of the blind (big blind, small blind, ante, etc)
666
+     */
667
+    protected void notifyPlaceBlind(final Player player, final int blind,
668
+            final String name) {
669
+        for (GameObserver observer : observers)  {
670
+            observer.placeBlind(player, blind, name);
671
+        }
672
+    }
673
+    
674
+    /**
675
+     * Notifies all observers that the specified player has raised.
676
+     *
677
+     * @param player The player that has raised
678
+     * @param amount The amount the player raised by
679
+     */
680
+    protected void notifyRaise(final Player player, final int amount) {
681
+        for (GameObserver observer : observers)  {
682
+            observer.raise(player, amount);
683
+        }
684
+    }
685
+    
686
+    /**
687
+     * Notifies all observers that the specified player has folded.
688
+     *
689
+     * @param player The player who has folded
690
+     */
691
+    protected void notifyFold(final Player player) {
692
+        for (GameObserver observer : observers)  {
693
+            observer.fold(player);
694
+        }
695
+    }
696
+    
697
+    /**
698
+     * Notifies all observers that the specified player has called.
699
+     *
700
+     * @param player The player who has called
701
+     */
702
+    protected void notifyCall(final Player player) {
703
+        for (GameObserver observer : observers)  {
704
+            observer.call(player);
705
+        }
706
+    }
707
+    
708
+    /**
709
+     * Notifies all observers that the specified player has checked.
710
+     *
711
+     * @param player The player who has checked
712
+     */
713
+    protected void notifyCheck(final Player player) {
714
+        for (GameObserver observer : observers)  {
715
+            observer.check(player);
716
+        }
717
+    }
718
+    
719
+    /**
720
+     * Notifies all observers that the specified player has opened.
721
+     *
722
+     * @param player The player who has opened
723
+     * @param amount The amount they opened at
724
+     */
725
+    protected void notifyOpen(final Player player, final int amount) {
726
+        for (GameObserver observer : observers)  {
727
+            observer.open(player, amount);
728
+        }
729
+    }
730
+    
731
+    protected void notifyDiscards(final Player player, final int amount) {
732
+        for (GameObserver observer : observers) {
733
+            observer.discards(player, amount);
734
+        }
735
+    }
736
+    
737
+    /**
738
+     * Notifies all observers that the specified player is a winner.
739
+     *
740
+     * @param player The player who has won
741
+     */
742
+    protected void notifyWinner(final Player player) {
743
+        for (GameObserver observer : observers)  {
744
+            observer.winner(player);
745
+        }
746
+    }
747
+    
748
+    /**
749
+     * Notifies all observers that the showdown is taking place.
750
+     */
751
+    protected void notifyShowdown() {
752
+        for (GameObserver observer : observers)  {
753
+            observer.showdown();
754
+        }
755
+    }
756
+    
757
+}

+ 41
- 0
src/com/md87/cardgame/games/AsianFiveCardStud.java View File

@@ -0,0 +1,41 @@
1
+/*
2
+ * Copyright (c) Chris 'MD87' Smith, 2007. All rights reserved.
3
+ *
4
+ * This code may not be redistributed without prior permission from the
5
+ * aforementioned copyright holder(s).
6
+ */
7
+
8
+package com.md87.cardgame.games;
9
+
10
+import com.md87.cardgame.Card;
11
+import com.md87.cardgame.Rank;
12
+import com.md87.cardgame.Suit;
13
+
14
+import java.util.Collections;
15
+
16
+/**
17
+ *
18
+ * @author Chris
19
+ */
20
+public class AsianFiveCardStud extends FiveCardStud {
21
+    
22
+    public AsianFiveCardStud(final int numplayers, final int bigblind, final int ante,
23
+            final int raises) {
24
+        super(numplayers, bigblind, ante, raises);
25
+    }
26
+    
27
+    @Override
28
+    protected void shuffle() {
29
+        deck.clear();
30
+        for (Suit suit : Suit.values()) {
31
+            for (Rank rank : Rank.values()) {
32
+                if (rank.compareTo(Rank.SEVEN) <= 0) {
33
+                    deck.add(new Card(suit, rank));
34
+                }
35
+            }
36
+        }
37
+        
38
+        Collections.shuffle(deck);
39
+    }
40
+    
41
+}

+ 38
- 0
src/com/md87/cardgame/games/Courchevel.java View File

@@ -0,0 +1,38 @@
1
+/*
2
+ * Copyright (c) Chris 'MD87' Smith, 2007. All rights reserved.
3
+ *
4
+ * This code may not be redistributed without prior permission from the
5
+ * aforementioned copyright holder(s).
6
+ */
7
+
8
+package com.md87.cardgame.games;
9
+
10
+import com.md87.cardgame.Deck;
11
+
12
+/**
13
+ * Implements a standard (local) Courchevel game.
14
+ *
15
+ * @author Chris
16
+ */
17
+public class Courchevel extends OmahaHoldEm {
18
+
19
+    public Courchevel(int numplayers, int bigblind, int ante, int raises) {
20
+        super(numplayers, bigblind, ante, raises);
21
+    }
22
+
23
+    @Override
24
+    public Deck getCommunityCards() {
25
+        if (community.isEmpty()) {
26
+            return new Deck();
27
+        } else if (!doneFlop || community.size() < 3) {
28
+            return new Deck(community.subList(0, 1));
29
+        } else if (!doneTurn || community.size() < 4) {
30
+            return new Deck(community.subList(0, 3));
31
+        } else if (!doneRiver || community.size() < 5) {
32
+            return new Deck(community.subList(0, 4));
33
+        } else {
34
+            return new Deck(community);
35
+        }
36
+    }
37
+
38
+}

+ 92
- 0
src/com/md87/cardgame/games/CrazyPineapple.java View File

@@ -0,0 +1,92 @@
1
+/*
2
+ * Copyright (c) Chris 'MD87' Smith, 2007. All rights reserved.
3
+ *
4
+ * This code may not be redistributed without prior permission from the
5
+ * aforementioned copyright holder(s).
6
+ */
7
+
8
+package com.md87.cardgame.games;
9
+
10
+import com.md87.cardgame.Player;
11
+
12
+/**
13
+ * Implements a standard local game of Crazy Pineapple.
14
+ * 
15
+ * @author chris
16
+ */
17
+public class CrazyPineapple extends Pineapple {
18
+
19
+    public CrazyPineapple(int numplayers, int bigblind, int ante, int raises) {
20
+        super(numplayers, bigblind, ante, raises);
21
+    }
22
+    
23
+    @Override
24
+    protected void dealPlayerCards() {
25
+        dealCard(players.get((dealer + 1) % numplayers), false);
26
+        dealCard(players.get((dealer + 1) % numplayers), false);
27
+        dealCard(players.get((dealer + 1) % numplayers), false);
28
+    }
29
+
30
+    @Override
31
+    protected void startGame() {
32
+        notifyNewGame();
33
+        
34
+        discardCards();
35
+        shuffle();
36
+        
37
+        community.clear();
38
+        
39
+        doAntes();
40
+        
41
+        doBlinds();
42
+        
43
+        doneFlop = false;
44
+        doneTurn = false;
45
+        doneRiver = false;        
46
+        
47
+        dealPlayerCards();
48
+        
49
+        for (int i = 0; i < 5; i++) {
50
+            community.add(deck.deal());
51
+        }
52
+        
53
+        waitForBets();
54
+        
55
+        if (countPlayers(true, true, false) > 1) {
56
+            doneFlop = true;
57
+            
58
+            doDrawRound(players.get((dealer + 1) % numplayers), 1, 1, false);
59
+            
60
+            doBettingRound();
61
+        }
62
+        
63
+        if (countPlayers(true, true, false) > 1) {
64
+            doneTurn = true;
65
+            
66
+            doBettingRound();
67
+        }
68
+        
69
+        if (countPlayers(true, true, false) > 1) {
70
+            doneRiver = true;
71
+            
72
+            doBettingRound();
73
+        }
74
+        
75
+        if (countPlayers(true, true, false) > 1) {
76
+            doShowDown();
77
+        } else {
78
+            doWinner();
79
+        }
80
+        
81
+        for (Player player : players) {
82
+            if (player.getCash() <= 0) {
83
+                player.setOut();
84
+            }
85
+        }
86
+        
87
+        notifyEndGame();
88
+        
89
+        doDealerAdvance();
90
+    }
91
+    
92
+}

+ 77
- 0
src/com/md87/cardgame/games/FiveCardDraw.java View File

@@ -0,0 +1,77 @@
1
+/*
2
+ * Copyright (c) Chris 'MD87' Smith, 2007. All rights reserved.
3
+ *
4
+ * This code may not be redistributed without prior permission from the
5
+ * aforementioned copyright holder(s).
6
+ */
7
+
8
+package com.md87.cardgame.games;
9
+
10
+import com.md87.cardgame.Deck;
11
+import com.md87.cardgame.Player;
12
+
13
+/**
14
+ * Implements a standard (local) Five Card Draw game.
15
+ * 
16
+ * @author chris
17
+ */
18
+public class FiveCardDraw extends AbstractGame {
19
+
20
+    public FiveCardDraw(int numplayers, int bigblind, int ante, int raises) {
21
+        super(numplayers, bigblind, ante, raises);
22
+    }
23
+
24
+    @Override
25
+    protected void startGame() {
26
+        notifyNewGame();
27
+        
28
+        discardCards();
29
+        shuffle();
30
+        
31
+        doAntes();
32
+        doBlinds();
33
+        
34
+        for (int i = 0; i < 5; i++) {
35
+            dealCard(players.get((dealer + 1) % numplayers), false);
36
+        }
37
+        
38
+        waitForBets();
39
+        
40
+        if (countPlayers(true, true, false) > 1) {
41
+            doDrawRound(players.get((dealer + 1) % numplayers), 0, 5, true);
42
+            doBettingRound();
43
+        }        
44
+        
45
+        if (countPlayers(true, true, false) > 1) {
46
+            doShowDown();
47
+        } else {
48
+            doWinner();
49
+        }
50
+        
51
+        for (Player player : players) {
52
+            if (player.getCash() <= 0) {
53
+                player.setOut();
54
+            }
55
+        }
56
+        
57
+        notifyEndGame();
58
+        
59
+        doDealerAdvance();        
60
+    }
61
+
62
+    @Override
63
+    protected boolean canDoBringIns() {
64
+        return false;
65
+    }
66
+
67
+    @Override
68
+    public int holeCardCount() {
69
+        return 5;
70
+    }
71
+
72
+    @Override
73
+    public Deck getCommunityCards() {
74
+        return new Deck();
75
+    }
76
+
77
+}

+ 86
- 0
src/com/md87/cardgame/games/FiveCardStud.java View File

@@ -0,0 +1,86 @@
1
+/*
2
+ * Copyright (c) Chris 'MD87' Smith, 2007. All rights reserved.
3
+ *
4
+ * This code may not be redistributed without prior permission from the
5
+ * aforementioned copyright holder(s).
6
+ */
7
+
8
+package com.md87.cardgame.games;
9
+
10
+import com.md87.cardgame.Deck;
11
+import com.md87.cardgame.Player;
12
+
13
+/**
14
+ *
15
+ * @author Chris
16
+ */
17
+public class FiveCardStud extends AbstractGame {
18
+
19
+    public FiveCardStud(final int numplayers, final int bigblind, final int ante,
20
+            final int raises) {
21
+        super(numplayers, bigblind, ante, raises);
22
+    }
23
+
24
+    /** {@inheritDoc} */
25
+    public int holeCardCount() {
26
+        return 5;
27
+    }
28
+
29
+    /** {@inheritDoc} */
30
+    public Deck getCommunityCards() {
31
+        return new Deck();
32
+    }
33
+
34
+    protected void startGame() {
35
+        notifyNewGame();
36
+        
37
+        discardCards();
38
+        shuffle();
39
+        
40
+        doAntes();
41
+        
42
+        doBlinds();
43
+        
44
+        dealCard(players.get((dealer + 1) % numplayers), false);
45
+        dealCard(players.get((dealer + 1) % numplayers), true);
46
+        
47
+        waitForBets();
48
+        
49
+        if (countPlayers(true, true, false) > 1) {
50
+            dealCard(players.get((dealer + 1) % numplayers), true);
51
+            doBettingRound();
52
+        }
53
+        
54
+        if (countPlayers(true, true, false) > 1) {
55
+            dealCard(players.get((dealer + 1) % numplayers), true);
56
+            doBettingRound();
57
+        }
58
+        
59
+        if (countPlayers(true, true, false) > 1) {
60
+            dealCard(players.get((dealer + 1) % numplayers), true);
61
+            doBettingRound();
62
+        }
63
+        
64
+        if (countPlayers(true, true, false) > 1) {
65
+            doShowDown();
66
+        } else {
67
+            doWinner();
68
+        }
69
+        
70
+        for (Player player : players) {
71
+            if (player.getCash() <= 0) {
72
+                player.setOut();
73
+            }
74
+        }
75
+        
76
+        notifyEndGame();
77
+        
78
+        doDealerAdvance();
79
+        
80
+    }
81
+
82
+    protected boolean canDoBringIns() {
83
+        return true;
84
+    }
85
+
86
+}

+ 132
- 0
src/com/md87/cardgame/games/OmahaHighLow.java View File

@@ -0,0 +1,132 @@
1
+/*
2
+ * Copyright (c) Chris 'MD87' Smith, 2007. All rights reserved.
3
+ *
4
+ * This code may not be redistributed without prior permission from the
5
+ * aforementioned copyright holder(s).
6
+ */
7
+
8
+package com.md87.cardgame.games;
9
+
10
+import com.md87.cardgame.Card;
11
+import com.md87.cardgame.Deck;
12
+import com.md87.cardgame.Player;
13
+import com.md87.cardgame.Rank;
14
+import com.md87.cardgame.Suit;
15
+import com.md87.cardgame.hands.AceFiveLowHand;
16
+import com.md87.cardgame.hands.StandardHand;
17
+import com.md87.cardgame.interfaces.Hand;
18
+import java.util.Collections;
19
+import java.util.concurrent.Semaphore;
20
+
21
+/**
22
+ * Implements a standard (local) Omaha Hold'em game.
23
+ *
24
+ * @author Chris
25
+ */
26
+public class OmahaHighLow extends OmahaHoldEm {
27
+    
28
+    protected static final Deck minDeck = new Deck(
29
+            new Card(Suit.CLUBS, Rank.EIGHT),
30
+            new Card(Suit.CLUBS, Rank.SEVEN),
31
+            new Card(Suit.CLUBS, Rank.SIX),
32
+            new Card(Suit.CLUBS, Rank.FIVE),
33
+            new Card(Suit.CLUBS, Rank.FOUR)
34
+            );
35
+    
36
+    protected boolean isHigh = true;
37
+    
38
+    protected final Semaphore highSemaphore = new Semaphore(1);
39
+    
40
+    public OmahaHighLow(final int numplayers, final int bigblind, final int ante,
41
+            final int raises) {
42
+        super(numplayers, bigblind, ante, raises);
43
+    }
44
+    
45
+    @Override
46
+    protected void doWinner() {
47
+        if (countPlayers(true, true, false) == 1) {
48
+            doWinner(false);
49
+            return;
50
+        }
51
+        
52
+        highSemaphore.acquireUninterruptibly();
53
+        
54
+        isHigh = false;
55
+        boolean isLowPlayer = false;
56
+        for (Player player : players) {
57
+            if (!player.isOut()) {
58
+                if (new AceFiveLowHand(player.getBestDeck()).getBestRank() != AceFiveLowHand.Ranking.NON_QUALIFIER) {
59
+                    isLowPlayer = true;
60
+                }
61
+            }
62
+        }
63
+        isHigh = true;
64
+        
65
+        if (isLowPlayer) {
66
+            doWinner(true);
67
+            isHigh = false;
68
+            doWinner(true);
69
+            isHigh = true;
70
+        } else {
71
+            doWinner(false);
72
+        }
73
+        
74
+        highSemaphore.release();
75
+    }
76
+    
77
+    @Override
78
+    public Hand getHand(Deck deck) {
79
+        if (isHigh) {
80
+            return new StandardHand(deck);
81
+        } else {
82
+            return new AceFiveLowHand(deck);
83
+        }
84
+    }
85
+    
86
+    /** {@inheritDoc} */
87
+    @Override
88
+    public String getHandText(final Player player) {
89
+        highSemaphore.acquireUninterruptibly();
90
+        
91
+        StringBuffer buff = new StringBuffer("High: ");
92
+        isHigh = true;
93
+        buff.append(getHand(player.getBestDeck()).getFriendlyName());
94
+        buff.append("\nLow: ");
95
+        isHigh = false;
96
+        
97
+        final AceFiveLowHand theHand = new AceFiveLowHand(player.getBestDeck());
98
+        
99
+        if (theHand.getBestRank() == AceFiveLowHand.Ranking.NO_PAIR) {
100
+            final Deck theDeck = theHand.getDeck();
101
+            StringBuffer other = new StringBuffer();
102
+            boolean addAce = false;
103
+            
104
+            Collections.sort(theDeck);
105
+            
106
+            for (Card card : theDeck) {
107
+                if (card.getRank() != Rank.ACE) {
108
+                    other.append('-');
109
+                    other.append("" + (14 - card.getRank().ordinal()));
110
+                } else {
111
+                    addAce = true;
112
+                }
113
+            }
114
+            
115
+            if (addAce) {
116
+                buff.append('A');
117
+                buff.append(other);
118
+            } else {
119
+                buff.append(other.substring(1));
120
+            }
121
+        } else {
122
+            buff.append("doesn't qualify");
123
+        }
124
+        
125
+        isHigh = true;
126
+        
127
+        highSemaphore.release();
128
+        
129
+        return buff.toString();
130
+    }
131
+    
132
+}

+ 132
- 0
src/com/md87/cardgame/games/OmahaHoldEm.java View File

@@ -0,0 +1,132 @@
1
+/*
2
+ * Copyright (c) Chris 'MD87' Smith, 2007. All rights reserved.
3
+ *
4
+ * This code may not be redistributed without prior permission from the
5
+ * aforementioned copyright holder(s).
6
+ */
7
+
8
+package com.md87.cardgame.games;
9
+
10
+import com.md87.cardgame.Deck;
11
+import com.md87.cardgame.Player;
12
+import com.md87.cardgame.interfaces.Hand;
13
+import java.util.ArrayList;
14
+import java.util.Collections;
15
+import java.util.List;
16
+
17
+/**
18
+ * Implements a standard (local) Omaha Hold'em game.
19
+ *
20
+ * @author Chris
21
+ */
22
+public class OmahaHoldEm extends TexasHoldEm {
23
+    
24
+    public OmahaHoldEm(final int numplayers, final int bigblind, final int ante,
25
+            final int raises) {
26
+        super(numplayers, bigblind, ante, raises);
27
+    }
28
+    
29
+    protected void startGame() {
30
+        notifyNewGame();
31
+        
32
+        discardCards();
33
+        shuffle();
34
+        
35
+        community.clear();
36
+        
37
+        doAntes();
38
+        
39
+        doBlinds();
40
+        
41
+        dealCard(players.get((dealer + 1) % numplayers), false);
42
+        dealCard(players.get((dealer + 1) % numplayers), false);
43
+        dealCard(players.get((dealer + 1) % numplayers), false);
44
+        dealCard(players.get((dealer + 1) % numplayers), false);
45
+        
46
+        for (int i = 0; i < 5; i++) {
47
+            community.add(deck.deal());
48
+        }
49
+        
50
+        doneFlop = false;
51
+        doneTurn = false;
52
+        doneRiver = false;
53
+        
54
+        waitForBets();
55
+        
56
+        if (countPlayers(true, true, false) > 1) {
57
+            doneFlop = true;
58
+            
59
+            doBettingRound();
60
+        }
61
+        
62
+        if (countPlayers(true, true, false) > 1) {
63
+            doneTurn = true;
64
+            
65
+            doBettingRound();
66
+        }
67
+        
68
+        if (countPlayers(true, true, false) > 1) {
69
+            doneRiver = true;
70
+            
71
+            doBettingRound();
72
+        }
73
+        
74
+        if (countPlayers(true, true, false) > 1) {
75
+            doShowDown();
76
+        } else {
77
+            doWinner();
78
+        }
79
+        
80
+        for (Player player : players) {
81
+            if (player.getCash() <= 0) {
82
+                player.setOut();
83
+            }
84
+        }
85
+        
86
+        notifyEndGame();
87
+        
88
+        doDealerAdvance();
89
+    }
90
+    
91
+    /** {@inheritDoc} */
92
+    public int holeCardCount() {
93
+        return 4;
94
+    }
95
+    
96
+    @Override
97
+    public Deck getBestDeck(final Deck cards) {
98
+        if(cards.size() != 4) {
99
+            System.err.println("getBestDeck(): card size != 4");
100
+            new Exception().printStackTrace();
101
+            return new Deck();
102
+        }
103
+        
104
+        Deck tempCards = new Deck(cards);
105
+        
106
+        final List<Hand> hands = new ArrayList<Hand>();
107
+        
108
+        for (int i = 0; i < 4; i++) {
109
+            for (int j = i + 1; j < 4; j++) {
110
+                final Deck base = new Deck();
111
+                base.add(tempCards.get(i));
112
+                base.add(tempCards.get(j));
113
+                
114
+                for (int k = 0; k < 5; k++) {
115
+                    for (int l = k + 1; l < 5; l++) {
116
+                        final Deck myDeck = new Deck(getCommunityCards());
117
+                        myDeck.remove(getCommunityCards().get(k));
118
+                        myDeck.remove(getCommunityCards().get(l));
119
+                        myDeck.addAll(base);
120
+                        
121
+                        hands.add(getHand(myDeck));
122
+                    }
123
+                }
124
+            }
125
+        }
126
+        
127
+        Collections.sort(hands);
128
+        
129
+        return hands.get(hands.size() - 1).getDeck();
130
+    }
131
+    
132
+}

+ 35
- 0
src/com/md87/cardgame/games/Pineapple.java View File

@@ -0,0 +1,35 @@
1
+/*
2
+ * Copyright (c) Chris 'MD87' Smith, 2007. All rights reserved.
3
+ *
4
+ * This code may not be redistributed without prior permission from the
5
+ * aforementioned copyright holder(s).
6
+ */
7
+
8
+package com.md87.cardgame.games;
9
+
10
+/**
11
+ * Implements a standard (local) game of Pineapple.
12
+ * 
13
+ * @author chris
14
+ */
15
+public class Pineapple extends TexasHoldEm {
16
+
17
+    public Pineapple(int numplayers, int bigblind, int ante, int raises) {
18
+        super(numplayers, bigblind, ante, raises);
19
+    }
20
+
21
+    @Override
22
+    protected void dealPlayerCards() {
23
+        dealCard(players.get((dealer + 1) % numplayers), false);
24
+        dealCard(players.get((dealer + 1) % numplayers), false);
25
+        dealCard(players.get((dealer + 1) % numplayers), false);
26
+        
27
+        doDrawRound(players.get((dealer + 1) % numplayers), 1, 1, false);
28
+    }
29
+
30
+    @Override
31
+    public int holeCardCount() {
32
+        return 3;
33
+    }
34
+
35
+}

+ 54
- 0
src/com/md87/cardgame/games/RoyalHoldEm.java View File

@@ -0,0 +1,54 @@
1
+/*
2
+ * Copyright (c) Chris 'MD87' Smith, 2007. All rights reserved.
3
+ *
4
+ * This code may not be redistributed without prior permission from the
5
+ * aforementioned copyright holder(s).
6
+ */
7
+
8
+package com.md87.cardgame.games;
9
+
10
+import com.md87.cardgame.Card;
11
+import com.md87.cardgame.Rank;
12
+import com.md87.cardgame.Suit;
13
+import java.util.Collections;
14
+
15
+/**
16
+ * Implements a standard Royal Hold'Em game.
17
+ *
18
+ * @author Chris
19
+ */
20
+public class RoyalHoldEm extends TexasHoldEm {
21
+    
22
+    /**
23
+     * Creates a new instance of RoyalHoldEm.
24
+     *
25
+     * @param numplayers The number of players who are taking part
26
+     * @param bigblind The size of the big blind
27
+     * @param ante The size of the ante
28
+     * @param raises The maximum number of raises per round
29
+     */
30
+    public RoyalHoldEm(final int numplayers, final int bigblind, final int ante,
31
+            final int raises) {
32
+        super(numplayers, bigblind, ante, raises);
33
+        
34
+        this.numplayers = Math.min(6, numplayers);
35
+    }
36
+    
37
+    /** {@inheritDoc} */
38
+    @Override
39
+    protected void shuffle() {
40
+        deck.clear();
41
+        for (Suit suit : Suit.values()) {
42
+            for (Rank rank : Rank.values()) {
43
+                if (rank.compareTo(Rank.TEN) <= 0) {
44
+                    deck.add(new Card(suit, rank));
45
+                }
46
+            }
47
+        }
48
+        
49
+        Collections.shuffle(deck);
50
+    }
51
+    
52
+    
53
+    
54
+}

+ 100
- 0
src/com/md87/cardgame/games/SevenCardStud.java View File

@@ -0,0 +1,100 @@
1
+/*
2
+ * Copyright (c) Chris 'MD87' Smith, 2007. All rights reserved.
3
+ *
4
+ * This code may not be redistributed without prior permission from the
5
+ * aforementioned copyright holder(s).
6
+ */
7
+
8
+package com.md87.cardgame.games;
9
+
10
+import com.md87.cardgame.Deck;
11
+import com.md87.cardgame.Player;
12
+
13
+/**
14
+ *
15
+ * @author Chris
16
+ */
17
+public class SevenCardStud extends AbstractGame {
18
+    
19
+    protected final Deck community = new Deck();
20
+    
21
+    public SevenCardStud(final int numplayers, final int bigblind, final int ante,
22
+            final int raises) {
23
+        super(numplayers, bigblind, ante, raises);
24
+    }
25
+    
26
+    /** {@inheritDoc} */
27
+    public int holeCardCount() {
28
+        return 7;
29
+    }
30
+    
31
+    /** {@inheritDoc} */
32
+    public Deck getCommunityCards() {
33
+        return community;
34
+    }
35
+    
36
+    protected void startGame() {
37
+        notifyNewGame();
38
+        
39
+        discardCards();
40
+        community.clear();
41
+        
42
+        shuffle();
43
+        
44
+        doAntes();
45
+        
46
+        doBlinds();
47
+        
48
+        dealCard(players.get((dealer + 1) % numplayers), false);
49
+        dealCard(players.get((dealer + 1) % numplayers), false);
50
+        dealCard(players.get((dealer + 1) % numplayers), true);
51
+        
52
+        waitForBets();
53
+        
54
+        if (countPlayers(true, true, false) > 1) {
55
+            dealCard(players.get((dealer + 1) % numplayers), true);
56
+            doBettingRound();
57
+        }
58
+        
59
+        if (countPlayers(true, true, false) > 1) {
60
+            dealCard(players.get((dealer + 1) % numplayers), true);
61
+            doBettingRound();
62
+        }
63
+        
64
+        if (countPlayers(true, true, false) > 1) {
65
+            dealCard(players.get((dealer + 1) % numplayers), true);
66
+            doBettingRound();
67
+        }
68
+        
69
+        if (countPlayers(true, true, false) > 1) {
70
+            if (deck.size() >= countPlayers(true, true, false)) {
71
+                dealCard(players.get((dealer + 1) % numplayers), false);
72
+            } else {
73
+                community.add(deck.deal());
74
+                notifyCommunityCardsUpdated();
75
+            }
76
+            doBettingRound();
77
+        }
78
+        
79
+        if (countPlayers(true, true, false) > 1) {
80
+            doShowDown();
81
+        } else {
82
+            doWinner();
83
+        }
84
+        
85
+        for (Player player : players) {
86
+            if (player.getCash() <= 0) {
87
+                player.setOut();
88
+            }
89
+        }
90
+        
91
+        notifyEndGame();
92
+        
93
+        doDealerAdvance();
94
+        
95
+    }
96
+
97
+    protected boolean canDoBringIns() {
98
+        return true;
99
+    }    
100
+}

+ 33
- 0
src/com/md87/cardgame/games/SuperHoldEm.java View File

@@ -0,0 +1,33 @@
1
+/*
2
+ * Copyright (c) Chris 'MD87' Smith, 2007. All rights reserved.
3
+ *
4
+ * This code may not be redistributed without prior permission from the
5
+ * aforementioned copyright holder(s).
6
+ */
7
+
8
+package com.md87.cardgame.games;
9
+
10
+/**
11
+ * Implements a standard (local) Super Hold'em game.
12
+ *
13
+ * @author Chris
14
+ */
15
+public class SuperHoldEm extends TexasHoldEm {
16
+
17
+    public SuperHoldEm(int numplayers, int bigblind, int ante, int raises) {
18
+        super(numplayers, bigblind, ante, raises);
19
+    }
20
+
21
+    @Override
22
+    protected void dealPlayerCards() {
23
+        dealCard(players.get((dealer + 1) % numplayers), false);
24
+        dealCard(players.get((dealer + 1) % numplayers), false);
25
+        dealCard(players.get((dealer + 1) % numplayers), false);
26
+    }
27
+
28
+    @Override
29
+    public int holeCardCount() {
30
+        return 3;
31
+    }
32
+
33
+}

+ 116
- 0
src/com/md87/cardgame/games/TexasHoldEm.java View File

@@ -0,0 +1,116 @@
1
+/*
2
+ * Copyright (c) Chris 'MD87' Smith, 2007. All rights reserved.
3
+ *
4
+ * This code may not be redistributed without prior permission from the
5
+ * aforementioned copyright holder(s).
6
+ */
7
+
8
+package com.md87.cardgame.games;
9
+
10
+import com.md87.cardgame.Deck;
11
+import com.md87.cardgame.Player;
12
+
13
+/**
14
+ * Implements a standard (local) Texas Hold'em game.
15
+ *
16
+ * @author Chris
17
+ */
18
+public class TexasHoldEm extends AbstractGame {
19
+    
20
+    protected final Deck community = new Deck();
21
+    
22
+    protected boolean doneFlop = false;
23
+    protected boolean doneTurn = false;
24
+    protected boolean doneRiver = false;
25
+    
26
+    public TexasHoldEm(final int numplayers, final int bigblind, final int ante,
27
+            final int raises) {
28
+        super(numplayers, bigblind, ante, raises);
29
+    }
30
+    
31
+    protected void dealPlayerCards() {
32
+        dealCard(players.get((dealer + 1) % numplayers), false);
33
+        dealCard(players.get((dealer + 1) % numplayers), false);
34
+    }
35
+    
36
+    protected void startGame() {
37
+        notifyNewGame();
38
+        
39
+        discardCards();
40
+        shuffle();
41
+        
42
+        community.clear();
43
+        
44
+        doAntes();
45
+        
46
+        doBlinds();
47
+        
48
+        doneFlop = false;
49
+        doneTurn = false;
50
+        doneRiver = false;        
51
+        
52
+        dealPlayerCards();
53
+        
54
+        for (int i = 0; i < 5; i++) {
55
+            community.add(deck.deal());
56
+        }
57
+        
58
+        waitForBets();
59
+        
60
+        if (countPlayers(true, true, false) > 1) {
61
+            doneFlop = true;
62
+            
63
+            doBettingRound();
64
+        }
65
+        
66
+        if (countPlayers(true, true, false) > 1) {
67
+            doneTurn = true;
68
+            
69
+            doBettingRound();
70
+        }
71
+        
72
+        if (countPlayers(true, true, false) > 1) {
73
+            doneRiver = true;
74
+            
75
+            doBettingRound();
76
+        }
77
+        
78
+        if (countPlayers(true, true, false) > 1) {
79
+            doShowDown();
80
+        } else {
81
+            doWinner();
82
+        }
83
+        
84
+        for (Player player : players) {
85
+            if (player.getCash() <= 0) {
86
+                player.setOut();
87
+            }
88
+        }
89
+        
90
+        notifyEndGame();
91
+        
92
+        doDealerAdvance();
93
+    }
94
+    
95
+    /** {@inheritDoc} */
96
+    public Deck getCommunityCards() {
97
+        if (!doneFlop || community.size() < 3) {
98
+            return new Deck();
99
+        } else if (!doneTurn || community.size() < 4) {
100
+            return new Deck(community.subList(0, 3));
101
+        } else if (!doneRiver || community.size() < 5) {
102
+            return new Deck(community.subList(0, 4));
103
+        } else {
104
+            return new Deck(community);
105
+        }
106
+    }
107
+    
108
+    /** {@inheritDoc} */
109
+    public int holeCardCount() {
110
+        return 2;
111
+    }
112
+    
113
+    protected boolean canDoBringIns() {
114
+        return true;
115
+    }
116
+}

+ 222
- 0
src/com/md87/cardgame/hands/AbstractHand.java View File

@@ -0,0 +1,222 @@
1
+/*
2
+ * Copyright (c) Chris 'MD87' Smith, 2007. All rights reserved.
3
+ *
4
+ * This code may not be redistributed without prior permission from the
5
+ * aforementioned copyright holder(s).
6
+ */
7
+
8
+package com.md87.cardgame.hands;
9
+
10
+import com.md87.cardgame.Deck;
11
+import com.md87.cardgame.Rank;
12
+import com.md87.cardgame.Suit;
13
+import com.md87.cardgame.interfaces.Hand;
14
+
15
+import java.util.Collections;
16
+
17
+/**
18
+ *
19
+ * @author Chris
20
+ */
21
+public abstract class AbstractHand implements Hand {
22
+    
23
+    protected Deck cards;
24
+    
25
+    protected Rank high;
26
+    protected Rank low;
27
+    protected Deck kickers = new Deck();
28
+    
29
+    protected boolean usesLow = false;
30
+    protected boolean usesAllCards = false;
31
+    
32
+    public Rank getHigh() {
33
+        return high;
34
+    }
35
+    
36
+    public Rank getLow() {
37
+        return low;
38
+    }
39
+    
40
+    public Deck getDeck() {
41
+        return cards;
42
+    }
43
+    
44
+    public Deck getKickers() {
45
+        return kickers;
46
+    }    
47
+    
48
+    protected boolean isStraightFlush(final Deck deck) {
49
+        usesLow = false;
50
+        usesAllCards = false;
51
+        
52
+        for (Suit suit : Suit.values()) {
53
+            Deck mySuit = deck.getSuit(suit);
54
+            
55
+            if (isStraight(mySuit)) {
56
+                return true;
57
+            }
58
+        }
59
+        
60
+        return false;
61
+    }
62
+    
63
+    protected boolean isFourOfAKind(final Deck deck) {
64
+        usesLow = false;
65
+        usesAllCards = false;
66
+        
67
+        for (Rank rank : Rank.values()) {
68
+            if (deck.getRank(rank).size() == 4) {
69
+                high = rank;
70
+                kickers = new Deck(deck);
71
+                kickers.removeByRank(high, 4);
72
+                kickers.limitTo(1);
73
+                return true;
74
+            }
75
+        }
76
+        
77
+        return false;
78
+    }
79
+    
80
+    protected boolean isFullHouse(final Deck deck) {
81
+        usesLow = true;
82
+        usesAllCards = false;
83
+        high = null;
84
+        low = null;
85
+        
86
+        for (Rank rank : Rank.values()) {
87
+            if (high == null && deck.getRank(rank).size() >= 3) {
88
+                high = rank;
89
+            } else if (low == null && deck.getRank(rank).size() >= 2) {
90
+                low = rank;
91
+            }
92
+            
93
+            if (high != null && low != null) {
94
+                return true;
95
+            }
96
+        }
97
+        
98
+        return false;
99
+    }
100
+    
101
+    protected boolean isFlush(final Deck deck) {
102
+        usesLow = false;
103
+        usesAllCards = true;
104
+        
105
+        for (Suit suit : Suit.values()) {
106
+            Deck myDeck = deck.getSuit(suit);
107
+            
108
+            if (myDeck.size() >= 5) {    
109
+                Collections.sort(myDeck);
110
+                
111
+                high = myDeck.get(0).getRank();
112
+                kickers.clear();
113
+                
114
+                myDeck.limitTo(5);
115
+                deck.clear();
116
+                deck.addAll(myDeck);
117
+                
118
+                return true;
119
+            }
120
+        }
121
+        
122
+        return false;
123
+    }
124
+    
125
+    protected boolean isStraight(final Deck deck) {
126
+        usesLow = false;
127
+        usesAllCards = false;
128
+        
129
+        for (Rank rank : Rank.values()) {
130
+            high = rank;
131
+            low = rank;
132
+            
133
+            kickers.clear();
134
+            
135
+            boolean fail = false;
136
+            
137
+            for (int i = 0; i < 5; i++) {
138
+                if (low == null || deck.getRank(low).size() == 0) {
139
+                    fail = true;
140
+                    break;
141
+                }
142
+                
143
+                if (low == Rank.DEUCE && i == 3) {
144
+                    low = Rank.ACE;
145
+                } else {
146
+                    low = low.getLower();
147
+                }
148
+            }
149
+            
150
+            if (!fail) {
151
+                low = null;
152
+                return true;
153
+            }
154
+        }
155
+        
156
+        low = null;
157
+        return false;
158
+    }
159
+    
160
+    protected boolean isThreeOfAKind(final Deck deck) {
161
+        usesLow = false;
162
+        usesAllCards = false;
163
+        
164
+        for (Rank rank : Rank.values()) {
165
+            if (deck.getRank(rank).size() == 3) {
166
+                high = rank;
167
+                kickers = new Deck(deck);
168
+                kickers.removeByRank(high, 3);
169
+                kickers.limitTo(2);
170
+                return true;
171
+            }
172
+        }
173
+        
174
+        return false;
175
+    }
176
+    
177
+    protected boolean isTwoPairs(final Deck deck) {
178
+        usesLow = true;
179
+        usesAllCards = false;
180
+        
181
+        high = null;
182
+        low = null;
183
+        
184
+        kickers = new Deck(deck);
185
+        
186
+        for (Rank rank : Rank.values()) {
187
+            Deck myDeck = deck.getRank(rank);
188
+            
189
+            if (myDeck.size() == 2) {
190
+                if (high == null) {
191
+                    high = rank;
192
+                    kickers.removeByRank(rank, 2);
193
+                } else {
194
+                    low = rank;
195
+                    kickers.removeByRank(rank, 2);
196
+                    kickers.limitTo(1);
197
+                    return true;
198
+                }
199
+            }
200
+        }
201
+        
202
+        return false;
203
+    }
204
+    
205
+    protected boolean isOnePair(final Deck deck) {
206
+        usesLow = false;
207
+        usesAllCards = false;
208
+        
209
+        for (Rank rank : Rank.values()) {
210
+            if (deck.getRank(rank).size() > 1) {
211
+                high = rank;
212
+                kickers = new Deck(deck);
213
+                kickers.removeByRank(high, 2);
214
+                kickers.limitTo(3);
215
+                return true;
216
+            }
217
+        }
218
+        
219
+        return false;
220
+    }
221
+    
222
+}

+ 87
- 0
src/com/md87/cardgame/hands/AceFiveLowHand.java View File

@@ -0,0 +1,87 @@
1
+/*
2
+ * Copyright (c) Chris 'MD87' Smith, 2007. All rights reserved.
3
+ *
4
+ * This code may not be redistributed without prior permission from the
5
+ * aforementioned copyright holder(s).
6
+ */
7
+
8
+package com.md87.cardgame.hands;
9
+
10
+import com.md87.cardgame.Card;
11
+import com.md87.cardgame.Deck;
12
+import com.md87.cardgame.Rank;
13
+import com.md87.cardgame.interfaces.Hand;
14
+
15
+/**
16
+ *
17
+ * @author Chris
18
+ */
19
+public class AceFiveLowHand extends AbstractHand {
20
+    
21
+    public static enum Ranking {
22
+        NO_PAIR,
23
+        
24
+        NON_QUALIFIER
25
+    }
26
+    
27
+    protected Ranking bestRank;
28
+    
29
+    public AceFiveLowHand(final Deck cards) {
30
+        this.cards = cards;
31
+        
32
+        bestRank = AceFiveLowHand.Ranking.NON_QUALIFIER;
33
+        
34
+        while (isOnePair(cards)) {
35
+            cards.removeByRank(high, 1);
36
+        }
37
+        
38
+        boolean valid = true;
39
+        
40
+        if (cards.size() >= 5) {
41
+            kickers = new Deck(cards);
42
+            kickers.reverseLimitTo(5);
43
+            
44
+            for (Card kicker : kickers) {
45
+                if (kicker.getRank().compareTo(Rank.NINE, true) <= 0) {
46
+                    valid = false;
47
+                }
48
+            }
49
+        } else {
50
+            valid = false;
51
+        }
52
+        
53
+        if (valid) {
54
+            bestRank = Ranking.NO_PAIR;
55
+        }
56
+    }
57
+    
58
+    public String getFriendlyName() {
59
+        switch (bestRank) {
60
+        case NO_PAIR:
61
+            return kickers.toString();
62
+        case NON_QUALIFIER:
63
+            return "(Doesn't qualify)";
64
+        default:
65
+            return "Unknown hand";
66
+        }
67
+    }
68
+    
69
+    public Ranking getBestRank() {
70
+        return bestRank;
71
+    }
72
+    
73
+    public int compareTo(Hand ob) {
74
+        final AceFiveLowHand o = (AceFiveLowHand) ob;
75
+        
76
+        if (o.getBestRank() == bestRank) {
77
+            if (bestRank == Ranking.NON_QUALIFIER) {
78
+                return 0;
79
+            } else {
80
+                return -1 * kickers.compareTo(o.getKickers(), true);
81
+            }
82
+        } else {
83
+            return -1 * bestRank.compareTo(o.getBestRank());
84
+        }
85
+    }
86
+    
87
+}

+ 127
- 0
src/com/md87/cardgame/hands/StandardHand.java View File

@@ -0,0 +1,127 @@
1
+/*
2
+ * Copyright (c) Chris 'MD87' Smith, 2007. All rights reserved.
3
+ *
4
+ * This code may not be redistributed without prior permission from the
5
+ * aforementioned copyright holder(s).
6
+ */
7
+
8
+package com.md87.cardgame.hands;
9
+
10
+import com.md87.cardgame.Deck;
11
+import com.md87.cardgame.interfaces.Hand;
12
+
13
+/**
14
+ *
15
+ * @author Chris
16
+ */
17
+public class StandardHand extends AbstractHand {
18
+    
19
+    public static enum Ranking {
20
+        STRAIGHT_FLUSH,
21
+        FOUR_OF_A_KIND,
22
+        FULL_HOUSE,
23
+        FLUSH,
24
+        STRAIGHT,
25
+        THREE_OF_A_KIND,
26
+        TWO_PAIR,
27
+        ONE_PAIR,
28
+        NO_PAIR
29
+    };
30
+    
31
+    protected Ranking bestRank;
32
+    
33
+    public StandardHand(final Deck cards) {
34
+        this.cards = cards;
35
+        
36
+        if (isStraightFlush(cards)) {
37
+            bestRank = StandardHand.Ranking.STRAIGHT_FLUSH;
38
+        } else if (isFourOfAKind(cards)) {
39
+            bestRank = StandardHand.Ranking.FOUR_OF_A_KIND;
40
+        } else if (isFullHouse(cards)) {
41
+            bestRank = StandardHand.Ranking.FULL_HOUSE;
42
+        } else if (isFlush(cards)) {
43
+            bestRank = StandardHand.Ranking.FLUSH;
44
+        } else if (isStraight(cards)) {
45
+            bestRank = StandardHand.Ranking.STRAIGHT;
46
+        } else if (isThreeOfAKind(cards)) {
47
+            bestRank = StandardHand.Ranking.THREE_OF_A_KIND;
48
+        } else if (isTwoPairs(cards)) {
49
+            bestRank = StandardHand.Ranking.TWO_PAIR;
50
+        } else if (isOnePair(cards)) {
51
+            bestRank = StandardHand.Ranking.ONE_PAIR;
52
+        } else {
53
+            high = null;
54
+            low = null;
55
+            usesLow = false;
56
+            usesAllCards = false;
57
+            kickers = new Deck(cards);
58
+            kickers.limitTo(5);
59
+            
60
+            bestRank = StandardHand.Ranking.NO_PAIR;
61
+        }
62
+    }
63
+    
64
+    public Ranking getBestRank() {
65
+        return bestRank;
66
+    }
67
+    
68
+    public int compareTo(final Hand ob) {
69
+        final StandardHand o = (StandardHand) ob;
70
+        
71
+        if (o.getBestRank() == bestRank) {
72
+            if (o.getHigh() == high) {
73
+                
74
+                if (usesLow && low != o.getLow()) {
75
+                    return -1 * low.compareTo(o.getLow());
76
+                }
77
+                
78
+                if (usesAllCards) {
79
+                    Deck myCards = new Deck(cards);
80
+                    myCards.removeAll(kickers);
81
+                    
82
+                    Deck theirCards = new Deck(o.getDeck());
83
+                    theirCards.removeAll(o.getKickers());
84
+                    
85
+                    int result = myCards.compareTo(theirCards);
86
+                    
87
+                    if (result != 0) {
88
+                        return result;
89
+                    }
90
+                }
91
+                
92
+                return kickers.compareTo(o.getKickers());
93
+            } else {
94
+                return -1 * high.compareTo(o.getHigh());
95
+            }
96
+        } else {
97
+            return -1 * bestRank.compareTo(o.getBestRank());
98
+        }
99
+    }
100
+        
101
+    public String getFriendlyName() {
102
+        switch (bestRank) {
103
+        case FLUSH:
104
+            return "Flush";
105
+        case FOUR_OF_A_KIND:
106
+            return "Four of a kind: " + high.capitalise() + "s";
107
+        case FULL_HOUSE:
108
+            return "Full house: " + high.capitalise() + "s full of "
109
+                    + low.capitalise() + "s";
110
+        case NO_PAIR:
111
+            return "No pair";
112
+        case ONE_PAIR:
113
+            return "One pair: " + high.capitalise() + "s";
114
+        case STRAIGHT:
115
+            return "Straight: " + high.capitalise() + " high";
116
+        case STRAIGHT_FLUSH:
117
+            return "Straight flush: " + high.capitalise() + " high";
118
+        case THREE_OF_A_KIND:
119
+            return "Three of a kind: " + high.capitalise() + "s";
120
+        case TWO_PAIR:
121
+            return "Two pair: " + high.capitalise() + "s over "
122
+                    + low.capitalise() + "s";
123
+        default:
124
+            return "Unknown hand";
125
+        }
126
+    }
127
+}

+ 145
- 0
src/com/md87/cardgame/interfaces/Game.java View File

@@ -0,0 +1,145 @@
1
+/*
2
+ * Copyright (c) Chris 'MD87' Smith, 2007. All rights reserved.
3
+ *
4
+ * This code may not be redistributed without prior permission from the
5
+ * aforementioned copyright holder(s).
6
+ */
7
+
8
+package com.md87.cardgame.interfaces;
9
+
10
+import com.md87.cardgame.Deck;
11
+import com.md87.cardgame.Player;
12
+
13
+import java.util.List;
14
+
15
+/**
16
+ * Defines a standard interface for games.
17
+ *
18
+ * @author Chris
19
+ */
20
+public interface Game {
21
+    
22
+    /**
23
+     * Starts a new tournament.
24
+     */
25
+    void startTournament();
26
+    
27
+    /**
28
+     * Returns the current total size of the pot.
29
+     *
30
+     * @return The size of the pot
31
+     */
32
+    int getCurrentPot();
33
+    
34
+    /**
35
+     * Returns the number of hole cards generally used by this game.
36
+     * 
37
+     * @return The usual number of hole cards
38
+     */
39
+    int holeCardCount();
40
+    
41
+    /**
42
+     * Returns the player who currently holds the dealer token.
43
+     *
44
+     * @return The current dealer
45
+     */
46
+    Player getDealer();
47
+    
48
+    /**
49
+     * Returns the (visible) community cards.
50
+     *
51
+     * @return The community cards
52
+     */
53
+    Deck getCommunityCards();
54
+    
55
+    /**
56
+     * Retrieves the size of the big blind for this game.
57
+     *
58
+     * @return The size of the big blind
59
+     */
60
+    int getBigBlind();
61
+    
62
+    /**
63
+     * Retrieves the size of the maximum bet that has been placed.
64
+     *
65
+     * @return The maximum bet
66
+     */
67
+    int getMaxBet();
68
+    
69
+    /**
70
+     * Retrieves a list of players that are part of this game.
71
+     *
72
+     * @return A list of players participating in the game
73
+     */
74
+    List<Player> getPlayers();
75
+    
76
+    /**
77
+     * Adds a new player to this game.
78
+     *
79
+     * @param name The name of the player that's being added
80
+     * @param cash The amount of cash the player has
81
+     * @param controller The controller for the player
82
+     */
83
+    void addPlayer(String name, int cash, PlayerController controller);    
84
+    
85
+    /**
86
+     * Adds a new player to this game.
87
+     *
88
+     * @param player The player to be added
89
+     */
90
+    void addPlayer(Player player);
91
+    
92
+    /**
93
+     * Retrieves the total number of players in this game.
94
+     *
95
+     * @return The number of players in this game
96
+     */
97
+    int getNumPlayers();
98
+    
99
+    /**
100
+     * Retrieves the best possible deck made up of the community cards and
101
+     * some of the specified hole cards, if applicable.
102
+     * 
103
+     * @param cards The hole cards to be used
104
+     * @return The best possible deck made up of the hole and community cards
105
+     */
106
+    Deck getBestDeck(final Deck cards);
107
+    
108
+    /**
109
+     * Determines if this game has an active, local, human player.
110
+     *
111
+     * @return True if the game has an active, local, human player.
112
+     */
113
+    boolean hasActiveHuman();
114
+    
115
+    /**
116
+     * Retrieves a hand for the specified deck.
117
+     * 
118
+     * @param deck The deck to be used for the hand
119
+     * @return A hand containing the cards in the specified deck
120
+     */
121
+    Hand getHand(final Deck deck);
122
+    
123
+    /**
124
+     * Retrieve the text to display for the specified player's hand(s).
125
+     * 
126
+     * @param player The player whose text should be determined
127
+     * @return A textual description of the player's hand(s).
128
+     */
129
+    String getHandText(final Player player);
130
+    
131
+    /**
132
+     * Registers a new game observer for this game.
133
+     *
134
+     * @param observer The game observer to be registered
135
+     */
136
+    void registerObserver(GameObserver observer);
137
+    
138
+    /**
139
+     * Unregisters a game observer for this game.
140
+     *
141
+     * @param observer The game observer to be unregistered
142
+     */
143
+    void unregisterObserver(GameObserver observer);
144
+    
145
+}

+ 53
- 0
src/com/md87/cardgame/interfaces/GameObserver.java View File

@@ -0,0 +1,53 @@
1
+/*
2
+ * Copyright (c) Chris 'MD87' Smith, 2007. All rights reserved.
3
+ *
4
+ * This code may not be redistributed without prior permission from the
5
+ * aforementioned copyright holder(s).
6
+ */
7
+
8
+package com.md87.cardgame.interfaces;
9
+
10
+import com.md87.cardgame.Card;
11
+import com.md87.cardgame.Player;
12
+
13
+/**
14
+ *
15
+ * @author Chris
16
+ */
17
+public interface GameObserver {
18
+
19
+    void communityCardsUpdated();
20
+    
21
+    void playerCardsUpdated();
22
+    
23
+    void cardDealt(final Player player, final Card card);
24
+    
25
+    void playersTurn(final Player player);
26
+    
27
+    void newPlayer(final Player player);
28
+    
29
+    void newGame();
30
+    
31
+    void endGame();
32
+    
33
+    void setDealer(final Player player);
34
+    
35
+    void placeBlind(final Player player, final int blind, final String name);
36
+    
37
+    void raise(final Player player, final int amount);
38
+    
39
+    void fold(final Player player);
40
+    
41
+    void call(final Player player);
42
+    
43
+    void check(final Player player);
44
+    
45
+    void open(final Player player, final int amount);
46
+    
47
+    void winner(final Player players);
48
+    
49
+    void discards(final Player player, final int number);
50
+    
51
+    void showdown();
52
+
53
+}

+ 22
- 0
src/com/md87/cardgame/interfaces/Hand.java View File

@@ -0,0 +1,22 @@
1
+/*
2
+ * Copyright (c) Chris 'MD87' Smith, 2007. All rights reserved.
3
+ *
4
+ * This code may not be redistributed without prior permission from the
5
+ * aforementioned copyright holder(s).
6
+ */
7
+
8
+package com.md87.cardgame.interfaces;
9
+
10
+import com.md87.cardgame.Deck;
11
+
12
+/**
13
+ *
14
+ * @author Chris
15
+ */
16
+public interface Hand extends Comparable<Hand> {
17
+    
18
+    String getFriendlyName();
19
+
20
+    Deck getDeck();
21
+    
22
+}

+ 83
- 0
src/com/md87/cardgame/interfaces/PlayerController.java View File

@@ -0,0 +1,83 @@
1
+/*
2
+ * Copyright (c) Chris 'MD87' Smith, 2007. All rights reserved.
3
+ *
4
+ * This code may not be redistributed without prior permission from the
5
+ * aforementioned copyright holder(s).
6
+ */
7
+
8
+package com.md87.cardgame.interfaces;
9
+
10
+import com.md87.cardgame.Deck;
11
+import com.md87.cardgame.Player;
12
+import com.md87.cardgame.Player.CallRaiseFold;
13
+import com.md87.cardgame.Player.OpenCheck;
14
+
15
+/**
16
+ * Defines the standard methods required for a player controller.
17
+ * 
18
+ * @author Chris
19
+ */
20
+public interface PlayerController {
21
+   
22
+    /**
23
+     * Determine whether the player will call, raise or fold.
24
+     * 
25
+     * @param callAmount The amount the player needs to put in the pot to call
26
+     * @param canRaise Whether the player can raise or not
27
+     * @return The player's selected action
28
+     */
29
+    CallRaiseFold doCallRaiseFold(final int callAmount, boolean canRaise);
30
+    
31
+    /**
32
+     * Determine whether the player will open or check.
33
+     * 
34
+     * @return The player's selected action
35
+     */
36
+    OpenCheck doOpenCheck();
37
+    
38
+    /**
39
+     * Indicates whether this player's cards should be shown locally.
40
+     * 
41
+     * @return True if the cards should be shown, false otherwise
42
+     */
43
+    boolean shouldShowCards();
44
+    
45
+    /**
46
+     * Sets the player that this controller is controlling.
47
+     * 
48
+     * @param player The player that this controller is controlling
49
+     */
50
+    void setPlayer(final Player player);
51
+    
52
+    /**
53
+     * Sets the game that the player is playing in.
54
+     * 
55
+     * @param game The game that is being played
56
+     */
57
+    void setGame(final Game game);
58
+    
59
+    /**
60
+     * Determine the amount that the player wishes to open or raise by.
61
+     * 
62
+     * @param minimum The minimum raise or opening amount
63
+     * @return The player's chosen amount
64
+     */
65
+    int getRaise(final int minimum);
66
+    
67
+    /**
68
+     * Determines if this controller represents a local human or not.
69
+     * 
70
+     * @return True iff the controller represents a local human
71
+     */
72
+    boolean isLocalHuman();
73
+    
74
+    /**
75
+     * Determines which cards (if any) this controller wishes to discard.
76
+     * 
77
+     * @param minimum The minimum number of cards to be discarded
78
+     * @param maximum The maximum number of cards to be discarded
79
+     * @return A deck containing the cards that are being discarded
80
+     */
81
+    Deck discardCards(final int minimum, final int maximum);
82
+
83
+}

BIN
src/com/md87/cardgame/res/Thumbs.db View File


BIN
src/com/md87/cardgame/res/back1.png View File


BIN
src/com/md87/cardgame/res/back2.png View File


BIN
src/com/md87/cardgame/res/cace.png View File


BIN
src/com/md87/cardgame/res/cdeuce.png View File


BIN
src/com/md87/cardgame/res/ceight.png View File


BIN
src/com/md87/cardgame/res/cfive.png View File


BIN
src/com/md87/cardgame/res/cfour.png View File


BIN
src/com/md87/cardgame/res/chip.pdn View File


BIN
src/com/md87/cardgame/res/chip1.png View File


BIN
src/com/md87/cardgame/res/cjack.png View File


BIN
src/com/md87/cardgame/res/cking.png View File


BIN
src/com/md87/cardgame/res/cnine.png View File


BIN
src/com/md87/cardgame/res/cqueen.png View File


BIN
src/com/md87/cardgame/res/cseven.png View File


BIN
src/com/md87/cardgame/res/csix.png View File


BIN
src/com/md87/cardgame/res/cten.png View File


BIN
src/com/md87/cardgame/res/cthree.png View File


BIN
src/com/md87/cardgame/res/dace.png View File


BIN
src/com/md87/cardgame/res/ddeuce.png View File


BIN
src/com/md87/cardgame/res/deight.png View File


BIN
src/com/md87/cardgame/res/dfive.png View File


BIN
src/com/md87/cardgame/res/dfour.png View File


BIN
src/com/md87/cardgame/res/djack.png View File


BIN
src/com/md87/cardgame/res/dking.png View File


BIN
src/com/md87/cardgame/res/dnine.png View File


BIN
src/com/md87/cardgame/res/dqueen.png View File


BIN
src/com/md87/cardgame/res/dseven.png View File


BIN
src/com/md87/cardgame/res/dsix.png View File


BIN
src/com/md87/cardgame/res/dten.png View File


BIN
src/com/md87/cardgame/res/dthree.png View File


BIN
src/com/md87/cardgame/res/hace.png View File


BIN
src/com/md87/cardgame/res/hdeuce.png View File


+ 0
- 0
src/com/md87/cardgame/res/height.png View File


Some files were not shown because too many files changed in this diff

Loading…
Cancel
Save