diff --git a/Poker/.idea/workspace.xml b/Poker/.idea/workspace.xml
index 4314323..3acd2cc 100644
--- a/Poker/.idea/workspace.xml
+++ b/Poker/.idea/workspace.xml
@@ -2,8 +2,12 @@
-
+
+
+
+
+
@@ -81,49 +85,65 @@
1586789556814
+
+ 1587329427974
+
+
+
+ 1587329427974
+
+
+
+
+
+
-
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
+
+
+
+
+
@@ -133,4 +153,25 @@
+
+
+
+
+ file://$PROJECT_DIR$/src/Poker.kt
+ 16
+
+
+
+ file://$PROJECT_DIR$/src/Poker.kt
+ 35
+
+
+
+ file://$PROJECT_DIR$/src/Poker.kt
+ 65
+
+
+
+
+
\ No newline at end of file
diff --git a/Poker/out/production/Poker/Card.class b/Poker/out/production/Poker/Card.class
deleted file mode 100644
index 0da506d..0000000
Binary files a/Poker/out/production/Poker/Card.class and /dev/null differ
diff --git a/Poker/out/production/Poker/Carta.class b/Poker/out/production/Poker/Carta.class
index 58f6085..bb097b7 100644
Binary files a/Poker/out/production/Poker/Carta.class and b/Poker/out/production/Poker/Carta.class differ
diff --git a/Poker/out/production/Poker/Poker.class b/Poker/out/production/Poker/Poker.class
deleted file mode 100644
index 603f000..0000000
Binary files a/Poker/out/production/Poker/Poker.class and /dev/null differ
diff --git a/Poker/out/production/Poker/PokerKt$isStraight$$inlined$sortedBy$1.class b/Poker/out/production/Poker/PokerKt$isStraight$$inlined$sortedBy$1.class
deleted file mode 100644
index c03f771..0000000
Binary files a/Poker/out/production/Poker/PokerKt$isStraight$$inlined$sortedBy$1.class and /dev/null differ
diff --git a/Poker/out/production/Poker/PokerKt.class b/Poker/out/production/Poker/PokerKt.class
index 54991eb..3917e37 100644
Binary files a/Poker/out/production/Poker/PokerKt.class and b/Poker/out/production/Poker/PokerKt.class differ
diff --git a/Poker/src/Poker.kt b/Poker/src/Poker.kt
index 11d2263..a54ffed 100644
--- a/Poker/src/Poker.kt
+++ b/Poker/src/Poker.kt
@@ -1,109 +1,67 @@
/*REPOSITORIO GITLAB: https://phoebe.roshka.com/gitlab/yalvarez/kotlin-e004-poker*/
+class Carta(val valor: Int, val palo: Char)
+const val CARAS = "23456789tjqka"
+const val LETRAS = "shdc"
-fun jugada(resultado: String): String{
- var cartas = arrayOf(0,0,0,0)
- var numerojugado = arrayOf(0,0,0,0,0,0,0,0,0,0,0,0,0)
- var resultado: String = "NADA"
+fun esEscalera(cards: List): Boolean {
+ val ordenar = cards.sortedBy { it.valor }
+ if (ordenar[0].valor + 4 == ordenar[4].valor) return true
+ if (ordenar[4].valor == 14 && ordenar[0].valor == 2 && ordenar[3].valor == 5) return true
+ return false
+}
- for (paloss in resultado){
+fun esColor(cartas: List): Boolean {
+ val palo = cartas[0].palo
+ if (cartas.drop(1).all { it.palo == palo }) return true
+ return false
+}
- if(paloss == 'S'){
- cartas[1]
- }
- if(paloss == 'D'){
- cartas[2]
- }
- if(paloss == 'D'){
- cartas[3]
- }
- if(paloss == 'S'){
- cartas[4]
- }
+fun jugada(mano: String): String {
+ val letraMinuscula = mano.toLowerCase() //RECONOCE LA LETRA MINUSCULA QUE INGRESE
+ val dividir = letraMinuscula.split(' ').filterNot { it == "" }.distinct()
+ if (dividir.size != 5) return "INVALIDO"
+ val cartas = mutableListOf()
+ for (s in dividir) {
+ if (s.length != 2) return "INVALIDO"
+ val fIndex = CARAS.indexOf(s[0])
+ if (fIndex == -1) return "INVALIDO"
+ val sIndex = LETRAS.indexOf(s[1])
+ if (sIndex == -1) return "INVALIDO"
+ cartas.add(Carta(fIndex + 2, s[1]))
}
- for (valor in resultado){
- if(valor == 'A'){
- numerojugado[1]
- }
- if(valor == '2'){
- numerojugado[2]
- }
- if(valor == '3'){
- numerojugado[3]
- }
- if(valor == '4'){
- numerojugado[4]
- }
- if(valor == '5'){
- numerojugado[5]
- }
- if(valor == '6'){
- numerojugado[6]
- }
- if(valor == '7'){
- numerojugado[7]
- }
- if(valor == '8'){
- numerojugado[8]
- }
- if(valor == '9'){
- numerojugado[9]
- }
- if(valor == 'T'){
- numerojugado[10]
- }
- if(valor == 'J'){
- numerojugado[11]
- }
- if(valor == 'Q'){
- numerojugado[12]
- }
- if(valor == 'K'){
- numerojugado[13]
- }
- }
+ val groups = cartas.groupBy { it.valor }
+ when (groups.size) {
+ 2 -> {
- for (carta in cartas){
- if (carta == 5){
- resultado = "COLOR"
- for (position in numerojugado.indices){
- resultado = if (position < 9){
- if (1 == numerojugado[position] && 1 == numerojugado[position+1] && 1 == numerojugado[position+2] && 1 == numerojugado[position+3] && 1 == numerojugado[position+4]) "ESCALERA COLOR" else continue
- }else if (position == 9){
- if (1 == numerojugado[position] && 1 == numerojugado[position+1] && 1 == numerojugado[position+2] && 1 == numerojugado[position+3] && 1 == numerojugado[0]) "ESCALERA COLOR REAL" else break
- }else break
- }
+ return "FULL"
}
- }
-
- var trio = false
- var doble = 0
+ 3 -> {
- for (position in numerojugado.indices) {
- if (numerojugado[position] == 5){
- resultado = "POKER"
- break
- } else {
- if (numerojugado[position] == 4) trio = true
- if (numerojugado[position] == 3) doble++
- resultado = if ((doble == 2) && trio) "FULL"
- else if ((doble == 1) && trio) "TRIO"
- else if (doble == 1) "PAREJA"
- else if (doble == 2) "PAREJA DOBLE"
- else "ESCALERA COLOR"
+ return "DOS PARES"
+ }
+ 4 -> return "UN PAR"
+ else -> {
+ val color = esColor(cartas)
+ val escalera = esEscalera(cartas) //corregir
+ when {
+ color && escalera -> return "ESCALERA COLOR" //corregir
+ color -> return "COLOR"
+ escalera -> return "ESCALERA" //corregir
+ else -> return "CARTA ALTA"
+ }
}
}
-
- return resultado
}
+
fun main(args: Array) {
val manos = arrayOf(
- "2h 2d 2c kc qd",
- "ah ah 7c 6c 4c"
+ "ah ad th tc 6s",
+ "as 2s 3s 4s 5s"
)
for (mano in manos) {
println("Jugada: ${jugada(mano)}")