Browse Source

stud at 45%

Nick Satinover 6 years ago
parent
commit
450b13f21a

+ 14
- 23
src/main/java/io/zipcoder/casino/Stud.java View File

@@ -18,12 +18,12 @@ public class Stud extends CardGame implements Game {
18 18
      * Determine what player wins by looping through player array and then
19 19
      * passing each hand to the 'handValue' method
20 20
      */
21
-    public CardPlayer determineWinner(){
21
+    public CardPlayer determineWinner(ArrayList<CardPlayer> players){
22 22
         int max = 0;
23 23
         CardPlayer winner = null;
24 24
 
25
-        for(int i = 0; i < getPlayers().size(); i ++){
26
-            CardPlayer player = getPlayers().get(i);
25
+        for(int i = 0; i < players.size(); i ++){
26
+            CardPlayer player = players.get(i);
27 27
             int playerHandValue = handValue(player); // 'handValue' method sets 'max' value of this hand
28 28
             if(playerHandValue > max){
29 29
                 max = playerHandValue;
@@ -64,7 +64,7 @@ public class Stud extends CardGame implements Game {
64 64
      * @param card1
65 65
      * @return
66 66
      */
67
-    private int threeOfAKindHandValue(int card1){
67
+    public int threeOfAKindHandValue(int card1){
68 68
         int handValue;
69 69
         handValue = card1 * 1000000;
70 70
         return handValue;
@@ -77,7 +77,7 @@ public class Stud extends CardGame implements Game {
77 77
      * @param card3
78 78
      * @return
79 79
      */
80
-    private int onePairHandValue(int card1, int card2, int card3){
80
+    public int onePairHandValue(int card1, int card2, int card3){
81 81
         int handValue = 0;
82 82
 
83 83
         if (card1 == card2){
@@ -100,8 +100,8 @@ public class Stud extends CardGame implements Game {
100 100
      * @param card3
101 101
      * @return
102 102
      */
103
-    private int highCardHandValue(int card1, int card2, int card3){
104
-        int handValue;
103
+    public int highCardHandValue(int card1, int card2, int card3){
104
+        int handValue = 0;
105 105
         // Card1 is Highest
106 106
         if (card1 > card2 && card1 > card3 && card2 > card3) {
107 107
             handValue = (card1 * 100) + (card2 * 10) + card3;
@@ -117,26 +117,16 @@ public class Stud extends CardGame implements Game {
117 117
             handValue = (card2 * 100) + (card3 * 10) + card1;
118 118
         }
119 119
         // Card3 is Highest
120
-        else if (card3 > card1 && card3 > card2 && card1 > card3) {
121
-            handValue = (card3 * 100) + (card1 * 10) + card3;
120
+        else if (card3 > card1 && card3 > card2 && card1 > card2) {
121
+            handValue = (card3 * 100) + (card1 * 10) + card2;
122 122
         }
123
-        else if (card3 > card1 && card3 > card2 && card3 > card1) {
124
-            handValue = (card3 * 100) + (card3 * 10) + card1;
125
-        }
126
-        else {
127
-            handValue = 0;
123
+        else if (card3 > card1 && card3 > card2 && card2 > card1) {
124
+            handValue = (card3 * 100) + (card2 * 10) + card1;
128 125
         }
126
+        else {}
129 127
         return handValue;
130 128
     }
131 129
 
132
-
133
-    public void payout(){
134
-        if(super.getWinner() != null){
135
-            super.getWinner().changeBalance(super.getTablePot());
136
-        }
137
-        System.out.println(getWinner().getName() + " won: " + super.getTablePot());
138
-    }
139
-
140 130
     public void payAnte() {
141 131
         for(int i = 0; i < super.getPlayers().size(); i ++)
142 132
         {
@@ -164,7 +154,7 @@ public class Stud extends CardGame implements Game {
164 154
         gameRound2();
165 155
         flipCard();
166 156
         lastGameRound();
167
-        determineWinner();
157
+        determineWinner(this.getPlayers()); //TEST ADDED ARGUMENT
168 158
     }
169 159
 
170 160
 
@@ -237,5 +227,6 @@ public class Stud extends CardGame implements Game {
237 227
     }
238 228
 
239 229
     public void quit() {}
230
+    // public void payout(){ }
240 231
 }
241 232
 

+ 215
- 7
src/test/java/io/zipcoder/casino/StudTest.java View File

@@ -1,18 +1,226 @@
1 1
 package io.zipcoder.casino;
2 2
 
3
+import org.junit.Assert;
4
+import org.junit.Before;
3 5
 import org.junit.Test;
4 6
 
7
+import java.util.ArrayList;
8
+
5 9
 public class StudTest {
6
-    public static void main(String[] args){
7
-        Casino casino = new Casino();
8
-        //get a player
9
-        casino.setPlayer(casino.getConsole().createAccount());
10
-        //player picks game
11
-        casino.chooseGame();
10
+
11
+    Stud stud = new Stud(10);
12
+    ArrayList<CardPlayer> players = new ArrayList<>();
13
+    CardPlayer cardPlayer1;
14
+    CardPlayer cardPlayer2;
15
+
16
+    @Before
17
+    public void setup(){
18
+        ArrayList<Card> cardsTest1 = new ArrayList<>();
19
+        Player player1 = new Player("Player1", 10);
20
+        this.cardPlayer1 = new CardPlayer(player1);
21
+        Card cardSix = new Card(Card.CardValue.SIX, Card.Suit.HEARTS);   //SIX   - 600
22
+        Card cardFive = new Card(Card.CardValue.FIVE, Card.Suit.HEARTS); //FIVE  -  50
23
+        Card cardFour = new Card(Card.CardValue.FOUR, Card.Suit.HEARTS); //FOUR  -   4
24
+        cardsTest1.add(cardSix); cardsTest1.add(cardFive); cardsTest1.add(cardFour);
25
+        this.cardPlayer1.setHand(cardsTest1);
26
+
27
+        ArrayList<Card> cardsTest2 = new ArrayList<>();
28
+        Player player2 = new Player("Player2", 10);
29
+        this.cardPlayer2 = new CardPlayer(player2);
30
+        Card cardSeven = new Card(Card.CardValue.SEVEN, Card.Suit.HEARTS);
31
+        Card cardEight = new Card(Card.CardValue.EIGHT, Card.Suit.HEARTS);
32
+        Card cardNine = new Card(Card.CardValue.NINE, Card.Suit.HEARTS);
33
+        cardsTest2.add(cardSeven); cardsTest2.add(cardEight); cardsTest2.add(cardNine);
34
+        this.cardPlayer2.setHand(cardsTest2);
35
+
36
+        players.add(this.cardPlayer1);
37
+        players.add(this.cardPlayer2);
38
+
39
+    }
40
+
41
+    @Test
42
+    public void highCardHandValueTest(){
43
+        //WHEN
44
+        int card1 = 14; //ACE   - 1400
45
+        int card2 = 13; //KING  -  130
46
+        int card3 = 12; //QUEEN -   12
47
+        //THEN
48
+        int expected = 1542;
49
+        int actual = stud.highCardHandValue(card1, card2, card3);
50
+
51
+        Assert.assertEquals(expected, actual);
52
+    }
53
+
54
+    @Test
55
+    public void highCardHandValueTest2(){
56
+        //WHEN
57
+        int card2 = 11; //JACK  -    110
58
+        int card1 =  9; //NINE   -    09
59
+        int card3 = 12; //QUEEN -   1200
60
+        //THEN
61
+        int expected = 1319;
62
+        int actual = stud.highCardHandValue(card1, card2, card3);
63
+
64
+        Assert.assertEquals(expected, actual);
65
+    }
66
+
67
+    @Test
68
+    public void highCardHandValueTest3(){
69
+        //WHEN
70
+        int card1 = 11; //JACK  -    110
71
+        int card2 =  9; //NINE   -    09
72
+        int card3 = 12; //QUEEN -   1200
73
+        //THEN
74
+        int expected = 1319;
75
+        int actual = stud.highCardHandValue(card2, card3, card1);
76
+
77
+        Assert.assertEquals(expected, actual);
78
+    }
79
+
80
+    @Test
81
+    public void onePairHandValueTest(){     // card1 == card2
82
+        //WHEN
83
+        int card1 = 10; //TEN  - 100000
84
+        int card2 = 10; //TEN  -      0
85
+        int card3 = 02; //TWO  -      2
86
+        //THEN
87
+        int expected = 100002;
88
+        int actual = stud.onePairHandValue(card1, card2, card3);
89
+
90
+        Assert.assertEquals(expected, actual);
91
+    }
92
+
93
+    @Test
94
+    public void onePairHandValueTest2() {     // card1 == card3
95
+        //WHEN
96
+        int card1 = 10; //TEN  - 100000
97
+        int card2 = 02; //TWO  -      2
98
+        int card3 = 10; //TEN  -      0
99
+        //THEN
100
+        int expected = 100002;
101
+        int actual = stud.onePairHandValue(card1, card2, card3);
102
+
103
+        Assert.assertEquals(expected, actual);
104
+    }
105
+
106
+    @Test
107
+    public void onePairHandValueTest3() {     // card2 == card3
108
+        //WHEN
109
+        int card1 = 02; //TWO  -      2
110
+        int card2 = 10; //TEN  - 100000
111
+        int card3 = 10; //TEN  -      0
112
+        //THEN
113
+        int expected = 100002;
114
+        int actual = stud.onePairHandValue(card1, card2, card3);
115
+
116
+        Assert.assertEquals(expected, actual);
117
+    }
118
+
119
+    @Test
120
+    public void threeOfAKindHandValueTest(){
121
+        //WHEN
122
+        int card1 = 3; //THREE  - 3000000
123
+        //THEN
124
+        int expected = 3000000;
125
+        int actual = stud.threeOfAKindHandValue(card1);
126
+
127
+        Assert.assertEquals(expected, actual);
12 128
     }
13 129
 
14 130
     @Test
15
-    public void thismethod(){
131
+    public void handValueTest(){
132
+        //WHEN
133
+            //SIX   - 600
134
+            //FIVE  -  50
135
+            //FOUR  -   4
16 136
 
137
+        //THEN
138
+        int expected = 654;
139
+        int actual = stud.handValue(cardPlayer1);
140
+
141
+        Assert.assertEquals(expected, actual);
142
+    }
143
+
144
+    @Test
145
+    public void handValueTest2(){
146
+        //WHEN
147
+        ArrayList<Card> cardsTest = new ArrayList<>();
148
+        Player player1 = new Player("Test", 10);
149
+        this.cardPlayer1 = new CardPlayer(player1);
150
+        Card cardSix = new Card(Card.CardValue.SIX, Card.Suit.HEARTS);
151
+        Card cardFive = new Card(Card.CardValue.SIX, Card.Suit.HEARTS);
152
+        Card cardFour = new Card(Card.CardValue.SIX, Card.Suit.HEARTS);
153
+        cardsTest.add(cardSix); cardsTest.add(cardFive); cardsTest.add(cardFour);
154
+        this.cardPlayer1.setHand(cardsTest);
155
+        //THEN
156
+        int expected = 6000000;
157
+        int actual = stud.handValue(this.cardPlayer1);
158
+
159
+        Assert.assertEquals(expected, actual);
160
+    }
161
+
162
+    @Test
163
+    public void handValueTest3(){
164
+        //WHEN
165
+        ArrayList<Card> cardsTest = new ArrayList<>();
166
+        Player player1 = new Player("Test", 10);
167
+        this.cardPlayer1 = new CardPlayer(player1);
168
+        Card cardSix = new Card(Card.CardValue.SIX, Card.Suit.HEARTS);
169
+        Card cardFive = new Card(Card.CardValue.SIX, Card.Suit.HEARTS);
170
+        Card cardFour = new Card(Card.CardValue.SEVEN, Card.Suit.HEARTS);
171
+        cardsTest.add(cardSix); cardsTest.add(cardFive); cardsTest.add(cardFour);
172
+        this.cardPlayer1.setHand(cardsTest);
173
+        //THEN
174
+        int expected = 60007;
175
+        int actual = stud.handValue(this.cardPlayer1);
176
+
177
+        Assert.assertEquals(expected, actual);
178
+    }
179
+
180
+    @Test
181
+    public void determineWinnerTEST(){
182
+
183
+
184
+        String expected = "Player2";
185
+        String actual = stud.determineWinner(players).getPlayer().getName();
186
+
187
+        Assert.assertEquals(expected, actual);
17 188
     }
18 189
 }
190
+/*
191
+    public CardPlayer determineWinner(ArrayList<CardPlayer> players){
192
+        int max = 0;
193
+        CardPlayer winner = null;
194
+
195
+        for(int i = 0; i < players.size(); i ++){
196
+            CardPlayer player = players.get(i);
197
+            int playerHandValue = handValue(player); // 'handValue' method sets 'max' value of this hand
198
+            if(playerHandValue > max){
199
+                max = playerHandValue;
200
+                winner = player;
201
+            }
202
+        }
203
+        System.out.println("The winner is " + winner.getPlayer().getName());
204
+        System.out.println(winner.getPlayer().getName() + "\'s hand was: " + winner.getHand().get(0).getName() +
205
+                " - " + winner.getHand().get(1).getName() + " - " + winner.getHand().get(2).getName() + "\n\n" );
206
+        return winner;
207
+    }
208
+
209
+        public CardPlayer determineWinner(){
210
+        int max = 0;
211
+        CardPlayer winner = null;
212
+
213
+        for(int i = 0; i < getPlayers().size(); i ++){
214
+            CardPlayer player = getPlayers().get(i);
215
+            int playerHandValue = handValue(player); // 'handValue' method sets 'max' value of this hand
216
+            if(playerHandValue > max){
217
+                max = playerHandValue;
218
+                winner = player;
219
+            }
220
+        }
221
+        System.out.println("The winner is " + winner.getPlayer().getName());
222
+        System.out.println(winner.getPlayer().getName() + "\'s hand was: " + winner.getHand().get(0).getName() +
223
+                " - " + winner.getHand().get(1).getName() + " - " + winner.getHand().get(2).getName() + "\n\n" );
224
+        return winner;
225
+    }
226
+ */