-
Notifications
You must be signed in to change notification settings - Fork 0
/
Player.fs
69 lines (56 loc) · 2.03 KB
/
Player.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
namespace DeepKuhnPoker
open MathNet.Numerics.LinearAlgebra
type Player = string (*info set*) -> int (*action*)
module Player =
let private play cards (players : Player[]) =
let rec loop history =
match KuhnPoker.getPayoff cards history with
| Some payoff -> payoff
| None ->
let playerIdx = history.Length % players.Length
let infoSetKey = cards[playerIdx] + history
let actionIdx = players[playerIdx] infoSetKey
let history = history + KuhnPoker.actions[actionIdx]
-(loop history)
loop ""
let private getPayoff players numGames =
Seq.init numGames (fun _ ->
let deal =
let iDeal =
settings.Random.Next(
KuhnPoker.allDeals.Length)
KuhnPoker.allDeals[iDeal]
play deal players)
|> Seq.sum
let runTournament players numGames =
let halfGames = numGames / 2
let payoffA = getPayoff players halfGames
let payoffB = -(getPayoff (Array.rev players) halfGames)
float (payoffA + payoffB) / (2. * float halfGames)
module Champion =
let player : Player =
let alpha = settings.Random.NextDouble() / 3.
let strategyMap =
[
"J", alpha
"Q", 0
"K", 3. * alpha
"Jb", 0
"Jc", 1./3.
"Qb", 1./3.
"Qc", 0
"Kb", 1
"Kc", 1
"Jcb", 0
"Qcb", alpha + 1./3.
"Kcb", 1
]
|> Seq.map (fun (infoSetKey, bet) ->
let strategy =
seq { bet; 1. - bet }
|> DenseVector.ofSeq
infoSetKey, strategy)
|> Map
fun infoSetKey ->
strategyMap[infoSetKey]
|> Vector.sample settings.Random