Files
pokerfreak/mac/Sources/Cockpit/Tischbild.swift
T
mmintel 9c79d8236b Acceptance 5.11.: channel play without AFK, quiet focus, working Cockpit, stronger play
- Practice tables: 20-min session 54/54 turns at the server, control session 28 turns,
  0 timeouts; stage: 3 tables, two rounds each, clean teardown.
- Never let the clock run: an engine abstention becomes check or fold (nie_verstreichen).
- Mittler join in a fixed order (kill the duplicate, then announce), a mittler ends with its
  game, the laufwache opens no tables, stop waits for the runner to stand up.
- Focus: no lobby connections from HUD, probes or layout; "Focus Window on Turn" off.
- Tables: disconnected or sitting-out opponents do not count; a table without channel is
  closed and avoided after 45 s; the join event keeps the writer's pid (strict invariants).
- Geldwache: same room list as the runner, the table's own report, stand up before closing.
- Engine: the small blind completes the top 65 % against limpers (price per fair share);
  the calling range of a bet is as wide as the villain calls - value bets into stations.
- Cockpit: the source tree never comes from SHELL; one operating set for laufwache and
  Cockpit (sicht/start.py --client, ServerStart).
- Project lives in ~/Projects/pokerfreak (kern was a detour).
2026-11-05 16:10:43 +01:00

