Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static class Hand implements Comparable{
- Card[] c;
- byte hand, handCompA, handCompB;
- Hand(String a,String b,String c,String d,String e){
- this.c=new Card[5];
- this.c[0]=new Card(a);
- this.c[1]=new Card(b);
- this.c[2]=new Card(c);
- this.c[3]=new Card(d);
- this.c[4]=new Card(e);
- java.util.Arrays.sort(this.c);
- if((this.c[1].s==this.c[0].s)&&(this.c[2].s==this.c[0].s)&&(this.c[3].s==this.c[0].s)&&(this.c[4].s==this.c[0].s)){
- if((this.c[1].v==this.c[0].v-1)&&(this.c[2].v==this.c[0].v-2)&&(this.c[3].v==this.c[0].v-3)&&(this.c[4].v==this.c[0].v-4)){
- handCompA=this.c[4].v;
- hand=(byte)((handCompA==10)?10:9);
- }else if((this.c[0].v==14)&&(this.c[1].v==5)&&(this.c[2].v==4)&&(this.c[3].v==3)&&(this.c[4].v==2)){
- hand=9;
- handCompA=1;
- }
- }else if(((this.c[1].v==this.c[0].v)&&(this.c[2].v==this.c[0].v)&&(this.c[3].v==this.c[0].v))||((this.c[2].v==this.c[1].v)&&(this.c[3].v==this.c[1].v)&&(this.c[4].v==this.c[1].v))){
- hand=8;
- handCompA=this.c[1].v;
- }else if((this.c[1].v==this.c[0].v)&&(this.c[2].v==this.c[0].v)&&(this.c[3].v==this.c[4].v)){
- hand=7;
- handCompA=this.c[0].v;
- handCompB=this.c[3].v;
- }else if((this.c[3].v==this.c[2].v)&&(this.c[4].v==this.c[2].v)&&(this.c[0].v==this.c[1].v)){
- hand=7;
- handCompB=this.c[0].v;
- handCompA=this.c[2].v;
- }else if((this.c[1].s==this.c[0].s)&&(this.c[2].s==this.c[0].s)&&(this.c[3].s==this.c[0].s)&&(this.c[4].s==this.c[0].s)){
- hand=6;
- handCompA=0;
- }else if((this.c[1].v==this.c[0].v-1)&&(this.c[2].v==this.c[0].v-2)&&(this.c[3].v==this.c[0].v-3)&&(this.c[4].v==this.c[0].v-4)){
- hand=5;
- handCompA=this.c[4].v;
- }else if((this.c[0].v==14)&&(this.c[1].v==5)&&(this.c[2].v==4)&&(this.c[3].v==3)&&(this.c[4].v==2)){
- hand=9;
- handCompA=1;
- }else if(((this.c[0].v==this.c[2].v)&&(this.c[1].v==this.c[2].v))||((this.c[1].v==this.c[2].v)&&(this.c[3].v==this.c[2].v))||((this.c[3].v==this.c[2].v)&&(this.c[4].v==this.c[2].v))){
- hand=4;
- handCompA=this.c[2].v;
- }else if((this.c[0].v==this.c[1].v&&((this.c[2].v==this.c[3].v)||(this.c[3].v==this.c[4].v)))||((this.c[1].v==this.c[2].v)&&(this.c[3].v==this.c[4].v))){
- hand=3;
- handCompA=this.c[1].v;
- handCompB=this.c[3].v;
- if(handCompA<handCompB){
- byte temp=handCompA;
- handCompA=handCompB;
- handCompB=temp;
- }
- }else if((this.c[0].v==this.c[1].v)||(this.c[2].v==this.c[1].v)){
- hand=1;
- handCompA=this.c[1].v;
- }else if((this.c[4].v==this.c[3].v)||(this.c[2].v==this.c[3].v)){
- hand=1;
- handCompA=this.c[3].v;
- }else{
- hand=1;
- handCompA=0;
- }
- }
- public int compareTo(Object o){
- Hand h=(Hand)o;
- if(hand>h.hand){
- return 1;
- }else if(hand<h.hand){
- return -1;
- }else{
- int comp=0;
- if(handCompA<h.handCompA){
- comp=-1;
- }else if(handCompA>h.handCompA){
- comp=1;
- }
- if((comp==0)&&((hand==3)||(hand==7))){
- if(handCompB<h.handCompB){
- comp=-1;
- }else if(handCompB>h.handCompB){
- comp=1;
- }
- }
- if(comp!=0){
- return comp;
- }else{
- for(int i=0;i<5;i++){
- if(c[i].v>h.c[i].v){
- return 1;
- }else if(c[i].v<h.c[i].v){
- return -1;
- }
- }
- return 0;
- }
- }
- }
- private static class Card implements Comparable{
- byte v, s;
- Card(String s){
- char vc=s.charAt(0);
- v=(byte)(vc>='2'&&vc<='9'?s.charAt(0)-'0':vc=='T'?10:vc=='J'?11:vc=='Q'?12:vc=='K'?13:14);
- this.s=(byte)(s.charAt(1)=='D'?0:s.charAt(1)=='H'?1:s.charAt(1)=='S'?2:3);
- }
- public int compareTo(Object o){
- Card c=(Card)o;
- if(v<c.v){
- return 1;
- }else if(v==c.v){
- return 0;
- }else{
- return -1;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement