Esempio n. 1
0
File: field.go Progetto: 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
}
Esempio n. 2
0
File: game.go Progetto: Rompei/lgb
func (g *Game) step() {
	g.finishFlag = true
	nextField := field.InitField(g.field.SizeX, g.field.SizeY)
	for y := 0; y < g.field.SizeY; y++ {
		for x := 0; x < g.field.SizeX; x++ {
			if utils.CheckRate(g.mutRate) {
				// 突然変異
				g.mutation(nextField, x, y)
				g.gameStatus.MutNum++
				g.finishFlag = false
				continue
			}
			aliveCells := g.field.GetAliveCells(x, y)
			if aliveCells == 2 {
				// 変化なし
				if g.debug {
					emoji.Printf(":grin:Points[%v][%v] was not changed\n", x, y)
				}
				nextField.Points[y][x] = g.field.Points[y][x]
			} else if aliveCells == 3 {
				// 創発
				if g.field.Points[y][x].IsAlive {
					if g.debug {
						emoji.Printf(":smiley:Points[%v][%v] is already existed\n", x, y)
					}
					nextField.Points[y][x] = g.field.Points[y][x]
					continue
				}
				tweet := g.getTweets(1)[0]
				if g.debug {
					emoji.Printf(":baby:Points[%v][%v] generated and Fetched tweet: %v\n", x, y, tweet)
				}
				if g.isChaos {
					// カオスモード
					crossedTweet, err := g.field.CrossParents(x, y, tweet)
					if err != nil {
						panic(err)
					}
					if g.debug {
						emoji.Printf(":baby:Points[%v][%v] generated and Crossed tweet: %v\n", x, y, crossedTweet)
					}
					nextField.AddPoint(x, y, crossedTweet)
					g.gameStatus.BornNum++
					g.finishFlag = false
					continue
				}
				nextField.AddPoint(x, y, tweet)
				g.gameStatus.BornNum++
				g.finishFlag = false
			} else {
				// 絶命
				if !g.field.Points[y][x].IsAlive {
					if g.debug {
						emoji.Printf(":angel:Point[%v][%v] already died\n", x, y)
					}
					continue
				}
				if g.debug {
					emoji.Printf(":dizzy_face:Points[%v][%v] died\n", x, y)
				}
				nextField.DelPoint(x, y)
				g.gameStatus.DeadNum++
				g.finishFlag = false
			}
		}
	}

	// フィールド切り替え
	g.field = nextField

	// 世代更新
	g.gameStatus.Generation++
}