Ejemplo n.º 1
0
func NewMario(figCount int, size *util.Vector) *Mario {
	fmt.Println("")
	level := NewLevel(int(size.X), int(size.Y))
	level.AddFigures(figCount)

	nets := make([]*neural.Net, figCount, figCount)
	for c := range nets {
		nets[c] = neural.NewNet(NRN_COUNT)

		for r := 0; r < (nrn(H4) - nrn(H1)); r++ {
			// input to H
			for inp := nrn(I0); inp <= nrn(I48); inp++ {
				*nets[c].Synapse(inp+nrn(I0), r+nrn(H1)) = 0.0
			}

			// R to output
			*nets[c].Synapse(r+nrn(R1), nrn(jump)) = 0.0
			*nets[c].Synapse(r+nrn(R1), nrn(xMove)) = 0.0
		}

		for r := 0; r < (nrn(H4) - nrn(H1)); r++ {
			for q := 0; q < (nrn(H4) - nrn(H1)); q++ {
				*nets[c].Synapse(r+nrn(H1), q+nrn(R1)) = 0.0
			}
		}

		nets[c].Randomize()
	}

	figs := make(MarioCol, figCount, figCount)
	for c := range figs {
		figs[c].brain = nets[c]
		figs[c].dead = false
		figs[c].bestX = 0
		figs[c].fig = level.figures[c]
		figs[c].cache = make(map[BoolMap]MarioOutput)
	}

	return &Mario{
		figures: figs,
		lvl:     *level,
		dbg: DebugMario{
			figure: &figs[0],
			output: MarioOutput{
				jump: 0,
				move: 0,
			},
		},
		drawCb:   func(pos, size *util.Vector, color uint32) {},
		drawSize: 5,
	}
}
Ejemplo n.º 2
0
func NewFlappy(birdCount int, size *util.Vector) *Flappy {
	level := NewLevel(int(size.X), int(size.Y))

	nets := make([]*neural.Net, birdCount, birdCount)
	for c := range nets {
		nets[c] = neural.NewNet(NRN_COUNT)

		// diffY- to hidden
		*nets[c].Synapse(nrn(diffY), nrn(H1)) = 0.0
		*nets[c].Synapse(nrn(diffY), nrn(H2)) = 0.0
		*nets[c].Synapse(nrn(diffY), nrn(H3)) = 0.0
		*nets[c].Synapse(nrn(diffY), nrn(H4)) = 0.0

		// diffX- to hidden
		*nets[c].Synapse(nrn(diffX), nrn(H1)) = 0.0
		*nets[c].Synapse(nrn(diffX), nrn(H2)) = 0.0
		*nets[c].Synapse(nrn(diffX), nrn(H3)) = 0.0
		*nets[c].Synapse(nrn(diffX), nrn(H4)) = 0.0

		// velY - to hidden
		*nets[c].Synapse(nrn(velY), nrn(H1)) = 0.0
		*nets[c].Synapse(nrn(velY), nrn(H2)) = 0.0
		*nets[c].Synapse(nrn(velY), nrn(H3)) = 0.0
		*nets[c].Synapse(nrn(velY), nrn(H4)) = 0.0

		// hidden to output
		*nets[c].Synapse(nrn(H1), nrn(jump)) = 0.0
		*nets[c].Synapse(nrn(H2), nrn(jump)) = 0.0
		*nets[c].Synapse(nrn(H3), nrn(jump)) = 0.0
		*nets[c].Synapse(nrn(H4), nrn(jump)) = 0.0

		nets[c].Randomize()
	}

	level.AddBirds(birdCount)
	flock := make(Flock, birdCount)
	for c := 0; c < birdCount; c++ {
		flock[c].bird = level.birds[c]
		flock[c].brain = nets[c]
		flock[c].bestX = 0
		flock[c].dead = false
	}

	return &Flappy{
		birds:    flock,
		lvl:      *level,
		drawCb:   func(pos, size *util.Vector, color uint32) {},
		drawSize: 5,
	}
}