diff --git a/api-webapp/src/main/kotlin/org/jeudego/pairgoth/ext/OpenGotha.kt b/api-webapp/src/main/kotlin/org/jeudego/pairgoth/ext/OpenGotha.kt index 90dbb9d..b5542d4 100644 --- a/api-webapp/src/main/kotlin/org/jeudego/pairgoth/ext/OpenGotha.kt +++ b/api-webapp/src/main/kotlin/org/jeudego/pairgoth/ext/OpenGotha.kt @@ -4,12 +4,11 @@ import org.jeudego.pairgoth.model.* import org.jeudego.pairgoth.store.Store import org.jeudego.pairgoth.util.XmlFormat import org.jeudego.pairgoth.util.booleanAttr -import org.jeudego.pairgoth.util.childrenArrayOf +import org.jeudego.pairgoth.util.arrayOf import org.jeudego.pairgoth.util.dateAttr import org.jeudego.pairgoth.util.doubleAttr -import org.jeudego.pairgoth.util.find -import org.jeudego.pairgoth.util.get import org.jeudego.pairgoth.util.intAttr +import org.jeudego.pairgoth.util.mutableArrayOf import org.jeudego.pairgoth.util.objectOf import org.jeudego.pairgoth.util.optBoolean import org.jeudego.pairgoth.util.stringAttr @@ -18,8 +17,8 @@ import java.util.* class OpenGothaFormat(xml: Element): XmlFormat(xml) { - val Players by childrenArrayOf() - val Games by childrenArrayOf() + val Players by mutableArrayOf() + val Games by mutableArrayOf() val TournamentParameterSet by objectOf() class Player(xml: Element): XmlFormat(xml) { @@ -48,6 +47,7 @@ class OpenGothaFormat(xml: Element): XmlFormat(xml) { val GeneralParameterSet by objectOf() val HandicapParameterSet by objectOf() val PairingParameterSet by objectOf() + val PlacementParameterSet by objectOf() class GenParams(xml: Element): XmlFormat(xml) { val bInternet by optBoolean() @@ -80,6 +80,12 @@ class OpenGothaFormat(xml: Element): XmlFormat(xml) { val paiMaSeedSystem1 by stringAttr() val paiMaSeedSystem2 by stringAttr() } + class Criteria(xml: Element): XmlFormat(xml) { + val PlacementCriterion by arrayOf() + } + class Criterion(xml: Element): XmlFormat(xml) { + val name by stringAttr() + } } } @@ -89,6 +95,7 @@ object OpenGotha { val genParams = imported.TournamentParameterSet.GeneralParameterSet val handParams = imported.TournamentParameterSet.HandicapParameterSet val pairingParams = imported.TournamentParameterSet.PairingParameterSet + val placementParams = imported.TournamentParameterSet.PlacementParameterSet val tournament = StandardTournament( id = Store.nextTournamentId, type = Tournament.Type.INDIVIDUAL, // CB for now, TODO @@ -107,22 +114,22 @@ object OpenGotha { else -> throw Error("missing byoyomi type") }, pairing = when (handParams.hdCeiling) { - /* - when (pairingParams.paiMaSeedSystem1) { - "SPLITANDFOLD" -> SeedMethod.SPLIT_AND_FOLD - "SPLITANDRANDOM" -> SeedMethod.SPLIT_AND_RANDOM - "SPLITANDSLIP" -> SeedMethod.SPLIT_AND_SLIP - else -> throw Error("unknown swiss pairing method") - }, - when (pairingParams.paiMaSeedSystem2) { - "SPLITANDFOLD" -> SeedMethod.SPLIT_AND_FOLD - "SPLITANDRANDOM" -> SeedMethod.SPLIT_AND_RANDOM - "SPLITANDSLIP" -> SeedMethod.SPLIT_AND_SLIP - else -> throw Error("unknown swiss pairing method") - } - */ - 0 -> Swiss() // TODO - else -> MacMahon() // TODO + 0 -> Swiss( + pairingParams = PairingParams( + + ), + placementParams = PlacementParams( + crit = placementParams.PlacementCriterion.map { Criterion.valueOf(it.name) }.toTypedArray() + ) + ) // TODO + else -> MacMahon( + pairingParams = PairingParams( + + ), + placementParams = PlacementParams( + + ) + ) // TODO }, rounds = genParams.numberOfRounds ) @@ -169,6 +176,12 @@ object OpenGotha { // TODO - bye player(s) fun export(tournament: Tournament<*>): String { + // two methods here + // method 1 (advised because it's more error-proof but more complex to set up) is to assign one by one + // the fields of an OpenGothaFormat instance, then call toPrettyString() on it + // opengotha = OpenGothaFormat() + // + // method 2 (quick and dirty) is to rely on templating: val xml = """ @@ -238,18 +251,17 @@ object OpenGotha { TimeSystem.TimeSystemType.CANADIAN -> "CANBYOYOMI" TimeSystem.TimeSystemType.FISCHER -> "FISCHER" } }" director="" endDate="${tournament.endDate}" fischerTime="${tournament.timeSystem.increment}" genCountNotPlayedGamesAsHalfPoint="false" genMMBar="9D" genMMFloor="30K" genMMS2ValueAbsent="1" genMMS2ValueBye="2" genMMZero="30K" genNBW2ValueAbsent="0" genNBW2ValueBye="2" genRoundDownNBWMMS="true" komi="${tournament.komi}" location="${tournament.location}" name="${tournament.name}" nbMovesCanTime="${tournament.timeSystem.stones}" numberOfCategories="1" numberOfRounds="${tournament.rounds}" shortName="${tournament.shortName}" size="${tournament.gobanSize}" stdByoYomiTime="${tournament.timeSystem.byoyomi}"/> - + - - - - - - + ${ + (0..5).map { + """""" + } + } - + diff --git a/api-webapp/src/main/kotlin/org/jeudego/pairgoth/model/Pairable.kt b/api-webapp/src/main/kotlin/org/jeudego/pairgoth/model/Pairable.kt index b1dd157..c9895e2 100644 --- a/api-webapp/src/main/kotlin/org/jeudego/pairgoth/model/Pairable.kt +++ b/api-webapp/src/main/kotlin/org/jeudego/pairgoth/model/Pairable.kt @@ -28,7 +28,8 @@ object ByePlayer: Pairable(0, "bye", 0, Int.MIN_VALUE) { override val country = "none" } -fun Pairable.displayRank() = if (rank < 0) "${-rank}k" else "${rank + 1}d" +fun displayRank(rank: Int) = if (rank < 0) "${-rank}k" else "${rank + 1}d" +fun Pairable.displayRank() = displayRank(rank) private val rankRegex = Regex("(\\d+)([kd])", RegexOption.IGNORE_CASE) diff --git a/api-webapp/src/main/kotlin/org/jeudego/pairgoth/util/XmlFormat.kt b/api-webapp/src/main/kotlin/org/jeudego/pairgoth/util/XmlFormat.kt index 1a16880..82e4685 100644 --- a/api-webapp/src/main/kotlin/org/jeudego/pairgoth/util/XmlFormat.kt +++ b/api-webapp/src/main/kotlin/org/jeudego/pairgoth/util/XmlFormat.kt @@ -34,8 +34,8 @@ fun XmlFormat.double() = DoubleXmlDelegate(xml.element()) inline fun > XmlFormat.enum() = EnumXmlDelegate(xml.element(), E::class) fun XmlFormat.date(format: String = ISO_LOCAL_DATE_FORMAT) = DateXmlDelegate(xml.element(), format) fun XmlFormat.datetime(format: String = ISO_LOCAL_DATETIME_FORMAT) = DateTimeXmlDelegate(xml.element(), format) -inline fun XmlFormat.childrenArrayOf() = ArrayXmlDelegate(xml, T::class) -inline fun XmlFormat.childrenArrayOf(tagName: String) = ChildrenArrayXmlDelegate(xml, tagName, T::class) +inline fun XmlFormat.arrayOf() = ArrayXmlDelegate(xml, T::class) +inline fun XmlFormat.arrayOf(tagName: String) = ChildrenArrayXmlDelegate(xml, tagName, T::class) inline fun XmlFormat.mutableArrayOf() = MutableArrayXmlDelegate(xml, T::class) inline fun XmlFormat.objectOf() = ObjectXmlDelegate(xml, T::class)