From fb86f6e310ecc5769ced9a1b7ecf6045463365a8 Mon Sep 17 00:00:00 2001 From: willgonzz Date: Wed, 27 Oct 2021 07:48:42 -0300 Subject: [PATCH] Initial commit --- MainWilliam.java | 32 ++++++++++++++++++++++++++++++++ PokerWilliam.java | 176 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ probabilidades.docx | Bin 0 -> 15475 bytes 3 files changed, 208 insertions(+) create mode 100644 MainWilliam.java create mode 100644 PokerWilliam.java create mode 100644 probabilidades.docx diff --git a/MainWilliam.java b/MainWilliam.java new file mode 100644 index 0000000..f65b484 --- /dev/null +++ b/MainWilliam.java @@ -0,0 +1,32 @@ +public class MainWilliam{ + public static void main(String[] args) { + Poker p=new Poker(); + String c[]={"2S","3S","4S","5S","6S"}; + p.setCartas(c); + p.recorrer(); + String d[]={"2S","2C","2D","2H","6S"}; + p.setCartas(d); + p.recorrer(); + String full[]={"2S","3S","2C","3D","3H"}; + p.setCartas(full); + p.recorrer(); + String color[]={"2S","3S","4S","5S","8S"}; + p.setCartas(color); + p.recorrer(); + String escalera[]={"3H","4D","5C","6S","7S"}; + p.setCartas(escalera); + p.recorrer(); + String trio[]={"3S","2C","3D","3H","4S"}; + p.setCartas(trio); + p.recorrer(); + String doblePar[]={"3D","3H","4S","4D","7H"}; + p.setCartas(doblePar); + p.recorrer(); + String doble[]={"3D","3H","4S","2D","5S"}; + p.setCartas(doble); + p.recorrer(); + String cartaAlta[]={"4S","9D","2S","3H","5C"}; + p.setCartas(cartaAlta); + p.recorrer(); + } +} \ No newline at end of file diff --git a/PokerWilliam.java b/PokerWilliam.java new file mode 100644 index 0000000..48cc3dd --- /dev/null +++ b/PokerWilliam.java @@ -0,0 +1,176 @@ +public class PokerWilliam{ + private String cartas[]; + + public Poker() { + this.cartas=new String[5]; + } + + public String[] getCartas() { + return this.cartas; + } + + public void setCartas(String[] cartas) { + this.cartas = cartas; + } + + public static int convertir(char a){ + if(a!='A'||a!='T'||a!='J'||a!='Q'||a!='K'){ + return Character.getNumericValue(a); + }else if(a=='A'){ + return 1; + }else if(a=='T'){ + return 10; + }else if(a=='J'){ + return 11; + }else if(a=='Q'){ + return 12; + }else if(a=='K'){ + return 13; + }else{ + return 0; + } + } + + public static void ordenarInt(int a[]){ + int aux; + for(int i=0; i<4;i++){ + for(int j=i+1;j<5;j++){ + if(a[i]>a[j]){ + aux=a[i]; + a[i]=a[j]; + a[j]=aux; + } + } + } + } + public static int iguales(int a[]){ + ordenarInt(a); + int c=1; + int auxdoble=0; + int auxtriple=0; + for(int i=0;i<4;i++){ + if(a[i]==a[i+1]){ + c++; + if(c==2){ + auxdoble++; + }else if(c==3){ + auxdoble--; + auxtriple++; + }else if(c==4){ + return 4; + } + }else if(i!=4){ + c=1; + } + } + if(auxtriple==1 && auxdoble==1){ + return 3; + }else if(auxtriple==1){ + return 2; + }else if(auxdoble==2){ + return 1; + }else if(auxdoble==1){ + return 0; + }else{ + return -1; + } + } + public static void ordenarString(char a[]){ + char aux; + for(int i=0; i<4;i++){ + for(int j=i+1;j<5;j++){ + if(a[i]>a[j]){ + aux=a[i]; + a[i]=a[j]; + a[j]=aux; + } + } + } + } + + public static int verificaPalo(char palo[]){ + ordenarString(palo); + int c=1; + for(int i=0;i<4;i++){ + if(palo[i]==palo[i+1]){ + c++; + } + } + if(c==5){ + return 2; + }else if(c==4){ + return 1; + }else{ + return 0; + } + } + public static int verificasucesion(int a[]){ + ordenarInt(a); + int c=1; + if(a[0]==1){ + for(int i=0;i<4;i++){ + if(a[i]==(a[i+1]+1)){ + c++; + }else{ + break; + } + } + if(c==5){ + return c; + } + c=1; + for(int i=1; i<5;i++){ + a[i-1]=a[i]; + } + a[4]=14; + + for(int i=0;i<4;i++){ + if(a[i]==(a[i+1]+1)){ + c++; + }else{ + break; + } + } + }else{ + for(int i=0;i<4;i++){ + if(a[i]+1==(a[i+1])){ + c++; + }else{ + break; + } + } + } + return c; + } + public void recorrer(){ + int j=0; + char tipo[]=new char[5]; + int i[]=new int[5]; + for(String carta: this.cartas){ + i[j]=convertir(carta.charAt(0)); + tipo[j]=carta.charAt(1); + System.out.print(carta+"|"); + j++; + } + if(verificaPalo(tipo)==2 && verificasucesion(i)==5){ + System.out.println("\nUsted tiene una Escalera Color"); + }else if(iguales(i)==4){ + System.out.println("\nUsted tiene una Poker"); + }else if(iguales(i)==3){ + System.out.println("\nUsted tiene Full"); + }else if(verificaPalo(tipo)==2){ + System.out.println("\nUsted tiene color"); + }else if(verificasucesion(i)==5){ + System.out.println("\nUsted tiene escalera"); + }else if(iguales(i)==2){ + System.out.println("\nUsted tiene trio"); + }else if(iguales(i)==1){ + System.out.println("\nUsted tiene par doble"); + }else if(iguales(i)==0){ + System.out.println("\nUsted tiene par"); + }else{ + System.out.println("\nUsted tiene carta Alta"); + } + } + +} \ No newline at end of file diff --git a/probabilidades.docx b/probabilidades.docx new file mode 100644 index 0000000..d5c3202 Binary files /dev/null and b/probabilidades.docx differ -- libgit2 0.26.0