generated from vacoote89/java-poker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPoker.java
135 lines (110 loc) · 3.08 KB
/
Poker.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
import java.util.Scanner;
import java.util.Arrays;
public class Poker {
private int rank1, rank2, rank3, rank4, rank5;
private char suit1, suit2, suit3, suit4, suit5;
private int [][] cards = new int [4][13];
private int [] temp = new int [5];
public Poker (int rank1, int rank2, int rank3, int rank4, int rank5, char suit1, char suit2, char suit3, char suit4, char suit5) {
this.rank1 = rank1;
this.rank2 = rank2;
this.rank3 = rank3;
this.rank4 = rank4;
this.rank5 = rank5;
this.suit1 = suit1;
this.suit2 = suit2;
this.suit3 = suit3;
this.suit4 = suit4;
this.suit5 = suit5;
}
public int suitToInt (char suit) {
int x = 4;
if (suit == 'D' || suit == 'd') {
x = 0;
}
if (suit == 'H' || suit == 'h') {
x = 1;
}
if (suit == 'C' || suit == 'c') {
x = 2;
}
if (suit == 'S' || suit == 's') {
x = 3;
}
return x;
}
public void initializeArray () {
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 13; j++) {
cards[i][j] = 0;
}
}
}
public void initializeTempArray () {
for (int i = 0; i < 5; i++) {
temp[i] = 0;
}
}
public void fillArray () {
cards [suitToInt(suit1)][rank1-1] = 1;
cards [suitToInt(suit2)][rank2-1] = 1;
cards [suitToInt(suit3)][rank3-1] = 1;
cards [suitToInt(suit4)][rank4-1] = 1;
cards [suitToInt(suit5)][rank5-1] = 1;
}
public boolean checkFlush () {
boolean flag = false;
if (suit1 == suit2 && suit2 == suit3 && suit3 == suit4) {
flag = true;
}
return flag;
}
public boolean checkStraight () {
int count = 0;
int count2 = 0;
boolean flag = false;
//initializeTempArray(temp);
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 13; j++) {
if (cards[i][j] == 1) {
temp[count] = (j+1);
count++;
}
}
}
Arrays.sort(temp);
for (int k = 0; k < 4; k++) {
if (temp[k+1] == temp[k]+1) {
count2++;
}
}
if (count2 == 4) {
flag = true;
}
return flag;
}
public boolean checkFourOfAKind () {
int count = 0;
int count2 = 0;
boolean flag = false;
//initializeTempArray(temp);
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 13; j++) {
if (cards[i][j] == 1) {
temp[count] = (j+1);
count++;
}
}
}
Arrays.sort(temp);
for (int k = 0; k < 4; k++) {
if (temp[k] == temp[k+1]) {
count2++;
}
}
if (count2 == 3) {
flag = true;
}
return flag;
}
}