Beispiel #1
0
func (self *Configurable) Turn(comm agent.Comm) {
	broadcasted := comm.Broadcast(23, []byte("hello_world"))
	if self.LogBroadcast {
		comm.Log("Broadcast success:", broadcasted)
	}
	comm.Move(self.XVelocity, self.YVelocity)
	if self.LogMove {
		// comm.Logf("Pos: %v (%t)", self.Position(), success)
	}
	if self.LogListen {
		comm.Log("Heard:", string(comm.Listen(23)))
	}
	if self.LogCollect {
		comm.Log("Collected: ", comm.Collect())
	}
	if self.LogLook {
		comm.Log("Look: ", comm.Collect())
	}
	if self.LogPrevious {
		comm.Log("Previous: ", comm.PrevResult())
	}
	if self.LogEnergy {
		comm.Log("Energy:", comm.Energy())
	}
	return
}
Beispiel #2
0
func (self *RandomBot) Turn(comm agent.Comm) {
	defer func() { self.time += 1 }()

	if self.Time()%250 == 0 {
		x := pseudo_rand.Intn(2) - 1
		y := pseudo_rand.Intn(2) - 1
		comm.Move(x, y)
		self.log("info", "moved", x, y)
	}

	if self.Id() == 8 && self.Time() == 500 {
		self.send.Send([]byte("Hello there Number 1."), 1)
	}

	self.hello.Run(comm)
	self.route.Run(self.hello.Neighbors(), comm)
	m := self.send.Run(self.route.Routes(), comm)

	if m != nil {
		self.log("info", self.Time(), "got a message", string([]byte(m.Body())))
	}
	if self.Time()%100 == 9 {
		//         self.log("info", self.Time(), "neighbors", self.hello.Neighbors())

		//         self.log("info", self.Time(), "reachable", self.route.Reachable())
		//         s := fmt.Sprintf("\nRoute Table (%v):\n", self.agent.Id())
		//         for i := uint32(1); i <= 8; i++ {
		//             if route, has := self.routes[i]; has {
		//                 s += fmt.Sprint(route, "\n")
		//             }
		//         }
		//         self.log("info", s)
	}
}
Beispiel #3
0
func (self *Simple) Turn(comm agent.Comm) {
	if !comm.Move(agent.NewMove(1, 0)) {
		fmt.Println("Move Failed!")
	}
	if !comm.Move(agent.NewMove(1, 0)) {
		fmt.Println("Move Failed!")
	}
	return
}