-
Notifications
You must be signed in to change notification settings - Fork 4
/
state_attack.go
67 lines (55 loc) · 1.53 KB
/
state_attack.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
package main
import "context"
// DefaultAttack attack closest players
func DefaultAttack(p *Player) State {
return &Attack{
Player: p,
ExplorationStrategy: NewClosestDistanceExploration(p),
}
}
// ExploratoryAttack ...
func ExploratoryAttack(p *Player) State {
return &Attack{
Player: p,
ExplorationStrategy: NewWeightedExploration(p),
}
}
// TargetedAttack should attack in normal cases, but when exploring it tries to search for the target
func TargetedAttack(p *Player) State {
return &Attack{
Player: p,
ExplorationStrategy: &TargetedEnemy{},
}
}
type Attack struct {
Player *Player
ExplorationStrategy Explorer
}
func (a *Attack) Play(ctx context.Context) Move {
ctx, span := tracer.Start(ctx, "Attack.Play")
defer span.End()
front := a.Player.FindTargetOnDirection(ctx, a.Player.GetDirection())
if front != nil {
return Throw
}
left := a.Player.FindTargetOnDirection(ctx, a.Player.GetDirection().Left())
right := a.Player.FindTargetOnDirection(ctx, a.Player.GetDirection().Right())
if left != nil && right != nil {
if left.Score > right.Score {
return TurnLeft
} else {
return TurnRight
}
}
if left != nil {
// TODO check whether opponent is already targeting us
return TurnLeft
}
if right != nil {
// TODO check whether opponent is already targeting us
return TurnRight
}
// TODO attack should be able to use closest/targeted
// TODO attack sambil maju satu langkah biar lawan terjepit
return a.ExplorationStrategy.Explore(ctx, a.Player)
}