sourcedemos/tttml-train.xtl
1⍝!/usr/bin/env xetal
2⍝# TTTML, part 1: learn tic-tac-toe by playing itself, then save what
3⍝# it learned to work/tttml.model, a text file of numbers (the codes of
4⍝# the positions it met, then their values). Run it with
5⍝# "xetal run demos/tttml-train.xtl"; part 2, demos/tttml-play.xtl, loads
6⍝# the model and plays you. Uses the TTTML library (lib/TTTML.xtl).
7
8ᵗ⁼u̲se< "TTTML"
9
10⍝# The model learned from 2000 games against itself.
11m ← 2000 ᵗt̲rain! ᵗempty
12
13⍝ Against a random player, as X and as O: won, lost, drawn.
1450 ᵗt̲rial! m
15
16⍝ Saved as text: f_ormat writes the model as it prints, and []N_PUT
17⍝ puts the text in a file, saying how many characters it wrote.
18(f̲ormat m) ⎕N̲PUT "work/tttml.model"