-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdead_monkey.go
More file actions
57 lines (53 loc) · 1.15 KB
/
dead_monkey.go
File metadata and controls
57 lines (53 loc) · 1.15 KB
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
package n
// DeadMonkey 跳出三界外 不在五行中
// Jump out of the sky
// Not in the N universe
type DeadMonkey struct {
N uint
EarthLocation *EarthLocation
Three *Three
Four *Four
//todo:按需扩容
//n的维度天知道
}
func NewDeadMonkeyFromEarth(l EarthLocation) *DeadMonkey {
return &DeadMonkey{
EarthLocation: &l,
N: 3,
}
}
func NewDeadMonkeyFrom3(th Three) *DeadMonkey {
return &DeadMonkey{
Three: &th,
N: 3,
}
}
func NewDeadMonkeyFrom4(four Four) *DeadMonkey {
dm := &DeadMonkey{
Four: &four,
N: 4,
}
return dm
}
// EatBanana 吃香蕉,运用gay佬的香蕉算法,计算N维空间中2点距离
func (dm DeadMonkey) EatBanana(sixMonkey *DeadMonkey) Distance {
//判断当前维度
d := Distance{}
if sixMonkey.Four != nil {
d.Duration = sixMonkey.Four.Time.Sub(dm.Four.Time)
}
if dm.N == 0 {
return Distance{} //zero
}
if dm.N <= 3 && dm.Three != nil {
d := dm.Three.Distance(sixMonkey.Three)
return d
}
if dm.N <= 3 && dm.EarthLocation != nil {
d := dm.EarthLocation.GetEarthDistance(sixMonkey.EarthLocation)
return d
}
// if dm.N >= 4 {
// }
return d
}