Commit 2afdb75a by Yannine Alvarez

corrección de valor de retorno.

parent 7380864d
......@@ -2,8 +2,12 @@
<project version="4">
<component name="ChangeListManager">
<list default="true" id="628f93ca-b7ce-4a63-90a4-4fc67deaa2b5" name="Default Changelist" comment="Unificar en una función para retornar valores en el poker">
<change afterPath="$PROJECT_DIR$/.idea/vcs.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/Poker/Card.class" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/Poker/Carta.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/Poker/Carta.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/Poker/Poker.class" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/Poker/PokerKt$isStraight$$inlined$sortedBy$1.class" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/Poker/PokerKt.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/Poker/PokerKt.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/Poker.kt" beforeDir="false" afterPath="$PROJECT_DIR$/src/Poker.kt" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
......@@ -81,49 +85,65 @@
<option name="presentableId" value="Default" />
<updated>1586789556814</updated>
</task>
<task id="LOCAL-00001" summary="Unificar en una función para retornar valores en el poker">
<created>1587329427974</created>
<option name="number" value="00001" />
<option name="presentableId" value="LOCAL-00001" />
<option name="project" value="LOCAL" />
<updated>1587329427974</updated>
</task>
<option name="localTasksCounter" value="2" />
<servers />
</component>
<component name="VcsManagerConfiguration">
<MESSAGE value="Unificar en una función para retornar valores en el poker" />
<option name="LAST_COMMIT_MESSAGE" value="Unificar en una función para retornar valores en el poker" />
</component>
<component name="WindowStateProjectService">
<state x="413" y="109" key="#com.intellij.refactoring.typeMigration.ui.FailedConversionsDialog" timestamp="1586915044775">
<screen x="0" y="0" width="1366" height="728" />
</state>
<state x="413" y="109" key="#com.intellij.refactoring.typeMigration.ui.FailedConversionsDialog/0.0.1366.728@0.0.1366.728" timestamp="1586915044775" />
<state x="313" y="0" key="CommitChangelistDialog2" timestamp="1587329027195">
<state x="313" y="0" key="CommitChangelistDialog2" timestamp="1587333206624">
<screen x="0" y="0" width="1366" height="728" />
</state>
<state x="313" y="0" key="CommitChangelistDialog2/0.0.1366.728@0.0.1366.728" timestamp="1587329027195" />
<state width="1322" height="174" key="GridCell.Tab.0.bottom" timestamp="1587328942458">
<state x="313" y="0" key="CommitChangelistDialog2/0.0.1366.728@0.0.1366.728" timestamp="1587333206624" />
<state width="1322" height="174" key="GridCell.Tab.0.bottom" timestamp="1587333192829">
<screen x="0" y="0" width="1366" height="728" />
</state>
<state width="1322" height="174" key="GridCell.Tab.0.bottom/0.0.1366.728@0.0.1366.728" timestamp="1587328942458" />
<state width="1322" height="174" key="GridCell.Tab.0.center" timestamp="1587328942458">
<state width="1322" height="174" key="GridCell.Tab.0.bottom/0.0.1366.728@0.0.1366.728" timestamp="1587333192829" />
<state width="1322" height="174" key="GridCell.Tab.0.center" timestamp="1587333192828">
<screen x="0" y="0" width="1366" height="728" />
</state>
<state width="1322" height="174" key="GridCell.Tab.0.center/0.0.1366.728@0.0.1366.728" timestamp="1587328942458" />
<state width="1322" height="174" key="GridCell.Tab.0.left" timestamp="1587328942458">
<state width="1322" height="174" key="GridCell.Tab.0.center/0.0.1366.728@0.0.1366.728" timestamp="1587333192828" />
<state width="1322" height="174" key="GridCell.Tab.0.left" timestamp="1587333192828">
<screen x="0" y="0" width="1366" height="728" />
</state>
<state width="1322" height="174" key="GridCell.Tab.0.left/0.0.1366.728@0.0.1366.728" timestamp="1587328942458" />
<state width="1322" height="174" key="GridCell.Tab.0.right" timestamp="1587328942458">
<state width="1322" height="174" key="GridCell.Tab.0.left/0.0.1366.728@0.0.1366.728" timestamp="1587333192828" />
<state width="1322" height="174" key="GridCell.Tab.0.right" timestamp="1587333192828">
<screen x="0" y="0" width="1366" height="728" />
</state>
<state width="1322" height="174" key="GridCell.Tab.0.right/0.0.1366.728@0.0.1366.728" timestamp="1587328942458" />
<state width="1322" height="217" key="GridCell.Tab.1.bottom" timestamp="1586962978163">
<state width="1322" height="174" key="GridCell.Tab.0.right/0.0.1366.728@0.0.1366.728" timestamp="1587333192828" />
<state width="1322" height="217" key="GridCell.Tab.1.bottom" timestamp="1587331383807">
<screen x="0" y="0" width="1366" height="728" />
</state>
<state width="1322" height="217" key="GridCell.Tab.1.bottom/0.0.1366.728@0.0.1366.728" timestamp="1586962978163" />
<state width="1322" height="217" key="GridCell.Tab.1.center" timestamp="1586962978162">
<state width="1322" height="217" key="GridCell.Tab.1.bottom/0.0.1366.728@0.0.1366.728" timestamp="1587331383807" />
<state width="1322" height="217" key="GridCell.Tab.1.center" timestamp="1587331383807">
<screen x="0" y="0" width="1366" height="728" />
</state>
<state width="1322" height="217" key="GridCell.Tab.1.center/0.0.1366.728@0.0.1366.728" timestamp="1586962978162" />
<state width="1322" height="217" key="GridCell.Tab.1.left" timestamp="1586962978162">
<state width="1322" height="217" key="GridCell.Tab.1.center/0.0.1366.728@0.0.1366.728" timestamp="1587331383807" />
<state width="1322" height="217" key="GridCell.Tab.1.left" timestamp="1587331383807">
<screen x="0" y="0" width="1366" height="728" />
</state>
<state width="1322" height="217" key="GridCell.Tab.1.left/0.0.1366.728@0.0.1366.728" timestamp="1586962978162" />
<state width="1322" height="217" key="GridCell.Tab.1.right" timestamp="1586962978162">
<state width="1322" height="217" key="GridCell.Tab.1.left/0.0.1366.728@0.0.1366.728" timestamp="1587331383807" />
<state width="1322" height="217" key="GridCell.Tab.1.right" timestamp="1587331383807">
<screen x="0" y="0" width="1366" height="728" />
</state>
<state width="1322" height="217" key="GridCell.Tab.1.right/0.0.1366.728@0.0.1366.728" timestamp="1586962978162" />
<state width="1322" height="217" key="GridCell.Tab.1.right/0.0.1366.728@0.0.1366.728" timestamp="1587331383807" />
<state x="275" y="95" key="Vcs.Push.Dialog.v2" timestamp="1587329488713">
<screen x="0" y="0" width="1366" height="728" />
</state>
<state x="275" y="95" key="Vcs.Push.Dialog.v2/0.0.1366.728@0.0.1366.728" timestamp="1587329488713" />
<state x="92" y="92" width="1182" height="544" key="com.intellij.history.integration.ui.views.FileHistoryDialog" timestamp="1586975782483">
<screen x="0" y="0" width="1366" height="728" />
</state>
......@@ -133,4 +153,25 @@
</state>
<state x="378" y="186" key="com.intellij.ide.util.TipDialog/0.0.1366.728@0.0.1366.728" timestamp="1587232896641" />
</component>
<component name="XDebuggerManager">
<breakpoint-manager>
<breakpoints>
<line-breakpoint enabled="true" type="kotlin-line">
<url>file://$PROJECT_DIR$/src/Poker.kt</url>
<line>16</line>
<option name="timeStamp" value="10" />
</line-breakpoint>
<line-breakpoint enabled="true" type="kotlin-line">
<url>file://$PROJECT_DIR$/src/Poker.kt</url>
<line>35</line>
<option name="timeStamp" value="11" />
</line-breakpoint>
<line-breakpoint enabled="true" type="kotlin-line">
<url>file://$PROJECT_DIR$/src/Poker.kt</url>
<line>65</line>
<option name="timeStamp" value="12" />
</line-breakpoint>
</breakpoints>
</breakpoint-manager>
</component>
</project>
\ No newline at end of file
/*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<Carta>): 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<Carta>): 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<Carta>()
}
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]
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]))
}
}
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"
}
3 -> {
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"
}
var trio = false
var doble = 0
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 resultado
}
fun main(args: Array<String>) {
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)}")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment