This commit is contained in:
Sarah Jamie Lewis 2019-08-27 19:34:28 -07:00
parent acc50d7001
commit af28fc7ec0
2 changed files with 79 additions and 0 deletions

67
actors/isolate.go Normal file
View File

@ -0,0 +1,67 @@
package actors
import (
"git.openprivacy.ca/sarah/microworlds/core"
"math/rand"
"strconv"
)
type Isolate struct {
color int
Probability float32
sureness float32
Byztantine bool
}
func (sm *Isolate) Setup(env *core.Environment, t *core.Turtle) {
num := rand.Intn(100)
if num >= int(sm.Probability*100.0) {
sm.color = 2
} else {
sm.color = 1
}
sm.sureness = 2
}
func (sm *Isolate) Run(env *core.Environment, t *core.Turtle) {
if sm.Byztantine {
t.Wiggle()
t.FollowGradient(env, 10,0, "2",)
t.Drop(env, 1, "2")
t.Step(env)
} else {
t.Wiggle()
am1 := t.Amount(env, 1, "1")
am2 := t.Amount(env, 1, "2")
if am1 > sm.sureness || am2 > sm.sureness {
if am1 > am2 {
if sm.color == 2 {
sm.sureness--
} else {
sm.sureness++
}
if sm.sureness == 0 {
sm.color = 1
}
} else if am2 > am1 {
if sm.color == 1 {
sm.sureness--
} else {
sm.sureness++
}
if sm.sureness == 0 {
sm.color = 2
}
}
}
if sm.sureness > 1 {
t.Drop(env, 1, strconv.Itoa(sm.color))
}
t.Step(env)
}
}

12
main.go
View File

@ -121,6 +121,18 @@ func main() {
env.InitPheromone("2")
g.ColorPheromone("1", [4]uint8{0x00, 0xFF, 0x80, 0x00})
g.ColorPheromone("2", [4]uint8{0xFF, 0x00, 0xa5, 0x00})
case "isolate":
honestTurtles := (*numTurtles)-(*byzantineTurtles)
for i := 0; i < honestTurtles; i++ {
turtles[i] = core.NewTurtle(env, &actors.Isolate{Probability:float32(*prob)})
}
for i := honestTurtles; i < honestTurtles+(*byzantineTurtles); i++ {
turtles[i] = core.NewTurtle(env, &actors.Isolate{Probability:float32(*prob), Byztantine:true})
}
env.InitPheromone("1")
env.InitPheromone("2")
g.ColorPheromone("1", [4]uint8{0x00, 0xFF, 0x80, 0x00})
g.ColorPheromone("2", [4]uint8{0xFF, 0x00, 0xa5, 0x00})
case "flocking":
for i := 0; i < *numTurtles; i++ {
turtles[i] = core.NewTurtle(env, &actors.Flocking{SniffDistance: 1})