librarylib/TTTML.xtl
ˡlines : Int
ˡlines ← 8 9 r̲eshape 1 1 1 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0 1 1 1 1 0 0 1 0 0 1 0 0 0 1 0 0 1 0 0 1 0 0 0 1 0 0 1 0 0 1 1 0 0 0 1 0 0 0 1 0 0 1 0 1 0 1 0 0
Used in: ˡo̲utcome
ˡo̲utcome : Num a => Int -> a
ˡo̲utcome ← { s → l ← ˡlines '+ '× i̲nner s 3 m̲ember? l ? 1◆ -3 m̲ember? l ? -1◆ 0 m̲ember? s ? 0◆ 2 }
ˡsymmetries : Int
ˡsymmetries ← 8 9 r̲eshape 1 2 3 4 5 6 7 8 9 7 4 1 8 5 2 9 6 3 9 8 7 6 5 4 3 2 1 3 6 9 2 5 8 1 4 7 3 2 1 6 5 4 9 8 7 7 8 9 4 5 6 1 2 3 1 4 7 2 5 8 3 6 9 9 6 3 8 5 2 7 4 1
Used in: ˡc̲ode
ˡv̲alues : Float -> Float -> Float
ˡv̲alues ← { m c → ((1 s̲elect m) i̲ndexOf c) s̲elect (2 s̲elect m) c̲at 0.5 }
ˡa̲fter : (Num a, Truthy a) => a -> Int -> a
ˡa̲fter ← { s a → s + (1 − 2 × '+ r̲/ s) × (r̲ange 9) = a }
ˡc̲hoose : (Num a, Truthy a) => Float -> a -> Int
ˡc̲hoose ← { m s → p ← w̲here s = 0 v ← m ˡv̲alues '{ a → f̲loat ˡc̲ode s ˡa̲fter a } e̲ach p (v i̲ndexOf 'm̲ax r̲/ v) s̲elect p }
p̲ick! : (Num a, Truthy a) => Float -> a -> Int
p̲ick! ← { m s → p ← w̲here s = 0 (r̲oll! 10) = 1 ? (r̲oll! t̲ally p) s̲elect p◆ m ˡc̲hoose s }
Used in: p̲lay!
p̲lay! : Float -> Int -> Int
p̲lay! ← { m g → s ← (t̲ally g) s̲elect g g ← g c̲at 1 9 r̲eshape s ˡa̲fter m p̲ick! s 0 = ˡo̲utcome (t̲ally g) s̲elect g ? m p̲lay! g◆ g }
r̲esult : Int -> Int -> Float
r̲esult ← { g j → w ← ˡo̲utcome (t̲ally g) s̲elect g x ← '+ r̲/ (j + 1) s̲elect g (0.5 × f̲loat w = 2) + f̲loat w = (2 × x) − 1 }
Used in: t̲arget
t̲arget : Int -> Float -> Int -> Float
t̲arget ← { g m j → j ≥ (t̲ally g) − 2 ? g r̲esult j◆ 0.9 × m ˡv̲alue (j + 3) s̲elect g }
Used in: b̲ack
b̲ack : Int -> Float -> Int -> Float
b̲ack ← { g m j → k ← (1 s̲elect m) i̲ndexOf f̲loat ˡc̲ode (j + 1) s̲elect g d ← 0.2 × ((g t̲arget m)_ j) − m ˡv̲alue (j + 1) s̲elect g m ← m + (0.0 c̲at d) '× t̲able f̲loat (r̲ange t̲ally 1 s̲elect m) = k j = 1 ? m◆ (g b̲ack m)_ j − 1 }
m̲eet : Num a => Float -> a -> Float
m̲eet ← { m g → c ← u̲nique '{ j → f̲loat ˡc̲ode j s̲elect g } e̲ach 1 d̲rop r̲ange t̲ally g n ← (w̲here 0 = c m̲ember? 1 s̲elect m) s̲elect c k ← (t̲ally 1 s̲elect m) + t̲ally n (2 c̲at k) r̲eshape ((1 s̲elect m) c̲at n) c̲at (2 s̲elect m) c̲at 0.5 + 0.0 × n }
Used in: ˡl̲earn
ˡl̲earn : Float -> Int -> Float
ˡl̲earn ← { m g → (g b̲ack m m̲eet g)_ (t̲ally g) − 1 }
Used in: r̲ound!
l̲oop! : Int -> Float -> Float
l̲oop! ← { n m → k ← 250 m̲in n m ← k 'r̲ound! p̲ower m shown ← p̲rint! (n − k) c̲at t̲ally 1 s̲elect m n = k ? m◆ (n − k) l̲oop! m }
ˡt̲rain! : Int -> Float -> Float
ˡt̲rain! ← { n m → shown ← p̲rint! "games to go, positions known:" n l̲oop! m }
t̲urn! : (Num a, Truthy a) => Float -> a -> a -> Int
t̲urn! ← { m side s → p ← w̲here s = 0 (1 − 2 × '+ r̲/ s) = side ? m ˡc̲hoose s◆ (r̲oll! t̲ally p) s̲elect p }
Used in: v̲ersus!
v̲ersus! : Num a => Float -> Int -> Int -> a
v̲ersus! ← { m side s → s ← s ˡa̲fter ((m t̲urn! side)_ s) w ← ˡo̲utcome s w = 0 ? ((m v̲ersus! side)_ s)◆ w }
c̲ount! : (Num a, Truthy a) => Float -> Int -> Int -> a
c̲ount! ← { m side n → w ← '{ i → ((m v̲ersus! side)_ 9 r̲eshape 0) } e̲ach r̲ange n '+ r̲/ w '= t̲able side c̲at (0 − side) c̲at 2 }
Used in: ˡt̲rial!
ˡt̲rial! : (Num a, Truthy a) => Int -> Float -> a
ˡt̲rial! ← { n m → 2 3 r̲eshape ((m c̲ount! 1)_ n) c̲at (m c̲ount! -1)_ n }
g̲reedy : Float -> Int -> Int
g̲reedy ← { m g → s ← (t̲ally g) s̲elect g g ← g c̲at 1 9 r̲eshape s ˡa̲fter m ˡc̲hoose s 0 = ˡo̲utcome (t̲ally g) s̲elect g ? m g̲reedy g◆ g }
ˡb̲oards : Int -> Char
ˡb̲oards ← { g → k ← t̲ally g rows ← (3 × (r̲ange 3) − 1) '+ t̲able 9 × (r̲ange k) − 1 at ← (1 + 9 × k) m̲in rows '+ t̲able 1 2 3 99 squares ← at s̲elect (r̲avel g) c̲at 3 (3 c̲at 8 × k) r̲eshape (1 + (squares + 2) '× t̲able 0 1) s̲elect " O.X " }