Terminadas funciones en yaku5.kt

master
Araozu 2020-10-21 07:38:57 -05:00
parent bfb91ce6a5
commit 65a792015b
5 changed files with 55 additions and 21 deletions

View File

@ -81,6 +81,8 @@ sealed class CartaNumero(valor: Int, val numero: Int = (valor shl 27) ushr 28) :
}
}
fun esExterior() = numero == 1 || numero == 10
}
class CartaNumeroNegro(valor: Int) : CartaNumero(valor)

View File

@ -32,8 +32,11 @@ enum class Yaku {
fun Yaku.obtenerListaYakus(contenedorGrupos: ContenedorGrupos): ArrayList<Yaku> {
val listaYakus = ArrayList<Yaku>()
// Invariante: 3 sequencias/triples/cuadruples y 1 par
if (contenedorGrupos.seqs.size + contenedorGrupos.tris.size != 3 || contenedorGrupos.pares.size != 1) {
// Invariante: 3 sequencias/triples/cuadruples, 1 par y ningun huerfano
if (contenedorGrupos.seqs.size + contenedorGrupos.tris.size != 3
|| contenedorGrupos.pares.size != 1
|| contenedorGrupos.huerfanos.size != 0
) {
throw Error("Error de invariante: Se intento verificar los yakus de un contenedor invalido.")
}

View File

@ -5,11 +5,7 @@ import dev.araozu.juego.ContenedorGrupos
internal fun yakuRealezaDragones(contenedorGrupos: ContenedorGrupos): Boolean {
for (carrl in contenedorGrupos.seqs) {
for (c in carrl) {
if (!c.esDragonORey()) return false
}
}
if (contenedorGrupos.tris.size != 3) return false
for (carrl in contenedorGrupos.tris) {
for (c in carrl) {

View File

@ -5,11 +5,7 @@ import dev.araozu.juego.ContenedorGrupos
internal fun yakuDragonesFull(contenedorGrupos: ContenedorGrupos): Boolean {
for (carrl in contenedorGrupos.seqs) {
for (c in carrl) {
if (c !is CartaDragon) return false
}
}
if (contenedorGrupos.tris.size != 3) return false
for (carrl in contenedorGrupos.tris) {
for (c in carrl) {
@ -28,11 +24,7 @@ internal fun yakuDragonesFull(contenedorGrupos: ContenedorGrupos): Boolean {
internal fun yakuVerde(contenedorGrupos: ContenedorGrupos): Boolean {
for (carrl in contenedorGrupos.seqs) {
for (c in carrl) {
if (!c.esCartaVerde()) return false
}
}
if (contenedorGrupos.tris.size != 3) return false
for (carrl in contenedorGrupos.tris) {
for (c in carrl) {

View File

@ -1,18 +1,59 @@
package dev.araozu.juego.yaku
import dev.araozu.juego.CartaNumero
import dev.araozu.juego.ContenedorGrupos
// TODO: Cambiar descripcion en la pagina web
internal fun yakuExterior(contenedorGrupos: ContenedorGrupos): Boolean {
if (contenedorGrupos.tris.size != 3) return false
for (carrl in contenedorGrupos.tris) {
for (c in carrl) {
if (!c.esDragonORey() || c !is CartaNumero || !c.esExterior())
return false
}
}
for (carrl in contenedorGrupos.pares) {
for (c in carrl) {
if (!c.esDragonORey() || c !is CartaNumero || !c.esExterior())
return false
}
}
return true
}
internal fun yakuEscaleraFull(contenedorGrupos: ContenedorGrupos): Boolean {
return false
}
if (contenedorGrupos.seqs.size != 3) return false
internal fun yakuTripleTriplesCerrados(contenedorGrupos: ContenedorGrupos): Boolean {
var numeroInicialSemiEscalera = 0
for (carrl in contenedorGrupos.pares) {
for (c in carrl) {
if (c !is CartaNumero) return false
numeroInicialSemiEscalera = when (c.numero) {
1 -> 2
10 -> 1
else -> return false
}
}
}
for (carrl in contenedorGrupos.seqs) {
for (c in carrl) {
if (c !is CartaNumero) return false
if (c.numero != numeroInicialSemiEscalera) return false
numeroInicialSemiEscalera += 1
}
}
return false
}
internal fun yakuTripleTriplesCerrados(contenedorGrupos: ContenedorGrupos) =
contenedorGrupos.tris.size == 3