Exemplo n.º 1
0
Arquivo: field.go Projeto: Rompei/lgb
// InitField initialize empty field
func InitField(sizeX, sizeY int) *Field {
	f := initField(sizeX, sizeY)

	f.Points = make([][]point.Point, sizeY)
	for y := 0; y < sizeY; y++ {
		cells := make([]point.Point, sizeX)
		for x := 0; x < sizeX; x++ {
			cells[x] = point.NewPoint(x, y, "", false)
		}
		f.Points[y] = cells
	}
	return f
}
Exemplo n.º 2
0
Arquivo: field.go Projeto: Rompei/lgb
// NewField : Constructor of Field
// @Param size      フィールドサイズ
// @Param aliveRate 初期化時の生存率
// @Param strs      文字
// return Field
func NewField(sizeX, sizeY int, aliveRate float64) (*Field, int, error) {
	aliveNum := 0
	f := initField(sizeX, sizeY)
	f.Points = make([][]point.Point, sizeY)
	for y := 0; y < sizeY; y++ {
		cells := make([]point.Point, sizeX)
		for x := 0; x < sizeX; x++ {
			isAlive := utils.CheckRate(aliveRate)
			if isAlive {
				aliveNum++
			}
			cells[x] = point.NewPoint(x, y, "", isAlive)
		}
		f.Points[y] = cells
	}
	return f, aliveNum, nil
}