-
Notifications
You must be signed in to change notification settings - Fork 0
/
uctopt
executable file
·104 lines (96 loc) · 2.18 KB
/
uctopt
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/usr/bin/env coffee
fs = require 'fs'
match = require './match.coffee'
{ SCORE_MULT } = require './pattern'
{ LOG_MULT } = require './logutil'
argv = require 'yargs'
.options
m:
alias: 'min'
desc: 'Minimum value to search'
default: 0
type: 'number'
requiresArg: true
M:
alias: 'max'
desc: 'Maximum value to search'
default: 4
type: 'number'
requiresArg: true
p:
alias: 'precision'
desc: 'Search precision'
default: 0.01
type: 'number'
requiresArg: true
s:
alias: 'search'
desc: 'Number of UCT search of match'
default: match.defaults.search
w:
alias: 'wld'
desc: 'WLD search depth'
default: match.defaults.wld
f:
alias: 'full'
desc: 'Full search depth'
default: match.defaults.full
d:
alias: 'depth'
desc: 'Minimax maximum search depth'
default: match.defaults.depth
l:
alias: 'leafs'
desc: 'Minimax maximum search nodes'
default: match.defaults.leafs
weights:
desc: 'Weights file'
default: 'weights.json'
requiresArg: true
h:
alias: 'help'
.strict()
.version false
.argv
try_value = (value, max) ->
process.stdout.write "C=#{value}: "
{ winrate, avg } = match
C: value * SCORE_MULT
C_log: value * LOG_MULT
weights: argv.weights
ref: argv.weights
search: argv.search
wld: argv.wld
full: argv.full
quiet: true
minimax: true
depth: argv.depth
leafs: argv.leafs
score = winrate + avg * 0.0001
process.stdout.write "score=#{Math.round(score*10000)/10000}"
if score > max
process.stdout.write ' *\n'
else
process.stdout.write '\n'
score
optimize = () ->
step = (argv.max - argv.min) / 4
best = (argv.min + argv.max) / 2
max = try_value(best, -Infinity)
loop
tmp = best + step
score = try_value(tmp, max)
if score > max
max = score
best = tmp
else
tmp = best - step
score = try_value(tmp, max)
if score > max
max = score
best = tmp
break if step < argv.precision
step *= .5
console.log "Best value #{best}"
do ->
optimize()