當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Grid.Locations方法代碼示例

本文整理匯總了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)
			}
		}
	}
}
開發者ID:dnesting,項目名稱:alife,代碼行數:13,代碼來源:cpu.go

示例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
}
開發者ID:dnesting,項目名稱:alife,代碼行數:13,代碼來源:maintain.go

示例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)
}
開發者ID:dnesting,項目名稱:alife,代碼行數:20,代碼來源:world.go


注:本文中的github.com/dnesting/alife/goalife/grid2d.Grid.Locations方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。