librarylib/TTTML.xtl

source

ˡs̲how : Int -> Char

function · line 13
ˡs̲how ← { s → 3 6 r̲eshape (1 + (s + 2) '× t̲able 0 1) s̲elect " O.X" }
Used in: ᵘy̲ou, ᵘm̲e

ˡlines : Int

value · line 17
ˡ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

function · line 21
ˡ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

value · line 29
ˡ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

ˡc̲ode : Num a => a -> a

function · line 30
ˡc̲ode ← { s → 'm̲in r̲/ 3 d̲ecode o̲\ 1 + ˡsymmetries s̲elect s }

ˡempty : Float

value · line 33
ˡempty ← 2 0 r̲eshape 0.5

ˡv̲alues : Float -> Float -> Float

function · line 39
ˡv̲alues ← { m c → ((1 s̲elect m) i̲ndexOf c) s̲elect (2 s̲elect m) c̲at 0.5 }

ˡv̲alue : Num a => Float -> a -> Float

function · line 40
ˡv̲alue ← { m s → m ˡv̲alues f̲loat ˡc̲ode s }
Used in: t̲arget, b̲ack

ˡa̲fter : (Num a, Truthy a) => a -> Int -> a

function · line 43
ˡa̲fter ← { s a → s + (1 − 2 × '+ r̲/ s) × (r̲ange 9) = a }

ˡc̲hoose : (Num a, Truthy a) => Float -> a -> Int

function · line 46
ˡ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

function (private) · line 55
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

function (private) · line 59
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
}
Used in: p̲lay!, ˡg̲ame!

ˡg̲ame! : Float -> Int

function · line 64
ˡg̲ame! ← { m → m p̲lay! 1 9 r̲eshape 0 }
Used in: r̲ound!

r̲esult : Int -> Int -> Float

function (private) · line 71
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

function (private) · line 76
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

function (private) · line 79
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
}
Used in: b̲ack, ˡl̲earn

m̲eet : Num a => Float -> a -> Float

function (private) · line 86
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

function · line 92
ˡl̲earn ← { m g → (g b̲ack m m̲eet g)_ (t̲ally g) − 1 }
Used in: r̲ound!

r̲ound! : Float -> Float

function (private) · line 100
r̲ound! ← { m → m ˡl̲earn ˡg̲ame! m }
Used in: l̲oop!

l̲oop! : Int -> Float -> Float

function (private) · line 101
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

function · line 107
ˡ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

function (private) · line 115
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

function (private) · line 119
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

function (private) · line 124
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

function · line 130
ˡ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

function (private) · line 134
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̲est : Float -> Int

function · line 139
ˡb̲est ← { m → m g̲reedy 1 9 r̲eshape 0 }

ˡb̲oards : Int -> Char

function · line 142
ˡ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  "
}

o̲pening! : (Num a, Truthy a) => Unit -> a

function (private) · line 154
o̲pening! ← { @ → 2 9 r̲eshape (9 r̲eshape 0) c̲at 1 × (r̲ange 9) = r̲oll! 9 }

f̲inal : Num a => Int -> a

function (private) · line 155
f̲inal ← { g → ˡo̲utcome (t̲ally g) s̲elect g }

ˡs̲elfTrial! : (Num a, Truthy a) => Int -> Float -> a

function · line 156
ˡs̲elfTrial! ← { n m →
  w ← '{ i → f̲inal m g̲reedy o̲pening! @ } e̲ach r̲ange n
  '+ r̲/ w '= t̲able 1 -1 2
}