More succint plasmodium algo
This commit is contained in:
parent
3e5eac7730
commit
a7be149155
|
@ -1,30 +1,18 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"flag"
|
|
||||||
"git.openprivacy.ca/sarah/microworlds/core"
|
"git.openprivacy.ca/sarah/microworlds/core"
|
||||||
"git.openprivacy.ca/sarah/microworlds/experiments"
|
"git.openprivacy.ca/sarah/microworlds/experiments"
|
||||||
"image/color"
|
"image/color"
|
||||||
)
|
)
|
||||||
|
|
||||||
var sniffDistance = flag.Int("sniffDistance", 3, "the distance a turtle can detect pheromone levels from")
|
|
||||||
var defensiveDecentralization = flag.Bool("defensiveDecentralization", false, "if true, slime molds will break up if the concentration is too great")
|
|
||||||
|
|
||||||
|
|
||||||
type SlimeMold struct {
|
type SlimeMold struct {
|
||||||
SniffDistance int
|
|
||||||
Num int
|
Num int
|
||||||
NotMoved int
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sm *SlimeMold) Setup(env *core.Environment, t *core.Turtle) {
|
func (sm *SlimeMold) Setup(env *core.Environment, t *core.Turtle) {
|
||||||
t.SetColor(color.RGBA{100, 255, 10, 0})
|
t.SetColor(color.RGBA{100, 255, 10, 0})
|
||||||
|
|
||||||
//if sm.Num 1000 {
|
|
||||||
//t.SetXY(150,150)
|
|
||||||
//} else {
|
|
||||||
t.SetXY(150+(sm.Num%100), 150+(sm.Num/100))
|
t.SetXY(150+(sm.Num%100), 150+(sm.Num/100))
|
||||||
//}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sm *SlimeMold) CheckNeighbours(env *core.Environment, ox, oy int) int {
|
func (sm *SlimeMold) CheckNeighbours(env *core.Environment, ox, oy int) int {
|
||||||
|
@ -57,13 +45,9 @@ func (sm * SlimeMold) CheckNeighbours(env *core.Environment, ox,oy int) int {
|
||||||
return neighbours
|
return neighbours
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
func (sm *SlimeMold) Run(env *core.Environment, t *core.Turtle) {
|
func (sm *SlimeMold) Run(env *core.Environment, t *core.Turtle) {
|
||||||
|
|
||||||
//t.FollowGradient(env, 1, 100, "food")
|
// Move around the world, if there are too many slimes around us turn around, otherwise follow slimes and food.
|
||||||
//x,y := t.Pos()
|
|
||||||
//
|
|
||||||
t.Wiggle()
|
t.Wiggle()
|
||||||
if t.Amount(env, 1, "slime") > 10 {
|
if t.Amount(env, 1, "slime") > 10 {
|
||||||
t.TurnAround()
|
t.TurnAround()
|
||||||
|
@ -72,33 +56,25 @@ func (sm *SlimeMold) Run(env *core.Environment, t *core.Turtle) {
|
||||||
}
|
}
|
||||||
t.FollowGradient(env, 1, .1, "food")
|
t.FollowGradient(env, 1, .1, "food")
|
||||||
|
|
||||||
if sm.NotMoved > 10 {
|
// If we have no neighbours we pretend we found some food so the others can find us.
|
||||||
t.Wiggle()
|
|
||||||
t.Wiggle()
|
|
||||||
t.Wiggle()
|
|
||||||
//t.Step(env)
|
|
||||||
}
|
|
||||||
//
|
|
||||||
//px,py := t.Pos()
|
|
||||||
if t.Step(env) {
|
if t.Step(env) {
|
||||||
ox, oy := t.Pos()
|
ox, oy := t.Pos()
|
||||||
if sm.CheckNeighbours(env, ox, oy) > 0 || env.HasValue(t.Pos()) {
|
if sm.CheckNeighbours(env, ox, oy) > 0 || env.HasValue(t.Pos()) {
|
||||||
sm.NotMoved = 0
|
|
||||||
t.Drop(env, .1, "slime")
|
t.Drop(env, .1, "slime")
|
||||||
} else {
|
} else {
|
||||||
sm.NotMoved++
|
|
||||||
t.Drop(env, 10, "food")
|
t.Drop(env, 10, "food")
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
sm.NotMoved++
|
// We are on top of other slime, add some more randomness
|
||||||
|
t.Wiggle()
|
||||||
|
t.Wiggle()
|
||||||
|
t.Wiggle()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// We've found food, let's drop some chemical to tell others
|
||||||
if env.HasValue(t.Pos()) {
|
if env.HasValue(t.Pos()) {
|
||||||
env.TakeValue(t.Pos())
|
env.TakeValue(t.Pos())
|
||||||
t.Drop(env, 256, "food")
|
t.Drop(env, 256, "food")
|
||||||
}else {
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -133,18 +109,13 @@ func main() {
|
||||||
|
|
||||||
experiment.InitNTurtles(func() core.Actor {
|
experiment.InitNTurtles(func() core.Actor {
|
||||||
sm := new(SlimeMold)
|
sm := new(SlimeMold)
|
||||||
sm.SniffDistance = *sniffDistance
|
|
||||||
sm.Num = num
|
sm.Num = num
|
||||||
num++
|
num++
|
||||||
return sm
|
return sm
|
||||||
}, 3000)
|
}, 3000)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
experiment.InitPheromone("slime", color.RGBA{0x80, 0xFF, 0x00, 0x00})
|
experiment.InitPheromone("slime", color.RGBA{0x80, 0xFF, 0x00, 0x00})
|
||||||
experiment.InitPheromone("food", color.RGBA{0x00, 0x00, 0x00, 0x00})
|
experiment.InitPheromone("food", color.RGBA{0x80, 0xFF, 0x00, 0x00})
|
||||||
experiment.OnStep = func(environment *core.Environment, turtles []*core.Turtle, i int) {
|
experiment.OnStep = func(environment *core.Environment, turtles []*core.Turtle, i int) {
|
||||||
environment.EvaporateAndDiffuse(0.99, "slime")
|
environment.EvaporateAndDiffuse(0.99, "slime")
|
||||||
environment.EvaporateAndDiffuse(0.99, "food")
|
environment.EvaporateAndDiffuse(0.99, "food")
|
||||||
|
|
Loading…
Reference in New Issue