本文整理汇总了Golang中github.com/dnesting/alife/goalife/grid2d.Grid.Locations方法的典型用法代码示例。如果您正苦于以下问题:Golang Grid.Locations方法的具体用法?Golang Grid.Locations怎么用?Golang Grid.Locations使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/dnesting/alife/goalife/grid2d.Grid
的用法示例。
在下文中一共展示了Grid.Locations方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: StartAll
// StartAll finds all organisms driven by Cpu instances, and spawns a goroutine
// to begin executing each Cpu instance found.
func StartAll(g grid2d.Grid) {
var locs []grid2d.Point
g.Locations(&locs)
for _, p := range locs {
if o, ok := p.V.(*org.Organism); ok {
if c, ok := o.Driver.(*Cpu); ok {
go c.Run(o)
}
}
}
}
示例2: Count
// Count counts the number of occupants in g that satisfy fn.
func Count(g grid2d.Grid, fn CounterFunc) int {
var locs []grid2d.Point
g.Locations(&locs)
var count int
for _, p := range locs {
if fn(p.V) {
count += 1
}
}
return count
}
示例3: PrintWorld
// PrintWorld renders g to w.
func PrintWorld(w io.Writer, g grid2d.Grid) {
points := locPool.Get().([]grid2d.Point)
width, height, _ := g.Locations(&points)
sort.Sort(byCoordinate(points))
iy, ix := 0, -1
addHeader(w, width)
for _, p := range points {
fillBefore(w, p.X, p.Y, width, &ix, &iy)
writeRune(w, RuneForOccupant(p.V))
ix += 1
}
locPool.Put(points)
fillBefore(w, width, height-1, width, &ix, &iy)
writeRune(w, rightRune)
writeRune(w, '\n')
addFooter(w, width)
}