const (
width = 20
height = 10
)
type Universe [][]int
//生成universe
func NewUniverse() Universe {
u := make(Universe,height)
for i:= range u{
u[i] = make([]int,width)
}
return u
}
//打印universe
func (u Universe) Show(){
for i:=0;i<height;i++{
for j:=0;j<width;j++{
fmt.Print(u[i][j]," ")
}
fmt.Println()
}
}
//随机显示约25%为true
func (u Universe) Seed(){
rand.Seed(time.Now().UnixNano())
for i:=0;i<height;i++{
for j:=0;j<width;j++{
n := rand.Intn(200)
//fmt.Println(n)
if n<50 {
u[i][j] = 1
}
}
}
}