Fixing Sniff Bias

This commit is contained in:
Sarah Jamie Lewis 2019-08-02 22:04:43 -07:00
parent 308345b502
commit f888eea668
3 changed files with 15 additions and 5 deletions

View File

@ -7,7 +7,7 @@ import (
func TestEnvironment_Mark(t *testing.T) { func TestEnvironment_Mark(t *testing.T) {
env := NewEnvironment(3,3) env := NewEnvironment(3,3)
env.Mark(1,1,9) env.Mark(1,1,9)
env.Evaporate() env.Evaporate(0.9)
for x:=0;x<3;x++ { for x:=0;x<3;x++ {
for y:=0;y<3;y++ { for y:=0;y<3;y++ {
t.Logf("mark(%d,%d) = %f", x,y,env.Sniff(x,y)) t.Logf("mark(%d,%d) = %f", x,y,env.Sniff(x,y))
@ -15,7 +15,7 @@ func TestEnvironment_Mark(t *testing.T) {
} }
t.Logf("\n") t.Logf("\n")
env.Evaporate() env.Evaporate(0.9)
for x:=0;x<3;x++ { for x:=0;x<3;x++ {
for y:=0;y<3;y++ { for y:=0;y<3;y++ {
t.Logf("mark(%d,%d) = %f", x,y,env.Sniff(x,y)) t.Logf("mark(%d,%d) = %f", x,y,env.Sniff(x,y))

View File

@ -11,6 +11,16 @@ type Turtle struct {
} }
type NilActor struct {
}
func (NilActor) Setup(*Environment, *Turtle) {
}
func (NilActor) Run(*Environment, *Turtle) {
}
func NewTurtle(env *Environment, actor Actor) *Turtle { func NewTurtle(env *Environment, actor Actor) *Turtle {
for { for {
turtle := new(Turtle) turtle := new(Turtle)
@ -35,7 +45,7 @@ var headings = [][]int{{-1,-1},{0,-1},{1,-1},{1,0},{1,1},{0,1},{-1,1},{-1,0}}
func (t *Turtle) setRandomHeading() { func (t *Turtle) setRandomHeading() {
t.heading = rand.Intn(7) t.heading = rand.Intn(8)
} }
func (t *Turtle) SetXY(x,y int) { func (t *Turtle) SetXY(x,y int) {
@ -82,7 +92,7 @@ func (t *Turtle) FollowGradient(env *Environment, distance int, threshold float3
y := (t.ypos + dy) y := (t.ypos + dy)
h1 := (t.heading+1) % 7 h1 := (t.heading+1) % 8
dx1 := headings[h1][0] * distance dx1 := headings[h1][0] * distance
dy1 := headings[h1][1] * distance dy1 := headings[h1][1] * distance

View File

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