"""Exercise 15.1: the rotation of roles and question groups for three people (standard library only). Three people (甲, 乙, 丙) run three protocols: direct QA (judge alone), consultancy (one consultant and a judge) and debate (two debaters and a judge). Nine question groups G1..G9 are each used once. The script prints the six sessions and checks the constraints stated in the exercise: - every group is used exactly once; - nobody judges a group they have read (experts read the article of their own group only); - every person judges under every protocol exactly once; - the order in which a person meets the three protocols as judge forms a Latin square, so no protocol is always met first or last; - nobody has two roles in the same session; - every person is a consultant once and a debater twice. Stances (which side a debater or consultant defends) are NOT decided here: they are drawn per question by ch15_quality_select.py and written only into the experts' files. """ P = ["甲", "乙", "丙"] QA, CON, DEB = "直接问答", "单方咨询", "辩论" # each session: list of (protocol, group, judge, experts, unused); in sessions 2, 3 and 6 the # direct-QA judge works alone at another table while the consultancy runs sessions = [ [(DEB, "G1", "丙", ["甲", "乙"], None)], [(CON, "G2", "乙", ["丙"], None), (QA, "G3", "甲", [], None)], [(CON, "G4", "甲", ["乙"], None), (QA, "G5", "丙", [], None)], [(DEB, "G6", "乙", ["甲", "丙"], None)], [(DEB, "G7", "甲", ["乙", "丙"], None)], [(CON, "G8", "丙", ["甲"], None), (QA, "G9", "乙", [], None)], ] # ---- checks ---- groups = [g for s in sessions for (_, g, _, _, _) in s] assert sorted(groups) == [f"G{i}" for i in range(1, 10)], "each group exactly once" for s in sessions: busy = [] for proto, g, judge, experts, _ in s: assert judge not in experts, "judge never reads the group" need = {QA: 0, CON: 1, DEB: 2}[proto] assert len(experts) == need busy += [judge] + experts assert len(busy) == len(set(busy)), "one role per person per session" order = {p: [] for p in P} for s in sessions: for proto, _, judge, _, _ in s: order[judge].append(proto) for p in P: assert sorted(order[p]) == sorted([QA, CON, DEB]), "each person judges each protocol once" for pos in range(3): assert sorted(order[p][pos] for p in P) == sorted([QA, CON, DEB]), "Latin square" roles = {p: {"con": 0, "deb": 0} for p in P} for s in sessions: for proto, _, _, experts, _ in s: for e in experts: roles[e]["con" if proto == CON else "deb"] += 1 for p in P: assert roles[p] == {"con": 1, "deb": 2}, roles # ---- print ---- print("| 场次 | 协议 | 题组 | 裁判 | 辩手或咨询方 |") print("| --- | --- | --- | --- | --- |") for i, s in enumerate(sessions, 1): for proto, g, judge, experts, _ in s: ex = "、".join(experts) if experts else "(无)" print(f"| {i} | {proto} | {g} | {judge} | {ex} |") print() for p in P: print(f"{p} 当裁判的顺序:{' → '.join(order[p])}") print("all constraints hold")