-
Notifications
You must be signed in to change notification settings - Fork 6
/
test12
executable file
·69 lines (57 loc) · 1.69 KB
/
test12
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/env scheme-script
(import (rnrs)
(QobiScheme)
(stochastic-scheme)
(stochastic-promises)
(reduced-gradient)
(games4))
(define (tic-tac-toe-initial-state)
(make-state
'#(#(#f #f #f) #(#f #f #f) #(#f #f #f)) '#(x x x x x) '#(o o o o o) 'x))
(define (hexapawn-initial-state)
(make-state
'#(#(x x x) #(#f #f #f) #(o o o)) '#(#f #f #f #f #f) '#(#f #f #f #f #f) 'x))
(define (words) (remove-duplicates (map second *lexicon*)))
(define (word-mixture) (uniform (length (words))))
(define (word-draw mixture)
(delayed-draw (map cons (words) (vector->list mixture))))
(define (restn n l) (if (zero? n) l (restn (- n 1) (rest l))))
(define (word-distribution mixture)
(remove-if (lambda (pair) (zero? (cdr pair)))
(map cons (words) (vector->list mixture))))
(define (learn-tic-tac-toe-initial-state n)
(map-vector
word-distribution
(argmax
(lambda (mixtures)
(probability
(distribution
(initial-state?
(list
(append
(map-n (lambda (i) (word-draw (vector-ref mixtures i))) n)
(restn
n
'(every cache square for every player has some piece of that
player))))
(tic-tac-toe-initial-state)))))
(map-n-vector (lambda (i) (word-mixture)) n))))
(define (learn-tic-tac-toe-win1)
(argmax
(lambda (mixtures)
(probability
(distribution
(initial-state?
(list (map-n (lambda (i) (word-draw (vector-ref mixtures i))) 15))
(make-state
'#(#(x x x) #(#f #f #f) #(#f #f #f))
'#(x x x x x)
'#(o o o o o)
'x)))))
(map-n-vector (lambda (i) (word-mixture)) 15)))
(write
(learn-tic-tac-toe-initial-state (string->number (second (command-line)))))
(newline)
;;; Local Variables:
;;; eval: (scheme-mode)
;;; End: