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 *SendMachine) send_message(comm agent.Comm) (sent, isack bool) {

	find := func() (*DataGram, bool) {
		for i := 0; i < self.sendq.Len(); i++ {
			msg, ok := self.sendq.Dequeue()
			if !ok {
				break
			}
			if _, has := self.routes[msg.DestAddr]; !has {
				self.sendq.Queue(msg)
			} else {
				return msg, true
			}
		}
		return nil, false
	}
	msg, found := find()
	if !found {
		return false, false
	}

	self.sendq.QueueFront(msg)

	next := self.routes[msg.DestAddr].NextAddr
	var pkt *Packet
	if msg.IsAck() {
		pkt = NewPacket(Commands["ACK"], self.agent.Id(), next)
	} else {
		pkt = NewPacket(Commands["MESSAGE"], self.agent.Id(), next)
	}
	pkt.SetBody(msg.Bytes())
	bytes := pkt.Bytes()
	comm.Broadcast(self.freq, bytes)
	if !msg.IsAck() {
		self.last_checksum = msg.ComputeChecksum()
	}
	self.last = bytes
	self.log("info", self.agent.Time(), "sent", pkt, msg)
	return true, msg.IsAck()
}