forked from paulhankin/cpoker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplay_test.go
executable file
·61 lines (56 loc) · 1.46 KB
/
play_test.go
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
package cpoker
import (
"fmt"
"math/rand"
"runtime"
"testing"
"time"
"github.com/paulhankin/poker/v2/poker"
)
func BenchmarkPlayProd(b *testing.B) {
cards := append([]poker.Card{}, poker.Cards...)
he := MaxProdEvaluator{}
for count := 0; count < b.N; count++ {
for i := 0; i < 13; i++ {
j := rand.Intn(52-i) + i
cards[i], cards[j] = cards[j], cards[i]
}
h, max := Play(cards[:13], he)
//fmt.Printf("%v: %#v\n", h, max)
_, _ = h, max
}
}
func BenchmarkPlayRollout(b *testing.B) {
runtime.GOMAXPROCS(8)
cards := append([]poker.Card{}, poker.Cards...)
he := &RolloutEvaluator{
Opponent: MaxProdEvaluator{},
N: 10000,
}
for count := 0; count < b.N; count++ {
for i := 0; i < 13; i++ {
j := rand.Intn(52-i) + i
cards[i], cards[j] = cards[j], cards[i]
}
h, max := Play(cards[:13], he)
//fmt.Printf("%v: %#v\n", h, max)
_, _ = h, max
}
}
func BenchmarkPlayComparison(b *testing.B) {
runtime.GOMAXPROCS(4)
rand.Seed(time.Now().UTC().UnixNano())
var hero, villain HandEvaluator
hero = MaxProdEvaluator{}
for iterations := 0; iterations < 10; iterations++ {
hero, villain = NewTrainedSampledEvaluator(hero, 1000), hero
b.Log("iteration", iterations)
}
b.Log("preparing rollout evaluator")
re := &RolloutEvaluator{PreRollout: true, Separable: true, Opponent: hero, N: 20000}
re.Init()
b.Log("running comparison")
hero, villain = re, hero
comparison := CompareEvaluators(hero, villain, 1000, 500)
fmt.Println(comparison)
}