-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate-neighbors.go
74 lines (61 loc) · 1.25 KB
/
generate-neighbors.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
package main
import (
"fmt"
"os"
"strings"
)
func main() {
if err := run(); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}
const (
BoardWidth int = 32
BoardHeight int = 30
)
func run() error {
out, err := os.Create("neighbors.inc")
if err != nil {
return err
}
defer out.Close()
//out := io.MultiWriter(file, os.Stdout)
fmt.Fprintln(out, "NeighborBytes:")
for y := 0; y < BoardHeight; y++ {
fmt.Fprintf(out, "\n; row: %d\n", y)
for x := 0; x < BoardWidth; x++ {
neighborsX := []int{
x-1, x, x+1,
x-1, x+1,
x-1, x, x+1,
}
neighborsY := []int{
y-1, y-1, y-1,
y, y,
y+1, y+1, y+1,
}
for i := 0; i < 8; i++ {
if neighborsX[i] < 0 {
neighborsX[i] = BoardWidth-1
}
if neighborsY[i] < 0 {
neighborsY[i] = BoardHeight-1
}
if neighborsX[i] >= BoardWidth {
neighborsX[i] = 0
}
if neighborsY[i] >= BoardHeight {
neighborsY[i] = 0
}
}
current := (y*(BoardWidth/8)) + (x/8)
str := make([]string, 8)
for i := 0; i < 8; i++ {
str[i] = fmt.Sprintf("%3d", (neighborsY[i]*(BoardWidth/8)) + (neighborsX[i]/8))
}
fmt.Fprintf(out, ".byte %s ; current %3d (%2d, %2d)\n", strings.Join(str, ", "), current, x, y)
}
}
return nil
}