From f40ae277c03619d445344681f2b192a5ad84e866 Mon Sep 17 00:00:00 2001 From: Marc Mintel Date: Fri, 30 Oct 2026 10:10:18 +0100 Subject: [PATCH] Mac-App: Modus je Tisch - Turnier mit Spur zum Geld, K-Poker mit Tasten und Uhr The data layer already sends `modus` on jetzt and on each decision row. The app now decodes it (TischModus, lenient like the other models) and shows it on every live tile and in the opened decision: tournament level, blinds, a pulsing Bubble / green "im Geld" capsule and one tick per remaining player (filled = paid place, a bar above 40 players); K-Poker as key caps with sizes and the move clock; Cash as a quiet chip. Co-Authored-By: Claude Opus 5.5 --- mac/Sources/Cockpit/Bausteine.swift | 2 +- mac/Sources/Cockpit/Diagramme.swift | 2 +- mac/Sources/Cockpit/EntscheidungenGeld.swift | 4 + mac/Sources/Cockpit/LiveTische.swift | 1 + mac/Sources/Cockpit/ModusLeiste.swift | 165 +++++++++++++++++++ mac/Sources/CockpitKern/Ansicht.swift | 2 +- mac/Sources/CockpitKern/Darstellung.swift | 4 +- mac/Sources/CockpitKern/Fenster.swift | 2 +- mac/Sources/CockpitKern/LiveKachel.swift | 6 +- mac/Sources/CockpitKern/Modelle.swift | 8 +- mac/Sources/CockpitKern/Modus.swift | 96 +++++++++++ mac/Tests/Pruefung/Hilfen.swift | 6 + mac/Tests/Pruefung/ModusSpec.swift | 129 +++++++++++++++ mac/Tests/Pruefung/NachrichtSpec.swift | 2 +- 14 files changed, 418 insertions(+), 11 deletions(-) create mode 100644 mac/Sources/Cockpit/ModusLeiste.swift create mode 100644 mac/Sources/CockpitKern/Modus.swift create mode 100644 mac/Tests/Pruefung/ModusSpec.swift diff --git a/mac/Sources/Cockpit/Bausteine.swift b/mac/Sources/Cockpit/Bausteine.swift index c85a650..e82be3e 100644 --- a/mac/Sources/Cockpit/Bausteine.swift +++ b/mac/Sources/Cockpit/Bausteine.swift @@ -16,7 +16,7 @@ enum Farben { } } - /// Zustand eines Raums als Farbe - wie zKlasse in der Seite. + /// Zustand eines Raums als Farbe. static func zustand(_ z: String?) -> Color { switch z { case "gesessen": .green; case "wartend", "Dialog offen": .orange; case "frei": .blue; case "voll": .red diff --git a/mac/Sources/Cockpit/Diagramme.swift b/mac/Sources/Cockpit/Diagramme.swift index 6227651..f4cd218 100644 --- a/mac/Sources/Cockpit/Diagramme.swift +++ b/mac/Sources/Cockpit/Diagramme.swift @@ -172,7 +172,7 @@ struct ErgebnisAnsicht: View { } } -/// bb/100 ueber alle Stakes, gewichtet nach Haenden (wie gesamtBB100 der Seite). +/// bb/100 ueber alle Stakes, gewichtet nach Haenden. enum BB100 { static func gesamt(_ z: [StakeZeile]) -> Double? { let n = z.reduce(0) { $0 + ($1.haende ?? 0) } diff --git a/mac/Sources/Cockpit/EntscheidungenGeld.swift b/mac/Sources/Cockpit/EntscheidungenGeld.swift index c4bb071..c699355 100644 --- a/mac/Sources/Cockpit/EntscheidungenGeld.swift +++ b/mac/Sources/Cockpit/EntscheidungenGeld.swift @@ -87,6 +87,10 @@ struct EntscheidungsZeileAnsicht: View { if !z.karten.isEmpty { Kartenzeile(karten: z.karten, board: z.board) } Text(z.klartext ?? z.grund ?? "").font(.caption).foregroundStyle(.secondary).lineLimit(offen ? nil : 2) } + if offen, let m = z.modus { + // Cash steht schon unter Stake; Turnier und K-Poker brauchen die ganze Lage + if case .cash = m {} else { ModusLeiste(modus: m) } + } if offen { Grid(alignment: .leading, horizontalSpacing: 10, verticalSpacing: 3) { zeile("Tisch", z.raum ?? "–") diff --git a/mac/Sources/Cockpit/LiveTische.swift b/mac/Sources/Cockpit/LiveTische.swift index a695bee..2b225b6 100644 --- a/mac/Sources/Cockpit/LiveTische.swift +++ b/mac/Sources/Cockpit/LiveTische.swift @@ -127,6 +127,7 @@ struct KachelAnsicht: View { symbolKnopf("camera", "Foto") { cockpit.steuern("foto", raum: k.raum) } symbolKnopf("xmark", "Tisch schließen") { cockpit.steuern("tische_schliessen", raum: k.raum) } } + if let m = k.modus { ModusLeiste(modus: m) } MiniTisch(plaetze: k.raumInfo?.groesse ?? 6, board: k.board, topf: topf, zug: k.zug, tisch: k.raumInfo?.tisch) if !k.karten.isEmpty { HStack(spacing: 4) { ForEach(Array(k.karten.enumerated()), id: \.offset) { KarteAnsicht(code: $0.element, gross: true) } } diff --git a/mac/Sources/Cockpit/ModusLeiste.swift b/mac/Sources/Cockpit/ModusLeiste.swift new file mode 100644 index 0000000..e0ba9e7 --- /dev/null +++ b/mac/Sources/Cockpit/ModusLeiste.swift @@ -0,0 +1,165 @@ +import CockpitKern +import SwiftUI + +/// Der Modus eines Tisches auf einen Blick: Cash, Turnier (Level, Blinds, Spur zum Geld) oder +/// K-Poker (Menue als Tasten, Uhr). Quelle ist die Anfrage, mit der der Kern entschied. +struct ModusLeiste: View { + var modus: TischModus + + var body: some View { + switch modus { + case .cash(let stake): cash(stake) + case .turnier(let t): TurnierLeiste(t: t) + case .kpoker(let k): kpoker(k) + } + } + + private func cash(_ stake: String?) -> some View { + HStack(spacing: 6) { + ModusChip(symbol: "circle.circle", text: "Cash", farbe: .secondary) + if let stake { Text(stake).font(.caption).foregroundStyle(.secondary) } + Spacer(minLength: 0) + } + } + + private func kpoker(_ k: TischModus.KPoker) -> some View { + HStack(spacing: 6) { + ModusChip(symbol: "keyboard", text: "K-Poker", farbe: .teal) + if k.menue.isEmpty { + Taste(text: "Menü unbekannt", leer: true) + } else { + ForEach(Array(k.menue.enumerated()), id: \.offset) { _, p in + Taste(text: Aktionskuerzel.kurz(p.aktion, nil), groessen: p.groessen) + } + } + Spacer(minLength: 0) + Label(k.uhrS.map { "\(Format.zahl($0, stellen: 0)) s" } ?? "–", systemImage: "timer") + .font(.caption.weight(.semibold).monospacedDigit()).foregroundStyle(.secondary) + .help("Zeit für einen Zug an diesem Tisch") + } + } +} + +private struct TurnierLeiste: View { + var t: TischModus.Turnier + + var body: some View { + VStack(alignment: .leading, spacing: 5) { + HStack(spacing: 6) { + ModusChip(symbol: "trophy.fill", text: "Level \(t.level.map(String.init) ?? "–")", farbe: .indigo) + Text(blinds).font(.caption.monospacedDigit()).foregroundStyle(.secondary).lineLimit(1) + Spacer(minLength: 0) + LageKapsel(lage: t.lage) + } + if let spur = t.spur { + HStack(spacing: 8) { + Geldspur(spur: spur, lage: t.lage) + Text(t.spurText).font(.caption2.monospacedDigit()).foregroundStyle(.secondary) + .fixedSize() + } + .help("\(t.feld) Spieler übrig, \(t.bezahlt) Plätze werden bezahlt") + } + } + } + + private var blinds: String { + "BB \(Format.zahl(t.bb, stellen: 0))" + (t.ante.map { $0 > 0 ? " · Ante \(Format.zahl($0, stellen: 0))" : "" } ?? "") + } +} + +/// Bubble pulsiert orange, im Geld ist gruen, davor ruhig mit der Zahl bis zum Geld. +private struct LageKapsel: View { + var lage: TischModus.Geldlage + @State private var puls = false + + private var farbe: Color { + switch lage { + case .bubble: .orange + case .imGeld: .green + case .vorDemGeld: .secondary + } + } + + var body: some View { + HStack(spacing: 5) { + Circle().fill(farbe).frame(width: 6, height: 6).opacity(lage == .bubble && puls ? 0.3 : 1) + Text(lage.text).font(.caption2.weight(.semibold)) + } + .padding(.horizontal, 8).frame(height: 20) + .foregroundStyle(farbe) + .background(farbe.opacity(0.14), in: Capsule()) + .animation(lage == .bubble ? .easeInOut(duration: 0.8).repeatForever(autoreverses: true) : .default, value: puls) + .onAppear { puls = lage == .bubble } + .onChange(of: lage) { _, l in puls = l == .bubble } + } +} + +/// Ein Strich je verbleibendem Spieler, gefuellt = bezahlter Platz; grosse Felder als Balken. +private struct Geldspur: View { + var spur: TischModus.Spur + var lage: TischModus.Geldlage + + private var farbe: Color { lage == .imGeld ? .green : .indigo } + + var body: some View { + switch spur { + case .striche(let gefuellt, let gesamt): + HStack(spacing: 2) { + ForEach(0.. Nachricht { guard let daten = text.data(using: .utf8), let json = (try? JSONSerialization.jsonObject(with: daten)) as? [String: Any] else { return .unbekannt } diff --git a/mac/Sources/CockpitKern/Darstellung.swift b/mac/Sources/CockpitKern/Darstellung.swift index 8d223dc..1fc86ba 100644 --- a/mac/Sources/CockpitKern/Darstellung.swift +++ b/mac/Sources/CockpitKern/Darstellung.swift @@ -1,6 +1,6 @@ import Foundation -/// Restzeit des offenen Zugs - die Seite zaehlt selbst, der Server schickt nur `bis`. +/// Restzeit des offenen Zugs - die App zaehlt selbst, der Server schickt nur `bis`. public struct Countdown: Equatable, Sendable { public var rest: Double public var anteil: Double @@ -57,7 +57,7 @@ public struct EntscheidungsFilter: Equatable, Sendable { } } -/// Zahlen wie die Seite sie zeigt: deutsch, Strich fuer unbekannt. +/// Zahlen, wie die App sie zeigt: deutsch, Strich fuer unbekannt. public enum Format { private static func formatter(_ stellen: Int) -> NumberFormatter { let f = NumberFormatter() diff --git a/mac/Sources/CockpitKern/Fenster.swift b/mac/Sources/CockpitKern/Fenster.swift index 70f5c47..ac342bf 100644 --- a/mac/Sources/CockpitKern/Fenster.swift +++ b/mac/Sources/CockpitKern/Fenster.swift @@ -1,7 +1,7 @@ import Foundation // Regeln fuer das Panel ueber den Tischen. Die Dateien in sicht/scratch/ sind der Vertrag mit dem -// Bot (hand/act.py, hand/dialog.py, sicht/tische.py) - dieselben Fristen wie sicht/leiste.py. +// Bot (hand/act.py, hand/dialog.py, sicht/tische.py). public enum EscFolge: Equatable, Sendable { case eigene, notAus, ruhe } diff --git a/mac/Sources/CockpitKern/LiveKachel.swift b/mac/Sources/CockpitKern/LiveKachel.swift index 75335f0..ea32f66 100644 --- a/mac/Sources/CockpitKern/LiveKachel.swift +++ b/mac/Sources/CockpitKern/LiveKachel.swift @@ -1,7 +1,6 @@ import Foundation /// Eine Kachel der Live-Ansicht: ein Tisch mit Karten, offenem Zug und der letzten Entscheidung. -/// Dieselbe Regel wie liveRaeume/rLive in sicht/seite.html. public struct LiveKachel: Equatable, Sendable, Identifiable { public var raum: String public var raumInfo: Raum? @@ -15,6 +14,8 @@ public struct LiveKachel: Equatable, Sendable, Identifiable { public var klartext: String? public var klick: Klick? public var hinweis: String? + /// Cash, Turnier oder K-Poker - vom offenen Zug, sonst von der letzten Entscheidung am Tisch. + public var modus: TischModus? public var id: String { raum } private static let besetzt: Set = ["gesessen", "ausgesetzt", "wartend", "Dialog offen"] @@ -34,9 +35,10 @@ public struct LiveKachel: Equatable, Sendable, Identifiable { private static func kachel(_ raum: String, _ a: Ansicht) -> LiveKachel { let info = a.sitzen?.raeume.first { $0.raum == raum } var k = LiveKachel(raum: raum, raumInfo: info, karten: [], board: [], topf: nil, zug: nil, aktion: nil, - betragBB: nil, equity: nil, klartext: nil, klick: nil, hinweis: nil) + betragBB: nil, equity: nil, klartext: nil, klick: nil, hinweis: nil, modus: nil) let log = info?.hand let letzte = a.entscheidungen?.zeilen.first(where: { $0.raum == raum }) + k.modus = (a.jetzt?.raum == raum ? a.jetzt?.modus : nil) ?? letzte?.modus if let j = a.jetzt, j.raum == raum, !j.karten.isEmpty || j.entscheidung != nil || j.zug != nil { k.karten = j.karten; k.board = j.board; k.topf = j.topf; k.zug = j.zug; k.klick = j.klick if let e = j.entscheidung { diff --git a/mac/Sources/CockpitKern/Modelle.swift b/mac/Sources/CockpitKern/Modelle.swift index 533f245..0654521 100644 --- a/mac/Sources/CockpitKern/Modelle.swift +++ b/mac/Sources/CockpitKern/Modelle.swift @@ -161,9 +161,10 @@ public struct Jetzt: Decodable, Equatable, Sendable { public var zug: Zug? public var entscheidung: Entscheidung? public var klick: Klick? + public var modus: TischModus? enum CodingKeys: String, CodingKey { - case leer, raum, hand, strasse, karten, board, topf, zuZahlen = "zu_zahlen", stack, zug, entscheidung, klick + case leer, raum, hand, strasse, karten, board, topf, zuZahlen = "zu_zahlen", stack, zug, entscheidung, klick, modus } public init(from d: Decoder) throws { @@ -174,6 +175,7 @@ public struct Jetzt: Decodable, Equatable, Sendable { zug = try? c.decodeIfPresent(Zug.self, forKey: .zug) entscheidung = try? c.decodeIfPresent(Entscheidung.self, forKey: .entscheidung) klick = try? c.decodeIfPresent(Klick.self, forKey: .klick) + modus = try? c.decodeIfPresent(TischModus.self, forKey: .modus) } } @@ -199,6 +201,7 @@ public struct EntscheidungsZeile: Decodable, Equatable, Sendable, Identifiable { public var klickWarum: String? public var beleg: String? public var gedenkzeitS: Double? + public var modus: TischModus? public var id: String { "\(zeit ?? 0)|\(hand ?? "")|\(raum ?? "")|\(aktion ?? "")" } @@ -216,7 +219,7 @@ public struct EntscheidungsZeile: Decodable, Equatable, Sendable, Identifiable { enum CodingKeys: String, CodingKey { case zeit, raum, hand, strasse, karten, board, aktion, aktionText = "aktion_text", betragBB = "betrag_bb" case grund, klartext, equity, confidence, stake, spielart, ergebnisBB = "ergebnis_bb" - case ergebnisText = "ergebnis_text", klick, klickWarum = "klick_warum", beleg, gedenkzeitS = "gedenkzeit_s" + case ergebnisText = "ergebnis_text", klick, klickWarum = "klick_warum", beleg, gedenkzeitS = "gedenkzeit_s", modus } public init(from d: Decoder) throws { @@ -228,6 +231,7 @@ public struct EntscheidungsZeile: Decodable, Equatable, Sendable, Identifiable { stake: c.text(.stake), spielart: c.text(.spielart), ergebnisBB: c.zahl(.ergebnisBB), ergebnisText: c.text(.ergebnisText), klick: c.text(.klick), klickWarum: c.text(.klickWarum), beleg: c.text(.beleg), gedenkzeitS: c.zahl(.gedenkzeitS)) + modus = try? c.decodeIfPresent(TischModus.self, forKey: .modus) } } diff --git a/mac/Sources/CockpitKern/Modus.swift b/mac/Sources/CockpitKern/Modus.swift new file mode 100644 index 0000000..7bd079e --- /dev/null +++ b/mac/Sources/CockpitKern/Modus.swift @@ -0,0 +1,96 @@ +import Foundation + +/// Der Modus eines Tisches (sicht/ANSICHT.md, `modus`): womit der Kern entschieden hat. +/// Eine unbekannte Art ist kein Fehler - sie dekodiert als Fehler, und das Feld bleibt nil. +public enum TischModus: Decodable, Equatable, Sendable { + case cash(stake: String?) + case turnier(Turnier) + case kpoker(KPoker) + + public struct Turnier: Equatable, Sendable { + public var level: Int? + public var bb: Double? + public var ante: Double? + public var feld: Int + public var bezahlt: Int + + public var lage: Geldlage { + let bisGeld = max(0, feld - bezahlt) + return bisGeld == 0 ? .imGeld : bisGeld == 1 ? .bubble : .vorDemGeld(bisGeld) + } + + /// Unter der Spur: wie viele der Uebrigen bezahlt werden. + public var spurText: String { + lage == .imGeld ? "alle \(feld) im Geld" : "\(bezahlt) von \(feld) bezahlt" + } + + /// Bis so viele Spieler zeigt die Spur einen Strich je Spieler, darueber einen Anteil. + public static let stricheMax = 40 + + public var spur: Spur? { + guard feld > 0 else { return nil } + if feld > Self.stricheMax { return .anteil(min(1, Double(bezahlt) / Double(feld))) } + return .striche(gefuellt: min(bezahlt, feld), gesamt: feld) + } + } + + public enum Geldlage: Equatable, Sendable { + case vorDemGeld(Int) + case bubble + case imGeld + + public var text: String { + switch self { + case .vorDemGeld(let n): "\(n) bis zum Geld" + case .bubble: "Bubble" + case .imGeld: "im Geld" + } + } + } + + /// Die Spur zum Geld: je verbleibendem Spieler ein Strich, gefuellt = bezahlter Platz. + public enum Spur: Equatable, Sendable { + case striche(gefuellt: Int, gesamt: Int) + case anteil(Double) + } + + public struct KPoker: Equatable, Sendable { + public var menue: [Punkt] + public var uhrS: Double? + + public struct Punkt: Decodable, Equatable, Sendable { + public var aktion: String + public var groessen: [Double] + + enum CodingKeys: String, CodingKey { case aktion, groessen } + + public init(from d: Decoder) throws { + let c = try d.container(keyedBy: CodingKeys.self) + guard let a = c.text(.aktion) else { + throw DecodingError.dataCorruptedError(forKey: .aktion, in: c, debugDescription: "ohne Aktion") + } + aktion = a + groessen = c.liste(.groessen).compactMap(Double.init) + } + } + } + + enum CodingKeys: String, CodingKey { case art, text, level, bb, ante, feld, bezahlt, menue, uhrS = "uhr_s" } + + public init(from d: Decoder) throws { + let c = try d.container(keyedBy: CodingKeys.self) + switch c.text(.art) { + case "Turnier": + self = .turnier(Turnier(level: c.zahl(.level).map { Int($0) }, bb: c.zahl(.bb), ante: c.zahl(.ante), + feld: c.zahl(.feld).map { Int($0) } ?? 0, bezahlt: c.zahl(.bezahlt).map { Int($0) } ?? 0)) + case "K-Poker": + self = .kpoker(KPoker(menue: c.objekte(.menue), uhrS: c.zahl(.uhrS))) + case "Cash": + // "Cash · 0.05/0.1": der Stake steht hinter dem ersten Trenner + let teile = (c.text(.text) ?? "").components(separatedBy: " · ") + self = .cash(stake: teile.count > 1 ? teile.dropFirst().joined(separator: " · ") : nil) + default: + throw DecodingError.dataCorruptedError(forKey: .art, in: c, debugDescription: "unbekannte Art") + } + } +} diff --git a/mac/Tests/Pruefung/Hilfen.swift b/mac/Tests/Pruefung/Hilfen.swift index 542c0d6..35e8124 100644 --- a/mac/Tests/Pruefung/Hilfen.swift +++ b/mac/Tests/Pruefung/Hilfen.swift @@ -1,3 +1,4 @@ +import CockpitKern import Foundation // Ohne `import Testing` in dieser Datei: die Command Line Tools liefern das Overlay @@ -9,6 +10,11 @@ enum Hilfen { return try? String(contentsOf: url, encoding: .utf8) } + /// Ein `modus`-Objekt der Ansicht, so dekodiert wie in der App. + static func modus(_ json: String) -> TischModus? { + try? JSONDecoder().decode(TischModus.self, from: Data(json.utf8)) + } + /// (rect, zeit) aus der Rahmendatei, wie hand/act.py sie liest. static func rahmenLesen(_ d: Data) -> ([Int]?, Double?) { let j = (try? JSONSerialization.jsonObject(with: d)) as? [String: Any] diff --git a/mac/Tests/Pruefung/ModusSpec.swift b/mac/Tests/Pruefung/ModusSpec.swift new file mode 100644 index 0000000..febd10a --- /dev/null +++ b/mac/Tests/Pruefung/ModusSpec.swift @@ -0,0 +1,129 @@ +import CockpitKern +import Testing + +private func modus(_ json: String) -> TischModus? { Hilfen.modus(json) } + +private func ansicht(_ json: String) -> Ansicht { + var a = Ansicht() + _ = a.anwenden(#"{"typ":"ansicht","teile":"# + json + "}") + return a +} + +@Suite("Modus in der Live-Kachel: der laufende Zug zuerst, sonst die letzte Entscheidung am Tisch") +struct ModusKachelSpec { + static let teile = #""" + {"kopf":{"laeuft":true,"tische":["A","B"]}, + "jetzt":{"raum":"A","karten":["Qh","8c"],"zug":{"offen":true,"bis":1}, + "entscheidung":{"aktion":"FOLD"},"modus":{"art":"Turnier","level":4,"feld":15,"bezahlt":14}}, + "entscheidungen":{"zeilen":[ + {"raum":"B","hand":"h9","aktion":"CALL","modus":{"art":"K-Poker","menue":[{"aktion":"FOLD"}],"uhr_s":10}}, + {"raum":"A","hand":"h1","aktion":"CALL","modus":{"art":"Cash","text":"Cash · 0.05/0.1"}}]}, + "sitzen":{"raeume":[]}} + """# + + @Test("jetzt und Entscheidungszeilen tragen den Modus") + func gelesen() { + let a = ansicht(Self.teile) + guard case .turnier(let t)? = a.jetzt?.modus else { Issue.record("jetzt ohne Turnier"); return } + #expect(t.lage == .bubble) + #expect(a.entscheidungen?.zeilen.last?.modus == .cash(stake: "0.05/0.1")) + } + + @Test("Kachel A: Modus des offenen Zugs, Kachel B: Modus der letzten Entscheidung") + func kachel() { + let k = LiveKachel.alle(ansicht(Self.teile)) + let a = k.first { $0.raum == "A" }, b = k.first { $0.raum == "B" } + guard case .turnier? = a?.modus else { Issue.record("A ohne Turnier: \(String(describing: a?.modus))"); return } + guard case .kpoker(let kp)? = b?.modus else { Issue.record("B ohne K-Poker: \(String(describing: b?.modus))"); return } + #expect(kp.uhrS == 10) + } + + @Test("ohne Modus im Server bleibt die Kachel ohne") + func ohne() { + let k = LiveKachel.alle(ansicht(#"{"kopf":{"laeuft":true,"tische":["C"]},"sitzen":{"raeume":[]}}"#)) + #expect(k.first?.modus == nil) + } +} + +@Suite("Modus des Tisches: Cash, Turnier mit Spur zum Geld, K-Poker mit Menü und Uhr (ANSICHT.md modus)") +struct ModusSpec { + @Test("Turnier auf der Bubble: Level, Blinds, Feld, bezahlt") + func bubble() { + let m = modus(#"{"art":"Turnier","level":19,"bb":2500.0,"ante":312,"feld":15,"bezahlt":14,"bis_geld":1,"bubble":true,"im_geld":false,"text":"Turnier · Level 19"}"#) + guard case .turnier(let t)? = m else { Issue.record("kein Turnier: \(String(describing: m))"); return } + #expect(t.level == 19) + #expect(t.bb == 2500) + #expect(t.ante == 312) + #expect((t.feld, t.bezahlt) == (15, 14)) + #expect(t.lage == .bubble) + #expect(t.lage.text == "Bubble") + } + + @Test("vor dem Geld und im Geld") + func lagen() { + guard case .turnier(let vor)? = modus(#"{"art":"Turnier","level":3,"feld":18,"bezahlt":14}"#), + case .turnier(let drin)? = modus(#"{"art":"Turnier","level":3,"feld":9,"bezahlt":14}"#) else { + Issue.record("kein Turnier"); return + } + #expect(vor.lage == .vorDemGeld(4)) + #expect(vor.lage.text == "4 bis zum Geld") + #expect(drin.lage == .imGeld) + #expect(drin.lage.text == "im Geld") + #expect(vor.spurText == "14 von 18 bezahlt") + #expect(drin.spurText == "alle 9 im Geld") + } + + @Test("Spur zum Geld: ein Strich je Spieler, gefüllt = bezahlt; große Felder als Anteil") + func spur() { + guard case .turnier(let t)? = modus(#"{"art":"Turnier","feld":15,"bezahlt":14}"#), + case .turnier(let gross)? = modus(#"{"art":"Turnier","feld":95,"bezahlt":14}"#), + case .turnier(let drin)? = modus(#"{"art":"Turnier","feld":9,"bezahlt":14}"#) else { + Issue.record("kein Turnier"); return + } + #expect(t.spur == .striche(gefuellt: 14, gesamt: 15)) + #expect(drin.spur == .striche(gefuellt: 9, gesamt: 9)) + #expect(gross.spur == .anteil(14.0 / 95.0)) + } + + @Test("K-Poker: Menü mit Größen und Uhr") + func kpoker() { + let m = modus(#"{"art":"K-Poker","menue":[{"aktion":"FOLD"},{"aktion":"CALL"},{"aktion":"RAISE","groessen":[0.8,2.4]}],"uhr_s":10,"text":"K-Poker"}"#) + guard case .kpoker(let k)? = m else { Issue.record("kein K-Poker: \(String(describing: m))"); return } + #expect(k.menue.map(\.aktion) == ["FOLD", "CALL", "RAISE"]) + #expect(k.menue.last?.groessen == [0.8, 2.4]) + #expect(k.menue.first?.groessen == []) + #expect(k.uhrS == 10) + } + + @Test("K-Poker ohne Menü und Uhr bleibt K-Poker") + func kpokerLeer() { + guard case .kpoker(let k)? = modus(#"{"art":"K-Poker","menue":[],"uhr_s":null}"#) else { + Issue.record("kein K-Poker"); return + } + #expect(k.menue.isEmpty) + #expect(k.uhrS == nil) + } + + @Test("Cash nennt den Stake aus dem Text") + func cash() { + #expect(modus(#"{"art":"Cash","text":"Cash · 0.05/0.1"}"#) == .cash(stake: "0.05/0.1")) + #expect(modus(#"{"art":"Cash","text":"Cash"}"#) == .cash(stake: nil)) + } + + @Test("unbekannte Art ist kein Fehler, sondern kein Modus") + func unbekannt() { + #expect(modus(#"{"art":"Sit&Go"}"#) == nil) + #expect(modus(#"{}"#) == nil) + } + + @Test("Zahlen mal als Text, mal als Zahl - nachsichtig gelesen") + func nachsichtig() { + guard case .turnier(let t)? = modus(#"{"art":"Turnier","level":"7","bb":"300","feld":"x","bezahlt":3}"#) else { + Issue.record("kein Turnier"); return + } + #expect(t.level == 7) + #expect(t.bb == 300) + #expect(t.feld == 0) + #expect(t.spur == nil) + } +} diff --git a/mac/Tests/Pruefung/NachrichtSpec.swift b/mac/Tests/Pruefung/NachrichtSpec.swift index 5292deb..c2da94a 100644 --- a/mac/Tests/Pruefung/NachrichtSpec.swift +++ b/mac/Tests/Pruefung/NachrichtSpec.swift @@ -80,7 +80,7 @@ struct NachrichtSpec { } } -@Suite("Live-Kacheln - gleiche Regel wie liveRaeume/rLive der Seite") +@Suite("Live-Kacheln: welche Tische, mit welchem Inhalt") struct LiveSpec { func ansicht(_ json: String) -> Ansicht { var a = Ansicht()