-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest_engine.go
130 lines (104 loc) · 1.97 KB
/
test_engine.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
124
125
126
127
128
129
130
package main
import (
"cryptobact/engine"
"fmt"
"log"
"os"
)
type Updater struct{}
func (f Updater) Update(w *engine.World) {
DrawMap(w.Snapshot())
}
func DrawMap(w *engine.World) {
return
maxCol := 40
maxRow := 40
startX := -10
endX := 10
startY := -10
endY := 10
stepX := float64(endX-startX) / float64(maxCol)
stepY := float64(endY-startY) / float64(maxRow)
fmt.Printf("\n\nTICK: %d\n", w.Tick)
fmt.Printf("RANGE: X[%d, %d] Y[%d, %d]\n", startX, endX, startY, endY)
for y := 0; y < maxRow; y++ {
for x := 0; x < maxCol; x++ {
printed := false
for _, p := range w.Populations {
if printed {
break
}
for _, b := range p.Bacts {
if !between(b.X, b.Y, stepX, stepY, x, y) {
continue
}
if b.Born {
// 70
// 7 0
// 6 1
// 5 2
// 43
fmt.Printf("%c", "01234566"[int(b.Angle)/45])
} else {
fmt.Print("o")
}
printed = true
break
}
}
if printed {
continue
}
for _, f := range w.Food {
if !between(f.X, f.Y, stepX, stepY, x, y) {
continue
}
fmt.Print("F")
printed = true
break
}
for _, a := range w.Acid {
if !between(a.X, a.Y, stepX, stepY, x, y) {
continue
}
fmt.Print("A")
printed = true
break
}
for _, c := range w.Clot {
if !between(c.X, c.Y, stepX, stepY, x, y) {
continue
}
fmt.Print("C")
printed = true
break
}
if !printed {
fmt.Print(".")
}
}
fmt.Println()
}
}
func between(x float64, y float64, stepX float64, stepY float64, i int, j int) bool {
if float64(j-1)*stepY >= y {
return false
}
if float64(j)*stepY <= y {
return false
}
if float64(i-1)*stepX >= x {
return false
}
if float64(i)*stepX <= x {
return false
}
return true
}
func main() {
f, _ := os.OpenFile("bact.log", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
log.SetOutput(f)
log.Println("testing engine")
u := Updater{}
engine.Loop(u)
}