Commit 38bf1150 by Yannine Alvarez

corrección de valor de retorno, agregar return poker.

parent ba41aa43
......@@ -3,6 +3,8 @@
<component name="ChangeListManager">
<list default="true" id="628f93ca-b7ce-4a63-90a4-4fc67deaa2b5" name="Default Changelist" comment="">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="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/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" />
......@@ -19,6 +21,11 @@
</option>
</component>
<component name="Git.Settings">
<option name="RECENT_BRANCH_BY_REPOSITORY">
<map>
<entry key="$PROJECT_DIR$/.." value="master" />
</map>
</option>
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$/.." />
</component>
<component name="ProjectId" id="1aUUEoXpf2zKLPGhVG9it1U3GrQ" />
......@@ -94,87 +101,82 @@
<option name="project" value="LOCAL" />
<updated>1587333258876</updated>
</task>
<option name="localTasksCounter" value="3" />
<task id="LOCAL-00003" summary="corrección de valor de retorno, agregar return poker.">
<created>1587334433015</created>
<option name="number" value="00003" />
<option name="presentableId" value="LOCAL-00003" />
<option name="project" value="LOCAL" />
<updated>1587334433015</updated>
</task>
<option name="localTasksCounter" value="4" />
<servers />
</component>
<component name="VcsManagerConfiguration">
<MESSAGE value="Unificar en una función para retornar valores en el poker" />
<MESSAGE value="corrección de valor de retorno." />
<option name="LAST_COMMIT_MESSAGE" value="corrección de valor de retorno." />
<MESSAGE value="corrección de valor de retorno, agregar return poker." />
<option name="LAST_COMMIT_MESSAGE" value="corrección de valor de retorno, agregar return 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="1587333255252">
<state x="313" y="0" key="CommitChangelistDialog2" timestamp="1587334430833">
<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="1587333255252" />
<state width="1322" height="174" key="GridCell.Tab.0.bottom" timestamp="1587333947392">
<state x="313" y="0" key="CommitChangelistDialog2/0.0.1366.728@0.0.1366.728" timestamp="1587334430833" />
<state width="1322" height="145" key="GridCell.Tab.0.bottom" timestamp="1587433392572">
<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="1587333947392" />
<state width="1322" height="174" key="GridCell.Tab.0.center" timestamp="1587333947392">
<state width="1322" height="145" key="GridCell.Tab.0.bottom/0.0.1366.728@0.0.1366.728" timestamp="1587433392572" />
<state width="1322" height="145" key="GridCell.Tab.0.center" timestamp="1587433392572">
<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="1587333947392" />
<state width="1322" height="174" key="GridCell.Tab.0.left" timestamp="1587333947392">
<state width="1322" height="145" key="GridCell.Tab.0.center/0.0.1366.728@0.0.1366.728" timestamp="1587433392572" />
<state width="1322" height="145" key="GridCell.Tab.0.left" timestamp="1587433392572">
<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="1587333947392" />
<state width="1322" height="174" key="GridCell.Tab.0.right" timestamp="1587333947392">
<state width="1322" height="145" key="GridCell.Tab.0.left/0.0.1366.728@0.0.1366.728" timestamp="1587433392572" />
<state width="1322" height="145" key="GridCell.Tab.0.right" timestamp="1587433392572">
<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="1587333947392" />
<state width="1322" height="217" key="GridCell.Tab.1.bottom" timestamp="1587331383807">
<state width="1322" height="145" key="GridCell.Tab.0.right/0.0.1366.728@0.0.1366.728" timestamp="1587433392572" />
<state width="1322" height="217" key="GridCell.Tab.1.bottom" timestamp="1587426755634">
<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="1587331383807" />
<state width="1322" height="217" key="GridCell.Tab.1.center" timestamp="1587331383807">
<state width="1322" height="217" key="GridCell.Tab.1.bottom/0.0.1366.728@0.0.1366.728" timestamp="1587426755634" />
<state width="1322" height="217" key="GridCell.Tab.1.center" timestamp="1587426755633">
<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="1587331383807" />
<state width="1322" height="217" key="GridCell.Tab.1.left" timestamp="1587331383807">
<state width="1322" height="217" key="GridCell.Tab.1.center/0.0.1366.728@0.0.1366.728" timestamp="1587426755633" />
<state width="1322" height="217" key="GridCell.Tab.1.left" timestamp="1587426755633">
<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="1587331383807" />
<state width="1322" height="217" key="GridCell.Tab.1.right" timestamp="1587331383807">
<state width="1322" height="217" key="GridCell.Tab.1.left/0.0.1366.728@0.0.1366.728" timestamp="1587426755633" />
<state width="1322" height="217" key="GridCell.Tab.1.right" timestamp="1587426755633">
<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="1587331383807" />
<state x="275" y="95" key="Vcs.Push.Dialog.v2" timestamp="1587333273924">
<state width="1322" height="217" key="GridCell.Tab.1.right/0.0.1366.728@0.0.1366.728" timestamp="1587426755633" />
<state x="275" y="95" key="Vcs.Push.Dialog.v2" timestamp="1587334538702">
<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="1587333273924" />
<state x="92" y="92" width="1182" height="544" key="com.intellij.history.integration.ui.views.FileHistoryDialog" timestamp="1586975782483">
<state x="275" y="95" key="Vcs.Push.Dialog.v2/0.0.1366.728@0.0.1366.728" timestamp="1587334538702" />
<state x="92" y="92" width="1182" height="544" key="com.intellij.history.integration.ui.views.FileHistoryDialog" timestamp="1587430678418">
<screen x="0" y="0" width="1366" height="728" />
</state>
<state x="92" y="92" width="1182" height="544" key="com.intellij.history.integration.ui.views.FileHistoryDialog/0.0.1366.728@0.0.1366.728" timestamp="1586975782483" />
<state x="92" y="92" width="1182" height="544" key="com.intellij.history.integration.ui.views.FileHistoryDialog/0.0.1366.728@0.0.1366.728" timestamp="1587430678418" />
<state x="378" y="186" key="com.intellij.ide.util.TipDialog" timestamp="1587232896641">
<screen x="0" y="0" width="1366" height="728" />
</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>70</line>
<option name="timeStamp" value="12" />
</line-breakpoint>
</breakpoints>
</breakpoint-manager>
<state x="424" y="5" key="refactoring.ChangeSignatureDialog" timestamp="1587430721574">
<screen x="0" y="0" width="1366" height="728" />
</state>
<state x="424" y="5" key="refactoring.ChangeSignatureDialog/0.0.1366.728@0.0.1366.728" timestamp="1587430721574" />
<state x="339" y="157" key="run.anything.popup" timestamp="1587335625311">
<screen x="0" y="0" width="1366" height="728" />
</state>
<state x="339" y="157" key="run.anything.popup/0.0.1366.728@0.0.1366.728" timestamp="1587335625311" />
</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)
// Repositorio https://phoebe.roshka.com/gitlab/yalvarez/kotlin-e004-poker
const val CARAS = "23456789tjqka"
const val LETRAS = "shdc"
//clase carta que recibe el valor y el palo
class Carta(completo: String) {
fun valorPalo(): String {
return valor + palo
}
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
}
fun esColor(cartas: List<Carta>): Boolean {
val palo = cartas[0].palo
if (cartas.drop(1).all { it.palo == palo }) return true
return false
}
var valor: String
var palo: String
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 (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]))
init {
valor = completo[0].toString()
palo = completo[1].toString()
}
}
//clase que ordena las cartas
class OrdenarCartas {
val valores = charArrayOf('A', '2', '3', '4', '5', '6', '7', '8', '9', 'T', 'J', 'Q', 'K')
val palos = charArrayOf('S', 'C', 'H', 'D')
val groups = cartas.groupBy { it.valor }
when (groups.size) {
2 -> {
fun compararValor(valor1: Char, valor2: Char): Int {
var numValor1 = 0
var numValor2 = 0
return "FULL"
for (i in valores.indices) {
if (valor1 == valores[i]) {
numValor1 = i
break
}
}
3 -> {
return "DOS PARES"
for (i in valores.indices) {
if (valor2 == valores[i]) {
numValor2 = i
break
}
}
4 -> {
return "UN PAR"
return if (numValor1 == numValor2) {
0
} else if (numValor1 > numValor2) {
1
} else {
-1
}
5 -> {
return "POKER"
}
fun esAnterior(carta1: Carta, carta2: Carta): Boolean {
var valor1 = 0
var valor2 = 0
//Buscamos la posicion del valor de la otra carta
for (i in valores.indices) {
if (carta1.valorPalo()[0] == valores[i]) {
valor1 = i
break
}
}
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"
//Buscamos la posicion del valor de esta carta
for (i in valores.indices) {
if (carta2.valorPalo()[0] == valores[i]) {
valor2 = i
break
}
}
//averiguamos si es el siguiente
return if (valor1 != valor2 + 1) {
false
} else true
}
}
//completar para mostrar la mano ganadora de acuerdo a la clasificacion de jugadas del poker
fun ganador(jugadas: MutableList<Array<Carta?>>): String? {
//Imprime la cantidad de jugadas
println("Cantidad de jugadas: " + jugadas.size)
val manos = IntArray(jugadas.size)
var mejor = 8
for (indice1 in manos.indices) {
if (manos[indice1] < mejor) {
mejor = manos[indice1]
}
}
val mejoresManos = ArrayList<Int>()
for (indice1 in manos.indices) {
if (mejor == manos[indice1]) {
mejoresManos.add(indice1)
}
}
if (mejoresManos.size == 1) {
return "Jugada " + (mejoresManos[0] + 1)
} else {
val variasManos = ArrayList<Array<Carta>>()
}
return "jugador 1"
}
fun main(args: Array<String>) {
val manos = arrayOf(
/*val manos = arrayOf(
"ah ad th tc 6s",
"as 2s 3s 4s 5s"
)
for (mano in manos) {
println("Jugada: ${jugada(mano)}")
}
}
\ No newline at end of file
}*/
val jugadas: MutableList<Array<Carta?>> = ArrayList()
val jugada1 = arrayOfNulls<Carta>(5)
jugada1[0] = Carta("AH")
jugada1[1] = Carta("AD")
jugada1[2] = Carta("TH")
jugada1[3] = Carta("TC")
jugada1[4] = Carta("6S")
val jugada2 = arrayOfNulls<Carta>(5)
jugada2[0] = Carta("AH")
jugada2[1] = Carta("KD")
jugada2[2] = Carta("QH")
jugada2[3] = Carta("3C")
jugada2[4] = Carta("3S")
jugadas.add(jugada1)
jugadas.add(jugada2)
// val ganadores: String = mc.ganadores(jugadas)
println("Jugada: ${ganador(jugadas)}")
}
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