-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplayer.go
123 lines (100 loc) · 1.9 KB
/
player.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
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
package eoc
import (
"fmt"
"math/rand"
)
type Player interface {
PlayWith(p Player) bool
JoinArena(a *Arena)
ID() int64
Name() string
ReceiveMatchResult(playerID int64, coop bool)
}
type PlayerA struct {
id int64
memory map[int64][]bool
}
type Random struct {
id int64
}
func (p *Random) ID() int64 {
return p.id
}
func (p *Random) JoinArena(a *Arena) {
p.id = a.NewPlayerID()
}
func (p *Random) Name() string {
return fmt.Sprintf("random_%d", p.ID())
}
func (p *Random) PlayWith(p2 Player) bool {
if rand.Intn(10) > 5 {
return true
}
return false
}
func (p *Random) ReceiveMatchResult(playerID int64, coop bool) {
return
}
// Fish has no memory, always coop/betray
type Fish struct {
id int64
coop bool
}
func NewFish(coop bool) *Fish {
return &Fish{
coop: coop,
}
}
func (p *Fish) PlayWith(p2 Player) bool {
return p.coop
}
func (p *Fish) JoinArena(a *Arena) {
p.id = a.NewPlayerID()
}
func (p *Fish) ID() int64 {
return p.id
}
func (p *Fish) Name() string {
position := "bad"
if p.coop {
position = "good"
}
return fmt.Sprintf("fish_%s_%d", position, p.ID())
}
func (p *Fish) ReceiveMatchResult(playerID int64, coop bool) {
return
}
type Tic4Tac struct {
id int64
memory map[int64][]bool
}
func NewTic4TacPlayer() *Tic4Tac {
return &Tic4Tac{
memory: make(map[int64][]bool),
}
}
func (p *Tic4Tac) ID() int64 {
return p.id
}
func (p *Tic4Tac) Name() string {
return fmt.Sprintf("tic4tac_%d", p.ID())
}
func (p *Tic4Tac) PlayWith(p2 Player) bool {
if hist, ok := p.memory[p2.ID()]; ok == true {
if len(hist) > 0 {
if !hist[len(hist)-1] {
return false
}
}
}
return true
}
func (p *Tic4Tac) ReceiveMatchResult(playerID int64, coop bool) {
if _, ok := p.memory[playerID]; ok == false {
p.memory[playerID] = make([]bool, 0)
}
p.memory[playerID] = append(p.memory[playerID], coop)
}
func (p *Tic4Tac) JoinArena(a *Arena) {
p.id = a.NewPlayerID()
}