Commit 7380864d by Yannine Alvarez

Unificar en una función para retornar valores en el poker

parent 5321f8a0
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="628f93ca-b7ce-4a63-90a4-4fc67deaa2b5" name="Default Changelist" comment="" /> <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$/src/Poker.kt" beforeDir="false" afterPath="$PROJECT_DIR$/src/Poker.kt" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" /> <option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
...@@ -10,12 +14,16 @@ ...@@ -10,12 +14,16 @@
<component name="FileTemplateManagerImpl"> <component name="FileTemplateManagerImpl">
<option name="RECENT_TEMPLATES"> <option name="RECENT_TEMPLATES">
<list> <list>
<option value="Kotlin File" />
<option value="Class" /> <option value="Class" />
<option value="Kotlin File" />
</list> </list>
</option> </option>
</component> </component>
<component name="Git.Settings">
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$/.." />
</component>
<component name="ProjectId" id="1aUUEoXpf2zKLPGhVG9it1U3GrQ" /> <component name="ProjectId" id="1aUUEoXpf2zKLPGhVG9it1U3GrQ" />
<component name="ProjectLevelVcsManager" settingsEditedManually="true" />
<component name="ProjectViewState"> <component name="ProjectViewState">
<option name="hideEmptyMiddlePackages" value="true" /> <option name="hideEmptyMiddlePackages" value="true" />
<option name="showExcludedFiles" value="true" /> <option name="showExcludedFiles" value="true" />
...@@ -23,6 +31,7 @@ ...@@ -23,6 +31,7 @@
</component> </component>
<component name="PropertiesComponent"> <component name="PropertiesComponent">
<property name="RunOnceActivity.ShowReadmeOnStart" value="true" /> <property name="RunOnceActivity.ShowReadmeOnStart" value="true" />
<property name="SHARE_PROJECT_CONFIGURATION_FILES" value="true" />
<property name="android.sdk.path" value="$USER_HOME$/AppData/Local/Android/Sdk" /> <property name="android.sdk.path" value="$USER_HOME$/AppData/Local/Android/Sdk" />
</component> </component>
<component name="RunManager" selected="Kotlin.PokerKt"> <component name="RunManager" selected="Kotlin.PokerKt">
...@@ -40,7 +49,7 @@ ...@@ -40,7 +49,7 @@
<option name="Make" enabled="true" /> <option name="Make" enabled="true" />
</method> </method>
</configuration> </configuration>
<configuration name="PokerKt" type="JetRunConfigurationType" factoryName="Kotlin" temporary="true" nameIsGenerated="true"> <configuration name="PokerKt" type="JetRunConfigurationType" temporary="true" nameIsGenerated="true">
<module name="Poker" /> <module name="Poker" />
<option name="VM_PARAMETERS" /> <option name="VM_PARAMETERS" />
<option name="PROGRAM_PARAMETERS" /> <option name="PROGRAM_PARAMETERS" />
...@@ -79,22 +88,26 @@ ...@@ -79,22 +88,26 @@
<screen x="0" y="0" width="1366" height="728" /> <screen x="0" y="0" width="1366" height="728" />
</state> </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="413" y="109" key="#com.intellij.refactoring.typeMigration.ui.FailedConversionsDialog/0.0.1366.728@0.0.1366.728" timestamp="1586915044775" />
<state width="1322" height="174" key="GridCell.Tab.0.bottom" timestamp="1587084922844"> <state x="313" y="0" key="CommitChangelistDialog2" timestamp="1587329027195">
<screen x="0" y="0" width="1366" height="728" /> <screen x="0" y="0" width="1366" height="728" />
</state> </state>
<state width="1322" height="174" key="GridCell.Tab.0.bottom/0.0.1366.728@0.0.1366.728" timestamp="1587084922844" /> <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.center" timestamp="1587084922843"> <state width="1322" height="174" key="GridCell.Tab.0.bottom" timestamp="1587328942458">
<screen x="0" y="0" width="1366" height="728" /> <screen x="0" y="0" width="1366" height="728" />
</state> </state>
<state width="1322" height="174" key="GridCell.Tab.0.center/0.0.1366.728@0.0.1366.728" timestamp="1587084922843" /> <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.left" timestamp="1587084922843"> <state width="1322" height="174" key="GridCell.Tab.0.center" timestamp="1587328942458">
<screen x="0" y="0" width="1366" height="728" /> <screen x="0" y="0" width="1366" height="728" />
</state> </state>
<state width="1322" height="174" key="GridCell.Tab.0.left/0.0.1366.728@0.0.1366.728" timestamp="1587084922843" /> <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.right" timestamp="1587084922843"> <state width="1322" height="174" key="GridCell.Tab.0.left" timestamp="1587328942458">
<screen x="0" y="0" width="1366" height="728" /> <screen x="0" y="0" width="1366" height="728" />
</state> </state>
<state width="1322" height="174" key="GridCell.Tab.0.right/0.0.1366.728@0.0.1366.728" timestamp="1587084922843" /> <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">
<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="217" key="GridCell.Tab.1.bottom" timestamp="1586962978163">
<screen x="0" y="0" width="1366" height="728" /> <screen x="0" y="0" width="1366" height="728" />
</state> </state>
...@@ -115,5 +128,9 @@ ...@@ -115,5 +128,9 @@
<screen x="0" y="0" width="1366" height="728" /> <screen x="0" y="0" width="1366" height="728" />
</state> </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="1586975782483" />
<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>
</project> </project>
\ No newline at end of file
/*REPOSITORIO GITLAB: https://phoebe.roshka.com/gitlab/yalvarez/kotlin-e004-poker*/ /*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 jugada(resultado: String): String{
fun isStraight(cards: List<Carta>): 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<Carta>): Boolean {
val suit = cartas[0].palo
if (cartas.drop(1).all { it.palo == suit }) return true
return false
}
fun jugada(mano: String): String { var cartas = arrayOf(0,0,0,0)
val h = mano.toLowerCase() var numerojugado = arrayOf(0,0,0,0,0,0,0,0,0,0,0,0,0)
val split = h.split(' ').filterNot { it == "" }.distinct() var resultado: String = "NADA"
if (split.size != 5) return "invalid"
val cartas = mutableListOf<Carta>()
for (s in split) { for (paloss in resultado){
if (s.length != 2) return "invalid"
val fIndex = CARAS.indexOf(s[0]) if(paloss == 'S'){
if (fIndex == -1) return "invalid" cartas[1]
val sIndex = LETRAS.indexOf(s[1]) }
if (sIndex == -1) return "invalid" if(paloss == 'D'){
cartas.add(Carta(fIndex + 2, s[1])) cartas[2]
}
if(paloss == 'D'){
cartas[3]
}
if(paloss == 'S'){
cartas[4]
} }
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 -> { for (valor in resultado){
if (groups.any { it.value.size == 3 }) return "3 tipos de cartas" if(valor == 'A'){
return "DOS PARES" numerojugado[1]
} }
4 -> return "UN PAR" if(valor == '2'){
else -> { numerojugado[2]
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"
} }
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 (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
}
}
}
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>) { fun main(args: Array<String>) {
val manos = arrayOf( val manos = arrayOf(
"2h 2d 2c kc qd", "2h 2d 2c kc qd",
......
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