feat: Cards writings and balancing (M8)

This commit is contained in:
gauvainboiche
2026-10-25 18:30:43 +01:00
parent 04193e2013
commit c2103c32e7
43 changed files with 25930 additions and 397 deletions
+18 -3
View File
@@ -114,7 +114,10 @@ func (c *cardChecker) conditions(id string, cond obj) {
for _, bound := range []string{"min", "max"} {
m, _ := cond[bound].(obj)
for k, v := range m {
okKey := c.condStats[k] || (strings.HasPrefix(k, "q:") && c.sectors[strings.TrimPrefix(k, "q:")])
okKey := c.condStats[k] ||
(strings.HasPrefix(k, "q:") && c.sectors[strings.TrimPrefix(k, "q:")]) ||
(strings.HasPrefix(k, "ratio:") && c.sectors[strings.TrimPrefix(k, "ratio:")]) ||
(strings.HasPrefix(k, "tax:") && c.revenues[strings.TrimPrefix(k, "tax:")] && k != "tax:other")
if !okKey {
t.Errorf("%s.conditions.%s: unknown stat %q", id, bound, k)
}
@@ -200,6 +203,7 @@ func TestCards(t *testing.T) {
followOnly := map[string]bool{}
total := 0
perCategory := map[string]int{}
for _, f := range index["files"].([]any) {
file := f.(string)
raw, err := web.Files.ReadFile("data/cards/" + file)
@@ -220,6 +224,7 @@ func TestCards(t *testing.T) {
continue
}
total++
perCategory[stem]++
if c.ids[id] {
t.Errorf("duplicate card id %s", id)
}
@@ -281,7 +286,17 @@ func TestCards(t *testing.T) {
t.Errorf("%s: flag %q is used in conditions but never set by any card", by, fl)
}
}
if total < 60 {
t.Errorf("only %d cards; M4 expects at least 60", total)
if total < 800 {
t.Errorf("only %d cards; M7 expects at least 800", total)
}
minPerCategory := map[string]int{
"economy": 90, "social": 60, "health": 55, "education": 55, "security": 60, "defense": 55,
"foreign": 60, "industry": 60, "transport": 55, "housing": 35, "environment": 45,
"justice": 55, "culture": 35, "crises": 45,
}
for cat, min := range minPerCategory {
if perCategory[cat] < min {
t.Errorf("category %s has %d cards; M7 expects at least %d", cat, perCategory[cat], min)
}
}
}