Tische je Stufe: Zahl je gewaehlter Cash-Stufe im Plan, live per Knopf

Owner 26.11.: live liess sich nur eine ganze Stufe an/aus schalten. Der Plan traegt jetzt
stufen_tische {modus: {BB: n}}; eine volle Stufe oeffnet nichts mehr, eine gesenkte baut
ihre schwaechsten Tische ab (wie die Gesamtzahl). Cockpit: je Stufe '− n +' und 'frei'.
Spec tischzahl_abbau kannte nur_offene noch nicht (nachgezogen).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-26 21:00:35 +01:00
co-authored by Claude Opus 5.5
parent 75a49aa79d
commit a3ae16e1f8
7 changed files with 241 additions and 8 deletions
+23 -2
View File
@@ -4215,7 +4215,12 @@ class Sitzer:
return
sitzend = [r for r, l in tische
if l is not None and l.held_sitz is not None and not sitzen.turniertisch(l)]
if len(sitzend) - sum(1 for r in sitzend if r in self.abgang) <= plan.tische:
bb_je = {r: round(float(l.bb), 6) for r, l in tische
if r in sitzend and isinstance(getattr(l, "bb", None), (int, float))}
kappe = spielplan.stufen_tische_von(plan)
ueber_stufe = any(sum(1 for r in sitzend if r not in self.abgang and bb_je.get(r) is not None
and abs(bb_je[r] - bb) < 1e-9) > n for bb, n in kappe.items())
if len(sitzend) - sum(1 for r in sitzend if r in self.abgang) <= plan.tische and not ueber_stufe:
return
jetzt = time.time()
werte = {}
@@ -4227,9 +4232,20 @@ class Sitzer:
werte[r] = float(tischwahl_bewerten(r, self.text, jetzt)[0]["wert"])
except Exception:
werte[r] = float(tischwert.POOL_SPENDE)
weg = spielplan.abzubauen(plan, werte, gehend=self.abgang)
weg = spielplan.abzubauen_je_stufe(plan, werte, bb_je, gehend=self.abgang)
rest = {r: w for r, w in werte.items() if r not in weg}
weg += spielplan.abzubauen(plan, rest, gehend=set(self.abgang) | set(weg))
self.zahl_abbau = {r: round(werte[r], 1) for r in weg}
def _tische_je_stufe(self):
"""{BB: Cash-Tische mit Sitz dort}, ohne die im Abgang - fuer die Tischzahl je Stufe."""
je = collections.Counter()
for r, l in self.lagen.items():
if (getattr(l, "held_sitz", None) is not None and not sitzen.turniertisch(l) and r not in self.abgang
and isinstance(getattr(l, "bb", None), (int, float))):
je[round(float(l.bb), 6)] += 1
return je
def _ueberzaehlige_schliessen(self, plan, z, lagen):
"""Mehr Tische offen als geplant: die, an denen wir weder sitzen noch gerade setzen,
schliessen (zuletzt geöffnete zuerst). Aufgestanden wird dafür nie."""
@@ -4530,6 +4546,11 @@ class Sitzer:
ereignis("warnung", grund="Auffüllen: keine gewählte Stufe trägt die Bankroll ("
+ ", ".join(stufenwahl.name(b, plan.modus) for b in gewaehlt) + ")")
return
if stufen and spielplan.stufen_tische_von(plan): # Tische je Stufe (Owner 26.11.): volle Stufen auslassen
voll = spielplan.stufen_voll(plan, self._tische_je_stufe())
stufen = tuple(b for b in stufen if b not in voll)
if not stufen:
return
wecken = (("keine Tischzeilen" in text or "Liste noch nicht gebaut" in text)
and self.wieder.darf(("lobby", "wecken"), jetzt))
self.auffuellen_letzter = jetzt
+50 -1
View File
@@ -102,6 +102,7 @@ class Spielplan:
stufen: tuple = () # ((modus, (BB, ...)), ...) - Stufen nach Vorrang je Modus (betrieb/stufenwahl.py)
ring_vor_pool: bool = False # "freie Sitze bevorzugen": gut besetzter Ring-Tisch > Pool (Owner 8.11.)
turnier: Turnierplan = field(default_factory=Turnierplan) # Turnier-Auswahl (Buy-in-Band, Typ); betrieb/turnierplan.py
stufen_tische: tuple = () # ((modus, ((BB, hoechstens), ...)), ...) - Tische je Stufe; fehlt: offen (Owner 26.11.)
def __post_init__(self):
if self.geld is None:
@@ -153,6 +154,52 @@ def _stufen_aus(d):
return tuple((m, r) for m, r in je.items() if r)
def _stufen_tische_aus(d):
"""{modus: {"0.02": 10}} -> ((modus, ((0.02, 10), ...)), ...); nur ganze Zahlen 0..HOECHSTENS."""
roh = d.get("stufen_tische") if isinstance(d.get("stufen_tische"), dict) else {}
raus = []
for m in REITER:
je = roh.get(m) if isinstance(roh.get(m), dict) else {}
paare = []
for k, n in je.items():
try:
bb = round(float(k), 6)
except (TypeError, ValueError):
continue
if bb > 0 and isinstance(n, (int, float)) and not isinstance(n, bool) and n >= 0:
paare.append((bb, min(HOECHSTENS, int(n))))
if paare:
raus.append((m, tuple(sorted(paare))))
return tuple(raus)
def stufen_tische_von(plan, modus=None):
"""{BB: hoechstens} des Modus - leer: keine Stufe begrenzt."""
if plan is None:
return {}
modus = modus or plan.modus
return dict(dict(plan.stufen_tische).get(modus, ()))
def stufen_voll(plan, belegt):
"""Die Big Blinds, deren Tischzahl erreicht ist (`belegt` {BB: Tische dort})."""
kappe = stufen_tische_von(plan)
return {bb for bb, n in kappe.items() if belegt.get(bb, 0) >= n}
def abzubauen_je_stufe(plan, werte, bb_je_raum, gehend=()):
"""Wie `abzubauen`, aber je Stufe: sitzen wir an einer Stufe an mehr Tischen als ihre Zahl, die
schwaechsten dort. `bb_je_raum` {raum: BB}."""
kappe = stufen_tische_von(plan)
weg = set(gehend or ())
raus = []
for bb, n in kappe.items():
dort = [r for r in werte if r not in weg and bb_je_raum.get(r) is not None
and abs(bb_je_raum[r] - bb) < 1e-9]
raus += sorted(dort, key=lambda r: (werte[r], r))[:max(0, len(dort) - n)]
return raus
def turniere_gewaehlt(plan):
"""Sind Turniere als Format mit Tischzahl > 0 GEWAEHLT? Reines Cash -> False, auch wenn alte
Turnier-Einstellungen (kategorie/nur_laufend) noch im Plan nachhaengen (Owner 10.11.: "nur Cash
@@ -265,7 +312,7 @@ def aus_dict(d) -> Optional[Spielplan]:
zeitplan.aus_dict(d.get("zeitplan")), geldplan.aus_dict(d.get("geld"), d["modus"]),
d.get("zeiger") is True, d.get("lehrer") is True, fm or (), ziel, form,
_stufen_aus(d), d.get("ring_vor_pool") is True,
turnierplan.aus_dict(d.get("turnier")))
turnierplan.aus_dict(d.get("turnier")), _stufen_tische_aus(d))
def lesen(pfad) -> Optional[Spielplan]:
@@ -282,6 +329,8 @@ def als_dict(plan: Spielplan) -> dict:
"zeiger": plan.zeiger, "lehrer": plan.lehrer, "tischform": plan.tischform,
"zeitplan": zeitplan.als_dict(plan.zeitplan),
**({"stufen": {m: list(r) for m, r in plan.stufen}} if plan.stufen else {}),
**({"stufen_tische": {m: {f"{b:g}": n for b, n in je} for m, je in plan.stufen_tische}}
if plan.stufen_tische else {}),
**({"ring_vor_pool": True} if plan.ring_vor_pool else {}),
**({"turnier": turnierplan.als_dict(plan.turnier)} if turnierplan.gesetzt(plan.turnier) else {}),
"geld": geldplan.als_dict(plan.geld), **({"formate": dict(plan.formate)} if plan.formate else {}),
+4
View File
@@ -1207,6 +1207,10 @@ def spielplan_setzen(daten):
alt = sp.lesen(SPIELPLAN)
if alt is not None and alt.stufen:
daten = {**daten, "stufen": {m: list(r) for m, r in alt.stufen}}
if isinstance(daten, dict) and "stufen_tische" not in daten: # ebenso die Tische je Stufe
alt = sp.lesen(SPIELPLAN)
if alt is not None and alt.stufen_tische:
daten = {**daten, "stufen_tische": sp.als_dict(alt)["stufen_tische"]}
plan = sp.aus_dict(daten)
if plan is None:
return _antwort(False, "Spielplan ungültig: Modus uebung/echt und eine Tischzahl")
+76
View File
@@ -0,0 +1,76 @@
"""Tische je Stufe (Owner 26.11.: "ich kann nicht live die Tische anpassen, nur alle NL2 weg druecken"):
der Plan traegt je Stufe eine Hoechstzahl; eine volle Stufe oeffnet nichts mehr, eine gesenkte baut ihre
schwaechsten Tische ab. Ohne Zahl bleibt alles wie bisher."""
import os
import sys
import tempfile
import unittest
_W = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
for _u in ("betrieb", "lesen", "hand", "client", "sicht", "mcp"):
_p = os.path.join(_W, _u)
if _p not in sys.path:
sys.path.insert(0, _p)
import spielplan # noqa: E402
def plan(**extra):
return spielplan.aus_dict({"modus": "cash", "tische": 16, "stufen": {"cash": [0.02, 0.05]}, **extra})
class StufenTische(unittest.TestCase):
def test_ohne_zahl_nichts_begrenzt(self):
p = plan()
self.assertEqual(spielplan.stufen_tische_von(p), {})
self.assertEqual(spielplan.stufen_voll(p, {0.02: 40}), set())
self.assertNotIn("stufen_tische", spielplan.als_dict(p))
def test_hin_und_zurueck(self):
p = plan(stufen_tische={"cash": {"0.02": 10, "0.05": 4}})
self.assertEqual(spielplan.stufen_tische_von(p), {0.02: 10, 0.05: 4})
self.assertEqual(spielplan.stufen_tische_von(spielplan.aus_dict(spielplan.als_dict(p))), {0.02: 10, 0.05: 4})
def test_unsinn_faellt_weg(self):
p = plan(stufen_tische={"cash": {"x": 3, "0.02": "viele", "0.05": True, "0.1": -1, "0.25": 2}})
self.assertEqual(spielplan.stufen_tische_von(p), {0.25: 2})
def test_je_modus(self):
p = plan(stufen_tische={"uebung": {"0.02": 3}})
self.assertEqual(spielplan.stufen_tische_von(p), {})
def test_volle_stufe(self):
p = plan(stufen_tische={"cash": {"0.02": 10, "0.05": 0}})
self.assertEqual(spielplan.stufen_voll(p, {0.02: 10}), {0.02, 0.05})
self.assertEqual(spielplan.stufen_voll(p, {0.02: 9}), {0.05})
def test_abbau_die_schwaechsten_der_stufe(self):
p = plan(stufen_tische={"cash": {"0.02": 2}})
werte = {"a": 5.0, "b": -3.0, "c": 1.0, "d": -9.0}
bb = {"a": 0.02, "b": 0.02, "c": 0.02, "d": 0.05}
self.assertEqual(spielplan.abzubauen_je_stufe(p, werte, bb), ["b"])
self.assertEqual(spielplan.abzubauen_je_stufe(p, werte, bb, gehend={"b"}), [])
def test_abbau_ohne_zahl_leer(self):
self.assertEqual(spielplan.abzubauen_je_stufe(plan(), {"a": 1.0}, {"a": 0.02}), [])
class ServerBehaeltDieZahlen(unittest.TestCase):
def test_spielplan_ohne_feld_behaelt_stufen_tische(self):
import steuern
with tempfile.TemporaryDirectory() as d:
pfad = os.path.join(d, "spielplan.json")
alt = steuern.SPIELPLAN
steuern.SPIELPLAN = pfad
try:
spielplan.schreiben(pfad, plan(stufen_tische={"cash": {"0.02": 6}}))
steuern.spielplan_setzen({"modus": "cash", "tische": 12, "stufen": {"cash": [0.02]}})
self.assertEqual(spielplan.stufen_tische_von(spielplan.lesen(pfad)), {0.02: 6})
steuern.spielplan_setzen({"modus": "cash", "tische": 12, "stufen_tische": {"cash": {}}})
self.assertEqual(spielplan.stufen_tische_von(spielplan.lesen(pfad)), {})
finally:
steuern.SPIELPLAN = alt
if __name__ == "__main__":
unittest.main()
+18 -3
View File
@@ -19,8 +19,8 @@ for _p in ("betrieb", "lesen", "hand", "lobby", "client"):
from spielplan import Spielplan # noqa: E402
def lage(sitz=1, turnier=False):
return types.SimpleNamespace(held_sitz=sitz, turnier=turnier)
def lage(sitz=1, turnier=False, bb=0.02):
return types.SimpleNamespace(held_sitz=sitz, turnier=turnier, bb=bb)
class Abbau(unittest.TestCase):
@@ -38,7 +38,8 @@ class Abbau(unittest.TestCase):
runner.tischwahl_bewerten = bewerten
runner.act = types.SimpleNamespace(gestoppt=lambda: False)
runner.sitzen = types.SimpleNamespace(turniertisch=lambda l: l.turnier)
self.s = types.SimpleNamespace(text="", abgang={}, zahl_abbau={}, klicken=True, auslauf=False)
self.s = types.SimpleNamespace(text="", abgang={}, zahl_abbau={}, klicken=True, auslauf=False,
nur_offene=False)
self.s._tischzahl_abbau = types.MethodType(runner.Sitzer._tischzahl_abbau, self.s)
def tische(self):
@@ -65,6 +66,20 @@ class Abbau(unittest.TestCase):
self.s._tischzahl_abbau(Spielplan("cash", 1), self.tische())
self.assertEqual(self.s.zahl_abbau, {})
def test_je_stufe_gesenkt(self):
# Gesamt reicht (16), aber NL2 ist auf 1 gesenkt: die schwaecheren NL2-Tische gehen, NL5 bleibt
import spielplan
p = spielplan.aus_dict({"modus": "cash", "tische": 16, "stufen_tische": {"cash": {"0.02": 1}}})
tische = [("A", lage()), ("B", lage()), ("C", lage(bb=0.05)), ("D", lage())]
self.s._tischzahl_abbau(p, tische)
self.assertEqual(self.s.zahl_abbau, {"B": -3.0, "D": 5.0})
def test_je_stufe_ohne_zahl_liest_nichts(self):
import spielplan
p = spielplan.aus_dict({"modus": "cash", "tische": 16})
self.s._tischzahl_abbau(p, self.tische())
self.assertEqual((self.s.zahl_abbau, self.gelesen), ({}, []))
if __name__ == "__main__":
unittest.main()
+28
View File
@@ -84,6 +84,18 @@ public sealed class Spielplan
private Dictionary<string, List<double>> _stufen = new();
public IReadOnlyList<double> Stufen => _stufen.TryGetValue(Cash ? "cash" : "uebung", out var r) ? r : Array.Empty<double>();
public void StufenSetzen(List<double> reihe) => _stufen[Cash ? "cash" : "uebung"] = reihe.Distinct().ToList();
/// <summary>Tische je Stufe (Owner 26.11.: "10 NL2 + 4 NL5" statt die Stufe nur an/aus); fehlt: frei.</summary>
private Dictionary<string, Dictionary<double, int>> _stufenTische = new();
public int? TischeJeStufe(double bb) =>
_stufenTische.TryGetValue(Cash ? "cash" : "uebung", out var je) && je.TryGetValue(bb, out var n) ? n : null;
public void TischeJeStufeSetzen(double bb, int? n)
{
var m = Cash ? "cash" : "uebung";
if (!_stufenTische.TryGetValue(m, out var je)) _stufenTische[m] = je = new();
if (n is int z) je[bb] = Math.Max(0, Math.Min(z, Hoechstens));
else je.Remove(bb);
}
public Tischform Tischform = Tischform.Multiway;
public JsonObject? Zeitplan, Geld, Turnier;
@@ -201,6 +213,13 @@ public sealed class Spielplan
foreach (var m in new[] { "cash", "uebung" })
if (o.Obj("stufen")?[m] is JsonArray reihe)
p._stufen[m] = reihe.Select(x => x is JsonValue v && v.TryGetValue<double>(out var b) ? b : 0).Where(b => b > 0 || b is >= -4 and <= -1).ToList();
foreach (var m in new[] { "cash", "uebung" })
if (o.Obj("stufen_tische")?[m] is JsonObject je)
p._stufenTische[m] = je.Where(kv => double.TryParse(kv.Key, System.Globalization.NumberStyles.Float,
System.Globalization.CultureInfo.InvariantCulture, out var b) && b > 0
&& kv.Value is JsonValue v && v.TryGetValue<double>(out _))
.ToDictionary(kv => double.Parse(kv.Key, System.Globalization.CultureInfo.InvariantCulture),
kv => (int)kv.Value!.GetValue<double>());
p.Tischform = o.Text("tischform") switch
{
"hu" => Tischform.Hu,
@@ -281,6 +300,15 @@ public sealed class Spielplan
var st = new JsonObject();
foreach (var (m, r) in _stufen) st[m] = new JsonArray(r.Select(b => (JsonNode?)JsonValue.Create(b)).ToArray());
d["stufen"] = st;
// ebenso immer: leer heisst "keine Stufe begrenzt" (fehlt es, behaelt der Server die alten Zahlen)
var stt = new JsonObject();
foreach (var (m, je) in _stufenTische)
{
var o = new JsonObject();
foreach (var (sb, n) in je) o[sb.ToString(System.Globalization.CultureInfo.InvariantCulture)] = n;
stt[m] = o;
}
d["stufen_tische"] = stt;
if (Turnier != null) d["turnier"] = Turnier.DeepClone();
d["tischform"] = Tischform switch { Tischform.Hu => "hu", Tischform.Beide => "beide", _ => "multiway" };
if (Zeitplan is { Count: > 0 }) d["zeitplan"] = Zeitplan.DeepClone();
+42 -2
View File
@@ -22,6 +22,8 @@ public sealed class StufenTeil : UserControl
private readonly TextBlock _fuss = Ui.Winzig("");
private readonly StufenPrio _prio;
private readonly Grid _knoepfe = new() { ColumnSpacing = 6, RowSpacing = 6 };
/// <summary>Je gewaehlter Cash-Stufe "NL2 · Tische − 10 +" (Owner 26.11.); Knoepfe statt Feld: kein Fokus, wirkt live.</summary>
private readonly StackPanel _zahlen = new() { Spacing = 4 };
private readonly DropDownButton _ordnung = new()
{
Content = "Reihenfolge", FontSize = 12, Padding = new Thickness(10, 3, 8, 4), MinHeight = 0,
@@ -45,7 +47,7 @@ public sealed class StufenTeil : UserControl
fuss.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto });
fuss.Children.Add(_fuss);
fuss.Children.Add(_ordnung.Spalte(1));
Content = Ui.Spalte(8, _knoepfe, fuss).Mit(s => s.Padding = new Thickness(10));
Content = Ui.Spalte(8, _knoepfe, _zahlen, fuss).Mit(s => s.Padding = new Thickness(10));
}
/// <summary>`stufen`: kopf.stufen vom Server; fehlt es (aelterer Server), bleibt der Teil unsichtbar.</summary>
@@ -56,7 +58,7 @@ public sealed class StufenTeil : UserControl
if (s is null) return;
var liste = s.Objekte("stufen").ToList();
var reihe = w.Stufen.ToList();
var abdruck = $"{w.Cash}|{laeuft}|{_alle}|{string.Join(",", reihe)}|{s.Obj("turnier")?.T("zeile")}|" + string.Join(",", liste.Select(x => $"{x.Zahl("bb")}:{x.T("text")}:{x.Zahl("offen")}:{x.Zahl("sitzt")}"));
var abdruck = $"{w.Cash}|{laeuft}|{_alle}|{string.Join(",", reihe)}|{string.Join(",", reihe.Select(b => w.TischeJeStufe(b)))}|{s.Obj("turnier")?.T("zeile")}|" + string.Join(",", liste.Select(x => $"{x.Zahl("bb")}:{x.T("text")}:{x.Zahl("offen")}:{x.Zahl("sitzt")}"));
if (abdruck == _abdruck) return;
_abdruck = abdruck;
string Name(double b) => liste.FirstOrDefault(x => x.Zahl("bb") == b)?.T("name") ?? $"{b:0.##}";
@@ -70,6 +72,7 @@ public sealed class StufenTeil : UserControl
_ordnung.Visibility = reihe.Count > 1 ? Visibility.Visible : Visibility.Collapsed;
string Text(JsonObject x) => (laeuft && x.Zahl("offen") is double n && n > 0 ? $"{n:0} offen" + (x.Zahl("sitzt") is double si && si < n ? $", {n - si:0} warten" : "") + " · " : "") + x.T("text");
_prio.Malen(liste, reihe, Text, Geht);
Zahlen(liste, reihe, Name, w);
var turniere = liste.Where(x => x.Wahr("turnier")).ToList();
var geld = liste.Where(x => !x.Wahr("turnier")).ToList();
@@ -117,6 +120,43 @@ public sealed class StufenTeil : UserControl
_knoepfe.Children.Add(regel);
}
private void Zahlen(List<JsonObject> liste, List<double> reihe, Func<double, string> name, Spielplan w)
{
_zahlen.Children.Clear();
var geld = reihe.Where(b => b > 0).ToList();
if (geld.Count == 0) return;
_zahlen.Children.Add(Ui.Winzig("Tische je Stufe – frei: so viele, wie die Gesamtzahl hergibt"));
foreach (var bb in geld)
{
var n = w.TischeJeStufe(bb);
var offen = (int)(liste.FirstOrDefault(x => x.Zahl("bb") == bb)?.Zahl("offen") ?? 0);
void Setzen(int? neu) => _z.Eingabe(p => p.TischeJeStufeSetzen(bb, neu));
// aus "frei" heraus beginnt die Zahl bei den Tischen, die dort gerade offen sind
int Basis() => n ?? Math.Max(offen, 1);
var zeile = new Grid { ColumnSpacing = 6 };
zeile.ColumnDefinitions.Add(new ColumnDefinition());
for (var i = 0; i < 4; i++) zeile.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto });
zeile.Children.Add(Ui.Text(name(bb), 13, fett: true).Mit(t => t.VerticalAlignment = VerticalAlignment.Center));
zeile.Children.Add(Klein("−", () => Setzen(Math.Max(0, Basis() - (n is null ? 0 : 1))), $"{name(bb)}: ein Tisch weniger").Spalte(1));
zeile.Children.Add(Ui.Text(n is int z ? $"{z}" : "frei", 13, fett: n is not null,
pinsel: n is null ? Ui.Zweit : null)
.Mit(t => { t.MinWidth = 34; t.TextAlignment = TextAlignment.Center; t.VerticalAlignment = VerticalAlignment.Center; }).Spalte(2));
zeile.Children.Add(Klein("+", () => Setzen(Basis() + (n is null ? 0 : 1)), $"{name(bb)}: ein Tisch mehr").Spalte(3));
var frei = Klein("frei", () => Setzen(null), $"{name(bb)}: keine eigene Zahl").Spalte(4);
frei.Visibility = n is null ? Visibility.Collapsed : Visibility.Visible;
zeile.Children.Add(frei);
_zahlen.Children.Add(zeile);
}
}
private static Button Klein(string text, Action tun, string hilfe)
{
var b = new Button { Content = text, MinWidth = 32, Padding = new Thickness(8, 2, 8, 3), FontSize = 13, IsTabStop = false };
b.Click += (_, _) => tun();
ToolTipService.SetToolTip(b, hilfe);
return b;
}
private Tippflaeche Knopf(JsonObject x, List<double> reihe, bool geht, string text, Spielplan w)
{
var bb = x.Zahl("bb") ?? 0;