-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.fs
73 lines (64 loc) · 2.55 KB
/
Program.fs
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
namespace DeepKuhnPoker
open System
module Program =
let private infoSetKeys =
[|
"J"; "Q"; "K"; "Jcb"; "Qcb"; "Kcb" // player 0
"Jb"; "Jc"; "Qb"; "Qc"; "Kb"; "Kc" // player 1
|]
let run () =
// train the model
printfn "Running Kuhn Poker Deep CFR for %A iterations"
settings.NumIterations
let stratModel = Trainer.train ()
// examine resulting strategy
let strategyMap =
infoSetKeys
|> Seq.map (fun infoSetKey ->
let strategy =
(StrategyModel.getStrategy infoSetKey stratModel)
.data<float32>()
.ToArray()
infoSetKey, strategy)
|> Map
let betIdx = Array.IndexOf(KuhnPoker.actions, "b")
let lookup infoSetKey =
strategyMap[infoSetKey][betIdx]
let alpha = lookup "J"
printfn ""
printfn "Player 0"
printfn " J bet: %.3f (should be between 0 and 1/3)" alpha
printfn " Q bet: %.3f (should be 0)" (lookup "Q")
printfn " K bet: %.3f (should be %.3f)" (lookup "K") (3f * alpha)
printfn " Jcb bet: %.3f (should be 0)" (lookup "Jcb")
printfn " Qcb bet: %.3f (should be %.3f)" (lookup "Qcb") (alpha + 1.f/3.f)
printfn " Kcb bet: %.3f (should be 1)" (lookup "Kcb")
printfn ""
printfn "Player 1"
printfn " Jb bet: %.3f (should be 0)" (lookup "Jb")
printfn " Jc bet: %.3f (should be 1/3)" (lookup "Jc")
printfn " Qb bet: %.3f (should be 1/3)" (lookup "Qb")
printfn " Qc bet: %.3f (should be 0)" (lookup "Qc")
printfn " Kb bet: %.3f (should be 1)" (lookup "Kb")
printfn " Kc bet: %.3f (should be 1)" (lookup "Kc")
strategyMap
let runTournament strategyMap =
let player : Player =
let strategyMap =
Map.map (fun _ strat ->
MathNet.Numerics.LinearAlgebra
.DenseVector.ofArray strat)
strategyMap
fun infoSetKey ->
Vector.sample
settings.Random
strategyMap[infoSetKey]
Player.runTournament
[| player; Champion.player |]
1000000
let timer = Diagnostics.Stopwatch.StartNew()
let strategyMap = run ()
printfn ""
printfn $"Elapsed time: {timer}"
printfn ""
printfn $"Average payoff: {runTournament strategyMap}"