Files
pokerfreak/mac/Sources/Cockpit/Gegner.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

165 lines
6.6 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
/// Farbe und Kürzel eines Stils, wie der Kern ihn sieht (src/exploit/style.rs).
enum GegnerStil {
static func farbe(_ stil: String?) -> Color {
switch stil {
case "callingStation": .green // zahlt zu viel: hier wird Geld verdient
case "looseAggressive": .orange
case "nit": .gray
case "regular": .blue
default: .secondary
}
}
static func kuerzel(_ stil: String?) -> String {
switch stil {
case "callingStation": "CS"
case "looseAggressive": "LAG"
case "nit": "Nit"
case "regular": "Reg"
default: "?"
}
}
}
/// Das Urteil über den Tisch in einer Zeile: weich (grün), mittel, hart (rot), unklar.
struct UrteilBand: View {
var urteil: TischUrteil
private var farbe: Color {
switch urteil.urteil {
case "weich": .green
case "hart": .red
case "mittel": .blue
default: .secondary
}
}
var body: some View {
HStack(spacing: 8) {
Image(systemName: urteil.setzen ? "checkmark.seal.fill" : "hand.raised.fill")
.foregroundStyle(farbe)
VStack(alignment: .leading, spacing: 1) {
Text("Tisch \(urteil.urteil)").font(.caption.weight(.semibold)).foregroundStyle(farbe)
Text(urteil.grund).font(.caption2).foregroundStyle(.secondary)
.lineLimit(2).fixedSize(horizontal: false, vertical: true)
}
Spacer(minLength: 0)
}
.padding(.horizontal, 8).padding(.vertical, 6)
.background(farbe.opacity(0.12), in: RoundedRectangle(cornerRadius: 10))
}
}
/// Die Gegner als Karten: was der Kern über jeden denkt, in einem Satz, mit Vertrauen und
/// Fold-Chance; aufgeklappt alle Werte des Clients und die Stichprobe.
struct GegnerListe: View {
var tisch: TischAnsicht
var body: some View {
VStack(alignment: .leading, spacing: 5) {
ForEach(tisch.spieler.filter { !$0.ich }) { s in GegnerKarte(spieler: s, tisch: tisch) }
}
}
}
private struct GegnerKarte: View {
var spieler: Spieler
var tisch: TischAnsicht
@State private var offen = false
var body: some View {
let e = spieler.einschaetzung
VStack(alignment: .leading, spacing: 4) {
Button { withAnimation(.snappy) { offen.toggle() } } label: { kopf(e) }
.buttonStyle(.plain)
if let e {
Text(e.satz).font(.caption2).foregroundStyle(.primary.opacity(0.85))
.fixedSize(horizontal: false, vertical: true)
} else {
Text(spieler.profil == nil ? "Noch keine Werte zu diesem Spieler."
: "Der Kern hat an diesem Tisch noch nicht entschieden - Werte unten.")
.font(.caption2).foregroundStyle(.tertiary)
}
if offen, let p = spieler.profil { WerteRaster(profil: p).transition(.opacity) }
}
.padding(8)
.background(.white.opacity(0.05), in: RoundedRectangle(cornerRadius: 10))
.overlay(RoundedRectangle(cornerRadius: 10).strokeBorder(GegnerStil.farbe(e?.stil).opacity(e == nil ? 0 : 0.35)))
.opacity(spieler.draussen ? 0.55 : 1)
}
private func kopf(_ e: Spieler.Einschaetzung?) -> some View {
VStack(alignment: .leading, spacing: 3) {
HStack(spacing: 6) {
if let r = spieler.rolle { RollenChip(rolle: r) }
Text(spieler.name).font(.caption.weight(.semibold)).lineLimit(1)
Spacer(minLength: 4)
Text(spieler.stack.map { Format.zahl($0, stellen: 0) } ?? "–")
.font(.caption.weight(.semibold).monospacedDigit()).foregroundStyle(.yellow.opacity(0.9))
Image(systemName: offen ? "chevron.up" : "chevron.down").font(.system(size: 9)).foregroundStyle(.tertiary)
}
if let e {
HStack(spacing: 8) {
Abzeichen(text: e.stilText, farbe: GegnerStil.farbe(e.stil)).fixedSize()
if let f = e.foldChance {
Label("foldet \(Format.prozent(f))", systemImage: "arrow.uturn.down")
.font(.caption2.monospacedDigit()).foregroundStyle(.secondary).fixedSize()
.help("Chance, dass er auf einen Einsatz von 2/3 Topf aufgibt - so rechnet der Kern")
}
Spacer(minLength: 0)
Vertrauen(wert: e.vertrauen, text: e.vertrauenText, haende: spieler.profil?.haende).fixedSize()
}
}
}
.contentShape(Rectangle())
}
}
/// Wie viel der Kern den Werten glaubt: ein kleiner Balken und das Wort (dünn, mittel, belastbar).
private struct Vertrauen: View {
var wert: Double?
var text: String
var haende: Double?
var body: some View {
HStack(spacing: 3) {
Capsule().fill(.quaternary).frame(width: 22, height: 4)
.overlay(alignment: .leading) {
Capsule().fill(farbe).frame(width: 22 * min(1, max(0, wert ?? 0)), height: 4)
}
Text(text).font(.system(size: 9, weight: .medium)).foregroundStyle(farbe)
}
.help("Vertrauen in die Werte: \(Format.prozent(wert))" + (haende.map { " · Stichprobe ≈ \(Int($0)) Hände" } ?? ""))
}
private var farbe: Color { text == "belastbar" ? .green : text == "mittel" ? .orange : .secondary }
}
/// Alle Werte des Clients in vier Spalten, dazu die Stichprobe.
private struct WerteRaster: View {
var profil: Spieler.Profil
private let spalten = Array(repeating: GridItem(.flexible(), spacing: 4), count: 4)
var body: some View {
VStack(alignment: .leading, spacing: 4) {
LazyVGrid(columns: spalten, alignment: .leading, spacing: 4) {
ForEach(Spieler.Profil.wertNamen, id: \.0) { schluessel, name in
VStack(alignment: .leading, spacing: 0) {
Text(profil.werte[schluessel].map { Format.prozent($0) } ?? "–")
.font(.caption.weight(.semibold).monospacedDigit())
Text(name).font(.system(size: 8.5)).foregroundStyle(.secondary).lineLimit(1)
}
}
}
Text(profil.haende.map { "Stichprobe ≈ \(Int($0)) Hände (Client-Werte über 30 Tage, ohne Handzahl)" }
?? "Stichprobe unbekannt")
.font(.system(size: 9)).foregroundStyle(.tertiary)
}
.padding(.top, 2)
}
}