programdemos/tttml-play.xtl

source · imports t: lib/TTTML.xtl

v : Float

value · line 10
v ← n̲umbers ⎕N̲GET "work/tttml.model"
Used in: m

m : Float

value · line 11
m ← (2 c̲at (t̲ally v) d̲iv 2) r̲eshape v

ᵘa̲sk : Num a => a -> Int

function · line 15
ᵘa̲sk ← { s →
  shown ← p̲rint! "your move (1 to 9):"
  t ← ⎕R̲EAD @
  k ← "123456789" i̲ndexOf f̲irst t c̲at " "
  (k ≤ 9) ∧ 0 = k s̲elect s c̲at 1 ? k◆ ᵘa̲sk s
}
Used in: ᵘa̲sk, ᵘy̲ou

ᵘy̲ou : Int -> Int

function · line 23
ᵘy̲ou ← { s →
  s ← s ᵗa̲fter ᵘa̲sk s
  shown ← p̲rint! ᵗs̲how s
  gap ← p̲rint! ""
  0 = ᵗo̲utcome s ? ᵘm̲e s◆ s
}

ᵘm̲e : Int -> Int

function · line 29
ᵘm̲e ← { s →
  s ← s ᵗa̲fter m ᵗc̲hoose s
  shown ← p̲rint! ᵗs̲how s
  gap ← p̲rint! ""
  0 = ᵗo̲utcome s ? ᵘy̲ou s◆ s
}
Used in: ᵘy̲ou

ᵘv̲erdict : Num a => a -> Char

function · line 35
ᵘv̲erdict ← { w → w = 1 ? "you win"◆ w = -1 ? "it wins"◆ "a draw" }