Initial commit
This commit is contained in:
commit
b3f3a77fc7
8 changed files with 242 additions and 0 deletions
32
simulation/simulation.go
Normal file
32
simulation/simulation.go
Normal file
|
@ -0,0 +1,32 @@
|
|||
package simulation
|
||||
|
||||
import (
|
||||
"math/rand/v2"
|
||||
)
|
||||
|
||||
type Simulation struct {
|
||||
Grid *XelGrid
|
||||
}
|
||||
|
||||
func (sim *Simulation) Update() {
|
||||
for range 10 {
|
||||
// get all available xels with energy != 0
|
||||
available_positions := []Vector2{}
|
||||
for i, xel := range sim.Grid.Xels {
|
||||
if xel.Energy != 0 {
|
||||
available_positions = append(available_positions, Vector2{X: i % sim.Grid.Width, Y: i/sim.Grid.Height})
|
||||
}
|
||||
}
|
||||
// choose random pos
|
||||
pos := available_positions[rand.IntN(len(available_positions))]
|
||||
xel := sim.Grid.GetXel(pos)
|
||||
if xel.Energy == 0 { panic("xel energy null") }
|
||||
xel.Step(pos, sim.Grid)
|
||||
}
|
||||
}
|
||||
|
||||
func NewSimulation(width int, height int) *Simulation {
|
||||
return &Simulation{
|
||||
Grid: NewXelGrid(width, height),
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue