From 5321f8a025a4e31a48b27a2b96abbe99959512e8 Mon Sep 17 00:00:00 2001 From: Yannine Alvarez Date: Thu, 16 Apr 2020 21:22:46 -0400 Subject: [PATCH] Repositorio de ejercicio de Poker 01 en kotlin --- Poker/.idea/codeStyles/Project.xml | 10 ++++++++++ Poker/.idea/codeStyles/codeStyleConfig.xml | 5 +++++ Poker/.idea/kotlinc.xml | 6 ++++++ Poker/.idea/libraries/KotlinJavaRuntime.xml | 19 +++++++++++++++++++ Poker/.idea/misc.xml | 6 ++++++ Poker/.idea/modules.xml | 8 ++++++++ Poker/.idea/workspace.xml | 119 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Poker/Poker.iml | 12 ++++++++++++ Poker/out/production/Poker/Card.class | Bin 0 -> 793 bytes Poker/out/production/Poker/Carta.class | Bin 0 -> 1056 bytes Poker/out/production/Poker/META-INF/Poker.kotlin_module | Bin 0 -> 29 bytes Poker/out/production/Poker/Poker.class | Bin 0 -> 2136 bytes Poker/out/production/Poker/PokerKt$isStraight$$inlined$sortedBy$1.class | Bin 0 -> 1813 bytes Poker/out/production/Poker/PokerKt.class | Bin 0 -> 7848 bytes Poker/src/Poker.kt | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ PokerYannine.md | 30 ++++++++++++++++++++++++++++++ 16 files changed, 285 insertions(+) create mode 100644 Poker/.idea/codeStyles/Project.xml create mode 100644 Poker/.idea/codeStyles/codeStyleConfig.xml create mode 100644 Poker/.idea/kotlinc.xml create mode 100644 Poker/.idea/libraries/KotlinJavaRuntime.xml create mode 100644 Poker/.idea/misc.xml create mode 100644 Poker/.idea/modules.xml create mode 100644 Poker/.idea/workspace.xml create mode 100644 Poker/Poker.iml create mode 100644 Poker/out/production/Poker/Card.class create mode 100644 Poker/out/production/Poker/Carta.class create mode 100644 Poker/out/production/Poker/META-INF/Poker.kotlin_module create mode 100644 Poker/out/production/Poker/Poker.class create mode 100644 Poker/out/production/Poker/PokerKt$isStraight$$inlined$sortedBy$1.class create mode 100644 Poker/out/production/Poker/PokerKt.class create mode 100644 Poker/src/Poker.kt create mode 100644 PokerYannine.md diff --git a/Poker/.idea/codeStyles/Project.xml b/Poker/.idea/codeStyles/Project.xml new file mode 100644 index 0000000..1bec35e --- /dev/null +++ b/Poker/.idea/codeStyles/Project.xml @@ -0,0 +1,10 @@ + + + + + + + + \ No newline at end of file diff --git a/Poker/.idea/codeStyles/codeStyleConfig.xml b/Poker/.idea/codeStyles/codeStyleConfig.xml new file mode 100644 index 0000000..79ee123 --- /dev/null +++ b/Poker/.idea/codeStyles/codeStyleConfig.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/Poker/.idea/kotlinc.xml b/Poker/.idea/kotlinc.xml new file mode 100644 index 0000000..0dd4b35 --- /dev/null +++ b/Poker/.idea/kotlinc.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/Poker/.idea/libraries/KotlinJavaRuntime.xml b/Poker/.idea/libraries/KotlinJavaRuntime.xml new file mode 100644 index 0000000..1a7265d --- /dev/null +++ b/Poker/.idea/libraries/KotlinJavaRuntime.xml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Poker/.idea/misc.xml b/Poker/.idea/misc.xml new file mode 100644 index 0000000..133ceed --- /dev/null +++ b/Poker/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Poker/.idea/modules.xml b/Poker/.idea/modules.xml new file mode 100644 index 0000000..de24c65 --- /dev/null +++ b/Poker/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/Poker/.idea/workspace.xml b/Poker/.idea/workspace.xml new file mode 100644 index 0000000..8edd815 --- /dev/null +++ b/Poker/.idea/workspace.xml @@ -0,0 +1,119 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1586789556814 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Poker/Poker.iml b/Poker/Poker.iml new file mode 100644 index 0000000..245d342 --- /dev/null +++ b/Poker/Poker.iml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/Poker/out/production/Poker/Card.class b/Poker/out/production/Poker/Card.class new file mode 100644 index 0000000..0da506d Binary files /dev/null and b/Poker/out/production/Poker/Card.class differ diff --git a/Poker/out/production/Poker/Carta.class b/Poker/out/production/Poker/Carta.class new file mode 100644 index 0000000..58f6085 Binary files /dev/null and b/Poker/out/production/Poker/Carta.class differ diff --git a/Poker/out/production/Poker/META-INF/Poker.kotlin_module b/Poker/out/production/Poker/META-INF/Poker.kotlin_module new file mode 100644 index 0000000..539866a Binary files /dev/null and b/Poker/out/production/Poker/META-INF/Poker.kotlin_module differ diff --git a/Poker/out/production/Poker/Poker.class b/Poker/out/production/Poker/Poker.class new file mode 100644 index 0000000..603f000 Binary files /dev/null and b/Poker/out/production/Poker/Poker.class 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 new file mode 100644 index 0000000..c03f771 Binary files /dev/null and b/Poker/out/production/Poker/PokerKt$isStraight$$inlined$sortedBy$1.class differ diff --git a/Poker/out/production/Poker/PokerKt.class b/Poker/out/production/Poker/PokerKt.class new file mode 100644 index 0000000..54991eb Binary files /dev/null and b/Poker/out/production/Poker/PokerKt.class differ diff --git a/Poker/src/Poker.kt b/Poker/src/Poker.kt new file mode 100644 index 0000000..063a06f --- /dev/null +++ b/Poker/src/Poker.kt @@ -0,0 +1,70 @@ +/*REPOSITORIO GITLAB: https://phoebe.roshka.com/gitlab/yalvarez/kotlin-e004-poker*/ + +class Carta(val valor: Int, val palo: Char) + +/*Probar para validar*/ +const val CARAS = "23456789tjqka" +const val LETRAS = "shdc" + +/* corregir esta funcion y agregar la funcion para obtener poker , full*/ +fun isStraight(cards: List): Boolean { + val sorted = cards.sortedBy { it.valor } + if (sorted[0].valor + 4 == sorted[4].valor) return true + if (sorted[4].valor == 14 && sorted[0].valor == 2 && sorted[3].valor == 5) return true + return false +} +/* probar funciones*/ +fun esColor(cartas: List): Boolean { + val suit = cartas[0].palo + if (cartas.drop(1).all { it.palo == suit }) return true + return false +} + +fun jugada(mano: String): String { + val h = mano.toLowerCase() + val split = h.split(' ').filterNot { it == "" }.distinct() + if (split.size != 5) return "invalid" + val cartas = mutableListOf() + + for (s in split) { + if (s.length != 2) return "invalid" + val fIndex = CARAS.indexOf(s[0]) + if (fIndex == -1) return "invalid" + val sIndex = LETRAS.indexOf(s[1]) + if (sIndex == -1) return "invalid" + cartas.add(Carta(fIndex + 2, s[1])) + } + + val groups = cartas.groupBy { it.valor } + when (groups.size) { + 2 -> { + if (groups.any { it.value.size == 4 }) return " 4 tipos de cartas" + return "full-house" + } + 3 -> { + if (groups.any { it.value.size == 3 }) return "3 tipos de cartas" + return "DOS PARES" + } + 4 -> return "UN PAR" + else -> { + val color = esColor(cartas) + val straight = isStraight(cartas) //corregir + when { + color && straight -> return "straight-flush" //corregir + color -> return "color" + straight -> return "straight" //corregir + else -> return "Carta Alta" + } + } + } +} + +fun main(args: Array) { + val manos = arrayOf( + "2h 2d 2c kc qd", + "ah ah 7c 6c 4c" + ) + for (mano in manos) { + println("Jugada: ${jugada(mano)}") + } +} \ No newline at end of file diff --git a/PokerYannine.md b/PokerYannine.md new file mode 100644 index 0000000..a66c64f --- /dev/null +++ b/PokerYannine.md @@ -0,0 +1,30 @@ + **2. Responder a las siguientes preguntas** + +2.1. Si se mezclan y reparten cartas al azar: Cuál es la probabilidad de obtener una escalera de color? + Para obtener la probabilidad de obtener una escalera a color se toma la combinación de las 52 cartas totales con las 5 cartas que se reparten, usando la formula de combinación en matemáticas se hace comb(52,5) --> (52,5)=5!/(52-5)!5! = 2598960 los casos posibles, y para obtener la probabilidad se hace en base al siguiente P=(40/2598960)*100, **P=0.0015%** de que salga escalera de color. + +2.2. Si se mezclan y reparten cartas al azar: Cuál es la probabilidad de obtener un poker? + Para obtener la probabilidad de obtener el poker se realiza nuevamente la combinación de las 52 cartas con las 5 cartas que se reparten, la probabilidad se hace de acuerdo a los casos favorables que es de 624, P=(624/2598960)*100, **P=0.0240%** de que salga poker + + +2.3. Si se mezclan y reparten cartas al azar: Cuál es la probabilidad de obtener un full house? + Para obtener la probabilidad de obtener el poker se realiza nuevamente la combinación de las 52 cartas con las 5 cartas que se reparten, la probabilidad se hace de acuerdo a los casos favorables que es de 1872, P=(1872/2598960)*100, **P=0.0720%** de que salga full house. + + +2.4. Si se mezclan y reparten cartas al azar: Cuál es la probabilidad de obtener una escalera? + Para obtener la probabilidad de obtener el poker se realiza nuevamente la combinación de las 52 cartas con las 5 cartas que se reparten, la probabilidad se hace de acuerdo a los casos favorables que es de 10200, P=(10200/2598960)*100, **P=0.3925%** de que salga escalera. + + +2.5. Si se mezclan y reparten cartas al azar: Cuál es la probabilidad de obtener un trio? + Para obtener la probabilidad de obtener el poker se realiza nuevamente la combinación de las 52 cartas con las 5 cartas que se reparten, la probabilidad se hace de acuerdo a los casos favorables que es de 56784, P=(56784/2598960)*100, **P=2.1849%** de que salga trío. + +2.6. Si se mezclan y reparten cartas al azar: Cuál es la probabilidad de obtener un par doble? + Para obtener la probabilidad de obtener el poker se realiza nuevamente la combinación de las 52 cartas con las 5 cartas que se reparten, la probabilidad se hace de acuerdo a los casos favorables que es de 123552, P=(123552/2598960)*100, **P=4.75%** de que salga par doble. + + +2.7. Si se mezclan y reparten cartas al azar: Cuál es la probabilidad de obtener un par? + Para obtener la probabilidad de obtener el poker se realiza nuevamente la combinación de las 52 cartas con las 5 cartas que se reparten, la probabilidad se hace de acuerdo a los casos favorables que es de 1098240, P=(1098240/2598960)*100, **P=42.26%** de que salga par. + + +2.8. Si se mezclan y reparten cartas al azar: Cuál es la probabilidad de no obtener ninguna de las jugadas anteriores? + Para obtener la probabilidad de obtener el poker se realiza nuevamente la combinación de las 52 cartas con las 5 cartas que se reparten, la probabilidad se hace de acuerdo a los casos favorables que es de 1302540, P=(1302540/2598960)*100, **P=50.12%** de no obtener ninguna de las jugadas anteriores. \ No newline at end of file -- libgit2 0.26.0