forked from sarah/microworlds
Plasmodium Experiment
This commit is contained in:
parent
5bba2f92d4
commit
3e5eac7730
|
@ -74,6 +74,7 @@ func (e Environment) Get(x, y int) *Turtle {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e Environment) Check(x, y int) bool {
|
func (e Environment) Check(x, y int) bool {
|
||||||
|
x, y = e.normXY(x, y)
|
||||||
return e.col[x][y] != nil
|
return e.col[x][y] != nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,49 +0,0 @@
|
||||||
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
|
|
||||||
}
|
|
||||||
|
|
||||||
func (sm *SlimeMold) Setup(env *core.Environment, t *core.Turtle) {
|
|
||||||
t.SetColor(color.RGBA{100, 255, 10, 0})
|
|
||||||
}
|
|
||||||
|
|
||||||
func (sm *SlimeMold) Run(env *core.Environment, t *core.Turtle) {
|
|
||||||
t.Wiggle()
|
|
||||||
if *defensiveDecentralization == false {
|
|
||||||
t.FollowGradient(env, sm.SniffDistance, 2, "trail")
|
|
||||||
} else if t.Amount(env,sm.SniffDistance,"trail") < 5.2 {
|
|
||||||
t.FollowGradient(env, sm.SniffDistance, 2, "trail")
|
|
||||||
} else {
|
|
||||||
//t.FollowGradient(env, sm.SniffDistance, 2, "trail")
|
|
||||||
//t.TurnAround()
|
|
||||||
}
|
|
||||||
t.Step(env)
|
|
||||||
t.Drop(env, 1, "trail")
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
experiment := new(experiments.Experiment)
|
|
||||||
experiment.InitializeExperiment()
|
|
||||||
experiment.InitTurtles(func() core.Actor {
|
|
||||||
sm := new(SlimeMold)
|
|
||||||
sm.SniffDistance = *sniffDistance
|
|
||||||
return sm
|
|
||||||
})
|
|
||||||
experiment.InitPheromone("trail", color.RGBA{0x80, 0xFF, 0x00, 0x00})
|
|
||||||
experiment.OnStep = func(environment *core.Environment, turtles []*core.Turtle, i int) {
|
|
||||||
environment.EvaporateAndDiffuse(0.95, "trail")
|
|
||||||
}
|
|
||||||
experiment.Run()
|
|
||||||
}
|
|
|
@ -0,0 +1,153 @@
|
||||||
|
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 {
|
||||||
|
neighbours := 0
|
||||||
|
if env.Check(ox-1, oy-1) {
|
||||||
|
neighbours++
|
||||||
|
}
|
||||||
|
if env.Check(ox, oy-1) {
|
||||||
|
neighbours++
|
||||||
|
}
|
||||||
|
if env.Check(ox+1, oy-1) {
|
||||||
|
neighbours++
|
||||||
|
}
|
||||||
|
if env.Check(ox-1, oy) {
|
||||||
|
neighbours++
|
||||||
|
}
|
||||||
|
if env.Check(ox+1, oy) {
|
||||||
|
neighbours++
|
||||||
|
}
|
||||||
|
|
||||||
|
if env.Check(ox-1, oy+1) {
|
||||||
|
neighbours++
|
||||||
|
}
|
||||||
|
if env.Check(ox, oy+1) {
|
||||||
|
neighbours++
|
||||||
|
}
|
||||||
|
if env.Check(ox+1, oy+1) {
|
||||||
|
neighbours++
|
||||||
|
}
|
||||||
|
return neighbours
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
func (sm *SlimeMold) Run(env *core.Environment, t *core.Turtle) {
|
||||||
|
|
||||||
|
//t.FollowGradient(env, 1, 100, "food")
|
||||||
|
//x,y := t.Pos()
|
||||||
|
//
|
||||||
|
t.Wiggle()
|
||||||
|
if t.Amount(env, 1, "slime") > 10 {
|
||||||
|
t.TurnAround()
|
||||||
|
} else {
|
||||||
|
t.FollowGradient(env,1,1,"slime")
|
||||||
|
}
|
||||||
|
t.FollowGradient(env, 1, .1, "food")
|
||||||
|
|
||||||
|
if sm.NotMoved > 10 {
|
||||||
|
t.Wiggle()
|
||||||
|
t.Wiggle()
|
||||||
|
t.Wiggle()
|
||||||
|
//t.Step(env)
|
||||||
|
}
|
||||||
|
//
|
||||||
|
//px,py := t.Pos()
|
||||||
|
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++
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if env.HasValue(t.Pos()) {
|
||||||
|
env.TakeValue(t.Pos())
|
||||||
|
t.Drop(env, 256, "food")
|
||||||
|
}else {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
experiment := new(experiments.Experiment)
|
||||||
|
experiment.InitializeExperiment()
|
||||||
|
|
||||||
|
num := 0
|
||||||
|
|
||||||
|
experiment.InitEnvironment(func(environment *core.Environment) {
|
||||||
|
x,y := 120,120
|
||||||
|
for i:=0;i<20;i++ {
|
||||||
|
for j :=0;j<20;j++ {
|
||||||
|
environment.PutValue(x+i,y+j)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
x,y = 250,120
|
||||||
|
for i:=0;i<20;i++ {
|
||||||
|
for j :=0;j<20;j++ {
|
||||||
|
environment.PutValue(x+i,y+j)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
x,y = 160,130
|
||||||
|
for i:=0;i<10;i++ {
|
||||||
|
for j :=0;j<10;j++ {
|
||||||
|
environment.PutValue(x+i,y+j)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
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.OnStep = func(environment *core.Environment, turtles []*core.Turtle, i int) {
|
||||||
|
environment.EvaporateAndDiffuse(0.99, "slime")
|
||||||
|
environment.EvaporateAndDiffuse(0.99, "food")
|
||||||
|
}
|
||||||
|
experiment.Run()
|
||||||
|
}
|
Loading…
Reference in New Issue