Guest User

Rank

a guest
Mar 15th, 2020
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.67 KB | None | 0 0
  1. public class Rank {
  2. // IDのふり方(Corresponddence Trump Number)
  3. // A 2 3 4 5 6 7 8 9 10 J Q K
  4. // S 0 4 8 12 16 20 24 28 32 36 40 44 48
  5. // H 1 5 9 13 17 21 25 29 33 37 41 45 49
  6. // C 2 6 10 14 18 22 26 30 34 38 42 46 50
  7. // D 3 7 11 15 19 23 27 31 35 39 43 47 51
  8. public int getRank(int[] id) {
  9. for (int i = 0; i < 5; i++) {
  10. System.out.printf("%d枚目 %4d\n", i, id[i]);
  11. }
  12. //calculation hand cards
  13. int[] b = { id[0] % 4, id[1] % 4, id[2] % 4, id[3] % 4, id[4] % 4 };// mark
  14. int[] c = { id[0] / 4, id[1] / 4, id[2] / 4, id[3] / 4, id[4] / 4 };// num
  15. //array sort
  16. java.util.Arrays.sort(b);
  17. java.util.Arrays.sort(c);
  18. //init vavriables
  19. int straight = 0;
  20. int max_count = 0;
  21. int flash=0;
  22. int pair_count=0;
  23. int fullhouse = 0;
  24.  
  25. for (int i = 0; i < 5; i++) {
  26. }
  27. if (c[0] == 0 && c[1] == 9 && c[2] == 10 && c[3] == 11 && c[4] == 12){
  28. return 1;// royal straight flush
  29. }
  30. //check flush
  31. for(int i=0; i<4; i++){
  32. for(int j=i;j<5; j++){
  33. if( i != j && b[i] == b[j] ){
  34. flash++;
  35. }
  36. }
  37. }
  38. //check straight
  39. for(int i=0; i<4; i++){
  40. if(c[i]==c[0]+i){
  41. straight++;
  42. }
  43. }
  44. //check sum pairs
  45. for(int i=0;i<5; i++){
  46. for(int j=i;j<5; j++){
  47. if(i != j && c[i] == c[j]){
  48. pair_count++;
  49.  
  50. //check fullhouse hand 1-2
  51. if(pair_count == 4 ){
  52. if(c[0]==c[1]){
  53. if(c[2]==c[4]){
  54. fullhouse++;
  55. }
  56. }
  57. //check fullhouse hand 1~3
  58. if(c[0]==c[2]){
  59. if(c[3]==c[4]){
  60. fullhouse++;
  61. }
  62. }
  63. }
  64. }
  65. }
  66.  
  67. }
  68. //result
  69. if (straight == 4 ){
  70. if( flash == 10) {
  71. return 2;//straight flash
  72. }
  73. }
  74. if (straight == 4) {
  75. return 6;//straight
  76. }
  77. if (fullhouse==1){
  78. return 4;//full house
  79. }
  80. if (pair_count == 4) {
  81. return 7;//three card
  82. }
  83. if (pair_count == 2) {
  84. return 8;//two card
  85. }
  86. if (pair_count == 1) {
  87. return 9;//one card
  88. }
  89. return 0;
  90. }
  91. }
Add Comment
Please, Sign In to add comment