mirror of
https://github.com/cwinfo/yggdrasil-go.git
synced 2024-11-24 23:01:35 +00:00
42 lines
842 B
Go
42 lines
842 B
Go
|
package main
|
||
|
|
||
|
type nodeStore map[int]*simNode
|
||
|
|
||
|
func makeStoreSingle() nodeStore {
|
||
|
s := make(nodeStore)
|
||
|
s[0] = newNode(0)
|
||
|
return s
|
||
|
}
|
||
|
|
||
|
func linkNodes(a *simNode, b *simNode) {
|
||
|
la := a.core.NewSimlink()
|
||
|
lb := b.core.NewSimlink()
|
||
|
la.SetDestination(lb)
|
||
|
lb.SetDestination(la)
|
||
|
la.Start()
|
||
|
lb.Start()
|
||
|
}
|
||
|
|
||
|
func makeStoreSquareGrid(sideLength int) nodeStore {
|
||
|
store := make(nodeStore)
|
||
|
nNodes := sideLength * sideLength
|
||
|
idxs := make([]int, 0, nNodes)
|
||
|
// TODO shuffle nodeIDs
|
||
|
for idx := 1; idx <= nNodes; idx++ {
|
||
|
idxs = append(idxs, idx)
|
||
|
}
|
||
|
for _, idx := range idxs {
|
||
|
n := newNode(idx)
|
||
|
store[idx] = n
|
||
|
}
|
||
|
for idx := 0; idx < nNodes; idx++ {
|
||
|
if (idx % sideLength) != 0 {
|
||
|
linkNodes(store[idxs[idx]], store[idxs[idx-1]])
|
||
|
}
|
||
|
if idx >= sideLength {
|
||
|
linkNodes(store[idxs[idx]], store[idxs[idx-sideLength]])
|
||
|
}
|
||
|
}
|
||
|
return store
|
||
|
}
|