forked from sarah/microworlds
More succint plasmodium algo
This commit is contained in:
parent
3e5eac7730
commit
a7be149155
|
@ -1,30 +1,18 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"git.openprivacy.ca/sarah/microworlds/core"
|
||||
"git.openprivacy.ca/sarah/microworlds/experiments"
|
||||
"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 {
|
||||
SniffDistance int
|
||||
Num int
|
||||
NotMoved int
|
||||
}
|
||||
|
||||
func (sm *SlimeMold) Setup(env *core.Environment, t *core.Turtle) {
|
||||
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))
|
||||
//}
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
|
||||
|
||||
func (sm *SlimeMold) Run(env *core.Environment, t *core.Turtle) {
|
||||
|
||||
//t.FollowGradient(env, 1, 100, "food")
|
||||
//x,y := t.Pos()
|
||||
//
|
||||
// Move around the world, if there are too many slimes around us turn around, otherwise follow slimes and food.
|
||||
t.Wiggle()
|
||||
if t.Amount(env, 1, "slime") > 10 {
|
||||
t.TurnAround()
|
||||
|
@ -72,33 +56,25 @@ func (sm *SlimeMold) Run(env *core.Environment, t *core.Turtle) {
|
|||
}
|
||||
t.FollowGradient(env, 1, .1, "food")
|
||||
|
||||
if sm.NotMoved > 10 {
|
||||
t.Wiggle()
|
||||
t.Wiggle()
|
||||
t.Wiggle()
|
||||
//t.Step(env)
|
||||
}
|
||||
//
|
||||
//px,py := t.Pos()
|
||||
// If we have no neighbours we pretend we found some food so the others can find us.
|
||||
if t.Step(env) {
|
||||
ox, oy := t.Pos()
|
||||
if sm.CheckNeighbours(env, ox, oy) > 0 || env.HasValue(t.Pos()) {
|
||||
sm.NotMoved = 0
|
||||
t.Drop(env, .1, "slime")
|
||||
} else {
|
||||
sm.NotMoved++
|
||||
t.Drop(env, 10, "food")
|
||||
}
|
||||
} 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()) {
|
||||
env.TakeValue(t.Pos())
|
||||
t.Drop(env, 256, "food")
|
||||
}else {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -133,18 +109,13 @@ func main() {
|
|||
|
||||
experiment.InitNTurtles(func() core.Actor {
|
||||
sm := new(SlimeMold)
|
||||
sm.SniffDistance = *sniffDistance
|
||||
sm.Num = num
|
||||
num++
|
||||
return sm
|
||||
}, 3000)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
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) {
|
||||
environment.EvaporateAndDiffuse(0.99, "slime")
|
||||
environment.EvaporateAndDiffuse(0.99, "food")
|
||||
|
|
Loading…
Reference in New Issue