Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Rank {
- // IDのふり方(Corresponddence Trump Number)
- // A 2 3 4 5 6 7 8 9 10 J Q K
- // S 0 4 8 12 16 20 24 28 32 36 40 44 48
- // H 1 5 9 13 17 21 25 29 33 37 41 45 49
- // C 2 6 10 14 18 22 26 30 34 38 42 46 50
- // D 3 7 11 15 19 23 27 31 35 39 43 47 51
- public int getRank(int[] id) {
- for (int i = 0; i < 5; i++) {
- System.out.printf("%d枚目 %4d\n", i, id[i]);
- }
- //calculation hand cards
- int[] b = { id[0] % 4, id[1] % 4, id[2] % 4, id[3] % 4, id[4] % 4 };// mark
- int[] c = { id[0] / 4, id[1] / 4, id[2] / 4, id[3] / 4, id[4] / 4 };// num
- //array sort
- java.util.Arrays.sort(b);
- java.util.Arrays.sort(c);
- //init vavriables
- int straight = 0;
- int max_count = 0;
- int flash=0;
- int pair_count=0;
- int fullhouse = 0;
- for (int i = 0; i < 5; i++) {
- }
- if (c[0] == 0 && c[1] == 9 && c[2] == 10 && c[3] == 11 && c[4] == 12){
- return 1;// royal straight flush
- }
- //check flush
- for(int i=0; i<4; i++){
- for(int j=i;j<5; j++){
- if( i != j && b[i] == b[j] ){
- flash++;
- }
- }
- }
- //check straight
- for(int i=0; i<4; i++){
- if(c[i]==c[0]+i){
- straight++;
- }
- }
- //check sum pairs
- for(int i=0;i<5; i++){
- for(int j=i;j<5; j++){
- if(i != j && c[i] == c[j]){
- pair_count++;
- //check fullhouse hand 1-2
- if(pair_count == 4 ){
- if(c[0]==c[1]){
- if(c[2]==c[4]){
- fullhouse++;
- }
- }
- //check fullhouse hand 1~3
- if(c[0]==c[2]){
- if(c[3]==c[4]){
- fullhouse++;
- }
- }
- }
- }
- }
- }
- //result
- if (straight == 4 ){
- if( flash == 10) {
- return 2;//straight flash
- }
- }
- if (straight == 4) {
- return 6;//straight
- }
- if (fullhouse==1){
- return 4;//full house
- }
- if (pair_count == 4) {
- return 7;//three card
- }
- if (pair_count == 2) {
- return 8;//two card
- }
- if (pair_count == 1) {
- return 9;//one card
- }
- return 0;
- }
- }
Add Comment
Please, Sign In to add comment