本文整理匯總了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)
}