Small fix + fmt

This commit is contained in:
Sarah Jamie Lewis 2019-08-02 22:14:56 -07:00
parent f888eea668
commit 56f0e4f487
9 changed files with 126 additions and 155 deletions

View File

@ -4,7 +4,6 @@ import (
"git.openprivacy.ca/sarah/microworlds/core"
)
type Ant struct {
SniffDistance int
Carrying bool
@ -34,4 +33,3 @@ func (a*Ant) Run(env *core.Environment, t *core.Turtle) {
t.Step(env)
}
}

View File

@ -12,7 +12,6 @@ func (e *Environment) Width() int {
return e.width
}
func (e *Environment) Height() int {
return e.height
}
@ -42,11 +41,8 @@ func (e *Environment) Mark(x,y int,amount float32) {
if e.state[x][y] > 255 {
e.state[x][y] = 255
}
//log.Debugf("Marking: %d %d %f", x, y, e.state[x][y])
}
func (e Environment) Occupy(x, y int) {
e.col[x][y] = true
}
@ -59,7 +55,6 @@ func (e Environment) Leave(x,y int) {
e.col[x][y] = false
}
func (e Environment) HasValue(x, y int) bool {
return e.value[x][y]
}
@ -76,7 +71,6 @@ func (e Environment) Sniff(x,y int) float32 {
return e.state[x][y]
}
func (e *Environment) normXY(x int, y int) (int, int) {
if x < 0 {
x = (e.width - 1)
@ -96,7 +90,6 @@ func (e *Environment) normXY(x int, y int) (int,int) {
func (e *Environment) Evaporate(rate float32) {
//log.Debugf("Evap")
e.pstate = make([][]float32, e.width)
for x := range e.pstate {
e.pstate[x] = make([]float32, e.height)
@ -107,7 +100,6 @@ func (e *Environment) Evaporate(rate float32) {
}
}
for x := 0; x < e.width; x++ {
for y := 0; y < e.height; y++ {
amount := e.pstate[x][y]

View File

@ -10,9 +10,7 @@ type Turtle struct {
actor Actor
}
type NilActor struct {
}
func (NilActor) Setup(*Environment, *Turtle) {
@ -43,7 +41,6 @@ func (t *Turtle) Pos() (int,int) {
var headings = [][]int{{-1, -1}, {0, -1}, {1, -1}, {1, 0}, {1, 1}, {0, 1}, {-1, 1}, {-1, 0}}
func (t *Turtle) setRandomHeading() {
t.heading = rand.Intn(8)
}
@ -62,12 +59,10 @@ func (t *Turtle) Wiggle() {
t.heading = h
}
func (t *Turtle) TurnAround() {
t.heading = (t.heading + 4) % 8
}
func (t *Turtle) Drop(env *Environment, amount float32) {
env.Mark(t.xpos, t.ypos, amount)
}
@ -91,7 +86,6 @@ func (t *Turtle) FollowGradient(env *Environment, distance int, threshold float3
x := (t.xpos + dx)
y := (t.ypos + dy)
h1 := (t.heading + 1) % 8
dx1 := headings[h1][0] * distance
dy1 := headings[h1][1] * distance
@ -126,11 +120,11 @@ func (t* Turtle) Step(env *Environment) bool {
ox := t.xpos
oy := t.ypos
env.Leave(ox, oy)
t.xpos = (t.xpos + dx) % (env.width -1)
t.xpos = (t.xpos + dx) % (env.width)
if t.xpos < 0 {
t.xpos = env.width - 1
}
t.ypos = (t.ypos + dy) % (env.height -1)
t.ypos = (t.ypos + dy) % (env.height)
if t.ypos < 0 {
t.ypos = env.height - 1
}
@ -147,6 +141,5 @@ func (t* Turtle) Step(env *Environment) bool {
// Run the turtle program
func (t *Turtle) Run(env *Environment) {
//log.Debugf("Pos: %v %v", t.xpos, t.ypos)
t.actor.Run(env, t)
}

View File

@ -5,7 +5,7 @@ import (
)
func TestTurtle_Wiggle(t *testing.T) {
turtle := NewTurtle(NewEnvironment(3,3,), new(NilActor))
turtle := NewTurtle(NewEnvironment(3, 3), new(NilActor))
counts := []int{0, 0, 0, 0, 0, 0, 0, 0}
for i := 0; i < 1000; i++ {
turtle.Wiggle()

View File

@ -41,8 +41,6 @@ func (g* Graphics) Render(env *core.Environment, turtles []*core.Turtle) {
g.renderer.SetDrawColor(0x00, 0x00, 0x00, 0x00)
g.renderer.FillRect(&sdl.Rect{0, 0, 600, 600})
for x := 0; x < int(g.width); x++ {
for y := 0; y < int(g.height); y++ {
amount := math.Min(float64(env.Sniff(x, y)), 255)
@ -63,7 +61,6 @@ func (g* Graphics) Render(env *core.Environment, turtles []*core.Turtle) {
}
}
g.renderer.SetDrawColor(0xF3, 0x81, 0, 0x00)
for _, t := range turtles {
x, y := t.Pos()
@ -76,5 +73,5 @@ func (g* Graphics) Render(env *core.Environment, turtles []*core.Turtle) {
g.window.UpdateSurface()
surface, _ := g.window.GetSurface()
surface.SaveBMP("./images/" + strconv.Itoa(g.t) + ".bmp")
g.t++;
g.t++
}

View File

@ -14,7 +14,6 @@ import (
"time"
)
var cpuprofile = flag.String("cpuprofile", "", "write cpu profile to file")
var model = flag.String("model", "slime", "slimemold|swarm|woodchips")
@ -23,8 +22,6 @@ var width = flag.Int("width", 300, "width of environment")
var height = flag.Int("height", 300, "height of environment")
var numTurtles = flag.Int("numTurtles", 5000, "number of turtles")
func main() {
// We don't need real randomness
@ -45,11 +42,9 @@ func main() {
}
defer sdl.Quit()
env := core.NewEnvironment(*width, *height)
turtles := make([]*core.Turtle, *numTurtles)
switch *model {
case "swarm":
@ -90,8 +85,6 @@ func main() {
}
}
g := graphics.NewGraphics(int32(*width), int32(*height))
running := true
@ -105,7 +98,6 @@ func main() {
wait.Done()
}()
wait.Add(1)
for running {
for event := sdl.PollEvent(); event != nil; event = sdl.PollEvent() {
@ -119,4 +111,3 @@ func main() {
wait.Done()
wait.Wait()
}