175 lines
7.9 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import Foundation
import CockpitKern
import SwiftUI
/// Ein Tisch als Bild: Filz-Oval, Sitze rundherum, Board und Topf in der Mitte, der eigene Platz
/// unten mit dem Countdown als Ring. Groesse und eigener Platz aus dem Log (sitzen.raeume).
struct MiniTisch: View {
var plaetze: Int
var board: [String]
var topf: Double?
var zug: Zug?
/// Mit Plätzen aus dem Log: jeder Sitz als Schild (Name, Stack, Rolle, Aktion).
var tisch: TischAnsicht? = nil
private static let filzHell = Color(red: 0.08, green: 0.45, blue: 0.30)
private static let filzDunkel = Color(red: 0.03, green: 0.25, blue: 0.17)
private static let bande = Color(red: 0.36, green: 0.24, blue: 0.13)
private static let sitzFarbe = Color(red: 0.14, green: 0.19, blue: 0.25)
var body: some View {
GeometryReader { g in
let w: Double = g.size.width
let h: Double = g.size.height
let mitte = CGPoint(x: w / 2, y: h / 2 - 6)
let rx: Double = w / 2 - (tisch == nil ? 22 : 40)
let ry: Double = h / 2 - (tisch == nil ? 20 : 26)
ZStack {
filz(breite: rx * 2 + 16, hoehe: ry * 2 + 14, radius: w / 2)
.position(x: mitte.x, y: mitte.y)
tischmitte.position(mitte)
ForEach(0..<sitzzahl, id: \.self) { i in
sitz(i).position(Self.lage(i, von: sitzzahl, mitte: mitte, rx: rx, ry: ry))
}
}
}
.frame(height: tisch == nil ? 130 : 220)
}
/// Der Spieler an Stelle i (0 = unten, dein Platz).
private func spieler(an i: Int) -> Spieler? {
guard let t = tisch else { return nil }
return t.spieler.first { Sitzlage.stelle(sitz: $0.sitz, ich: t.ich, plaetze: sitzzahl) == i }
}
private var sitzzahl: Int { max(2, plaetze) }
/// Sitz i auf dem Oval; Sitz 0 (der eigene) unten in der Mitte.
private static func lage(_ i: Int, von n: Int, mitte: CGPoint, rx: Double, ry: Double) -> CGPoint {
let winkel = Double.pi / 2 + 2 * Double.pi * Double(i) / Double(n)
return CGPoint(x: mitte.x + rx * cos(winkel), y: mitte.y + ry * sin(winkel))
}
private func filz(breite: Double, hoehe: Double, radius: Double) -> some View {
let verlauf = RadialGradient(colors: [Self.filzHell, Self.filzDunkel], center: .center, startRadius: 4, endRadius: radius)
return Ellipse().fill(verlauf)
.overlay(Ellipse().strokeBorder(Self.bande, lineWidth: 5))
.frame(width: breite, height: hoehe)
}
/// Das Board in fünf Plätzen (noch nicht gezeigte Straßen als leere Felder), darunter der Topf.
private var tischmitte: some View {
let karten = Array(board.filter { Karte($0) != nil }.prefix(5))
return VStack(spacing: 5) {
HStack(spacing: 3) {
ForEach(0..<5, id: \.self) { i in
if i < karten.count {
KarteAnsicht(code: karten[i]).scaleEffect(0.9).frame(width: 24, height: 29)
} else {
RoundedRectangle(cornerRadius: 5).strokeBorder(.white.opacity(0.18), style: StrokeStyle(lineWidth: 1, dash: [3]))
.frame(width: 24, height: 29)
}
}
}
if let topf {
Text("Topf \(Format.zahl(topf, stellen: 0))").font(.caption.weight(.bold).monospacedDigit())
.foregroundStyle(.white)
.padding(.horizontal, 8).padding(.vertical, 2)
.background(.black.opacity(0.35), in: Capsule())
}
}
}
@ViewBuilder private func sitz(_ i: Int) -> some View {
if let s = spieler(an: i) {
SitzSchild(spieler: s, zug: s.ich ? zug : nil, bb: tisch?.bb)
} else if tisch != nil {
Circle().fill(Self.sitzFarbe.opacity(0.5)).frame(width: 12, height: 12) // frei
} else if i == 0 {
EigenerPlatz(zug: zug)
} else {
Circle().fill(Self.sitzFarbe).frame(width: 16, height: 16)
.overlay(Circle().stroke(.white.opacity(0.12)))
}
}
}
/// Ein Platz am Tisch wie am Tisch: Name, Stack in Chips (BB klein darunter), Rolle und die
/// letzte Aktion mit Betrag in Chips. Der Rand hat die Farbe des Stils, den der Kern sieht.
/// Wer aussitzt, ist blass; dein Platz trägt den Countdown-Ring.
struct SitzSchild: View {
var spieler: Spieler
var zug: Zug?
var bb: Double?
var body: some View {
let stil = spieler.einschaetzung?.stil
VStack(spacing: 0) {
HStack(spacing: 2) {
if spieler.ich { EigenerPlatz(zug: zug).scaleEffect(0.62).frame(width: 16, height: 16) }
if let r = spieler.rolle { RollenChip(rolle: r) }
Text(spieler.name).font(.system(size: 9, weight: .semibold)).lineLimit(1).truncationMode(.tail)
}
Text(spieler.stack.map { Format.zahl($0, stellen: 0) } ?? "–")
.font(.system(size: 10, weight: .bold).monospacedDigit()).foregroundStyle(.yellow.opacity(0.9))
Text(spieler.stackBB.map { "\(Format.auto($0)) bb" } ?? "")
.font(.system(size: 7.5).monospacedDigit()).foregroundStyle(.white.opacity(0.55))
if let a = spieler.aktion {
Text(aktion(a)).font(.system(size: 8, weight: .bold)).foregroundStyle(Aktionstext.farbe(a))
}
}
.padding(.horizontal, 4).padding(.vertical, 2)
.frame(maxWidth: 80)
.background(spieler.ich ? Color.accentColor.opacity(0.35) : Color.black.opacity(0.5),
in: RoundedRectangle(cornerRadius: 6))
.overlay(RoundedRectangle(cornerRadius: 6).strokeBorder(GegnerStil.farbe(stil).opacity(stil == nil ? 0 : 0.9), lineWidth: 1.5))
.overlay(alignment: .topTrailing) {
if let stil { Text(GegnerStil.kuerzel(stil)).font(.system(size: 6.5, weight: .heavy)).padding(.horizontal, 2)
.background(GegnerStil.farbe(stil), in: Capsule()).foregroundStyle(.black).offset(x: 4, y: -4) }
}
.opacity(spieler.draussen ? 0.45 : 1)
}
/// "Call 2.000" wie am Tisch - ohne Big Blind in BB.
private func aktion(_ a: String) -> String {
guard let betrag = spieler.betragBB, let bb, betrag > 0, a != "FOLD", a != "CHECK" else {
return Aktionstext.kurz(a, spieler.betragBB)
}
return Aktionstext.kurz(a, nil) + " " + Format.zahl(betrag * bb, stellen: 0)
}
}
struct RollenChip: View {
var rolle: String
var body: some View {
Text(rolle == "BTN" ? "D" : rolle).font(.system(size: 7, weight: .heavy))
.padding(.horizontal, 2.5).padding(.vertical, 0.5)
.foregroundStyle(rolle == "BTN" ? Color.black : Color.white)
.background(rolle == "BTN" ? Color.white : Color.blue.opacity(0.8), in: Capsule())
}
}
/// Der eigene Platz: pulsiert, solange ein Zug offen ist; der Ring ist die Restzeit.
struct EigenerPlatz: View {
var zug: Zug?
var body: some View {
TimelineView(.periodic(from: .now, by: 0.25)) { t in
let c = Countdown(zug: zug, jetzt: t.date.timeIntervalSince1970)
let f: Color = (c?.anteil ?? 1) < 0.25 ? .red : (c?.anteil ?? 1) < 0.5 ? .orange : .green
ZStack {
Circle().fill(Color(red: 0.10, green: 0.13, blue: 0.18))
if let c {
Circle().trim(from: 0, to: c.anteil).stroke(f, style: .init(lineWidth: 3, lineCap: .round)).rotationEffect(.degrees(-90))
Text("\(Int(c.rest.rounded(.up)))").font(.caption2.monospacedDigit().weight(.bold)).foregroundStyle(.white)
} else {
Circle().stroke(.white.opacity(0.35), lineWidth: 1.5)
Image(systemName: "person.fill").font(.system(size: 9)).foregroundStyle(.white.opacity(0.7))
}
}
.frame(width: 26, height: 26)
}
}
}