forked from imrenagi/cloud-run-hackathon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
strategy_normal.go
43 lines (34 loc) · 1.02 KB
/
strategy_normal.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
package main
import "context"
// NewNormalStrategy attack normally, and immediately escape when it get hits
func NewNormalStrategy() *NormalStrategy {
return &NormalStrategy{}
}
type NormalStrategy struct {
}
func (ns *NormalStrategy) Play(ctx context.Context, p *Player) Move {
ctx, span := tracer.Start(ctx, "NormalStrategy.Play")
defer span.End()
if p.WasHit {
p.ChangeState(&Escape{Player: p})
} else {
p.ChangeState(ExploratoryAttack(p))
}
return p.State.Play(ctx)
}
// NewBraveStrategy attacks normally, but when it was hit, it tried to do counter attack
// TODO add counter for hit threshold until it needs to escape
func NewBraveStrategy() *BraveStrategy {
return &BraveStrategy{}
}
type BraveStrategy struct {}
func (ns *BraveStrategy) Play(ctx context.Context, p *Player) Move {
ctx, span := tracer.Start(ctx, "BraveStrategy.Play")
defer span.End()
if p.WasHit {
p.ChangeState(&BraveEscapeDecorator{Escaper: &Escape{Player: p}})
} else {
p.ChangeState(ExploratoryAttack(p))
}
return p.State.Play(ctx)
}