コード例 #1
0
ファイル: master.go プロジェクト: jmptrader/Tecellate
func (self *Master) sendCoordConfigs() {
	for address, cc := range self.conf.Coordinators {
		self.log.Print("Configuring ", address)

		peers := make(map[string]int)
		for _, peerAddress := range cc.Peers {
			peerConf := self.conf.Coordinators[peerAddress]
			peers[peerAddress] = peerConf.Identifier
		}
		thisConf := coordconf.NewConfig(cc.Identifier,
			address,
			self.conf.MaxTurns,
			cc.Agents,
			self.conf.MessageStyle,
			self.conf.UseFood,
			cc.BottomLeft,
			cc.TopRight)
		thisConf.Logs = cc.Logs
		thisConf.Peers = peers

		bytes, err := json.Marshal(thisConf)
		if err != nil {
			self.log.Fatal(err)
		}
		self.coordSendChannels[address] <- bytes

		self.log.Println("Waiting for response")
		rsp := <-self.coordRecvChannels[address]
		if string(rsp) != "configured" {
			self.log.Fatal("Coordinator at ", address, " failed: ", string(bytes))
		}
	}
}
コード例 #2
0
func TestWithCoord(t *testing.T) {
	fmt.Println("Testing With Coord")
	agnt := make(chan link.Message, 10)
	prox := make(chan link.Message, 10)
	simple := NewSimple(1)
	proxy := cagent.NewAgentProxy(prox, agnt)
	go func() {
		agent.Run(simple, agnt, prox)
	}()

	co := coord.NewCoordinator()
	co.Configure(
		config.NewConfig(
			0,
			[]cagent.Agent{
				proxy,
			},
			"noise",
			true,
			true,
			geo.NewPoint(0, 0),
			geo.NewPoint(10, 10),
		),
	)
	co.Run()
}
コード例 #3
0
ファイル: gameconfig.go プロジェクト: jmptrader/Tecellate
func (self *GameConfig) CoordConfig(id int, bl *geo.Point, tr *geo.Point) *config.Config {
	thisCoordsAgents := make([]*config.AgentDefinition, 0)

	for _, ad := range self.Agents {
		if bl.X <= ad.X && ad.X < tr.X && bl.Y <= ad.Y && ad.Y < tr.Y {
			thisCoordsAgents = append(thisCoordsAgents, ad)
		}
	}

	return config.NewConfig(id,
		fmt.Sprintf("127.0.0.1:%d", 8000+id),
		self.MaxTurns,
		thisCoordsAgents,
		self.MessageStyle,
		self.UseFood,
		bl,
		tr)
}