public Agent(AgentConfiguration agentConfiguration) { logger.Info("[Agent] Agent created"); var teamId = agentConfiguration.TeamID.ToLower() == "red" ? TeamId.Red : TeamId.Blue; StartGameComponent = new StartGameComponent(this, teamId); AgentInformationsComponent = new AgentInformationsComponent(this); AgentConfiguration = agentConfiguration; NetworkComponent = new ClientNetworkComponent(agentConfiguration.CsIP, agentConfiguration.CsPort); Piece = null; WaitingPlayers = new List <int>(); switch (agentConfiguration.Strategy) { case winningStrategy: strategy = new WinningStrategy(); break; case doNothingStrategy: strategy = new DoNothingStrategy(); break; default: strategy = new SimpleStrategy(); break; } injectedMessages = new List <BaseMessage>(); AgentState = AgentState.Created; ProcessMessages = new ProcessMessages(this); }
static void Main(string[] args) { AgentConfiguration configuration = AgentConfiguration.ReadConfiguration(args); CreateLogger(configuration.LoggingMode); using (Agent agent = new Agent(configuration)) agent.StartListening(); }
public Agent(AgentConfiguration configuration) { this.Configuration = configuration; _client = new TcpClient(Configuration.CsIp, Configuration.CsPort); NetworkStream stream = _client.GetStream(); this._communicator = new SenderReceiverQueueAdapter(new StreamMessageSenderReceiver(stream, new Parser()), HandleJoinTimeError); }
public static AgentConfiguration LoadFromFile(string filename) { var logger = NLog.LogManager.GetCurrentClassLogger(); try { var text = File.ReadAllText(@filename); AgentConfiguration agentConfiguration = JsonConvert.DeserializeObject <AgentConfiguration>(text); logger.Info("[AgentConfiguration] Configuration loaded from {name}", filename); return(agentConfiguration); } catch (Exception e) { logger.Error("[AgentConfiguration] Cannot load configuration!"); logger.Error(e.Message); } return(null); }
private static Agent[] CreateDefaultAgents(int blue, int red, AgentConfiguration defaultConfig) { var agents = new Agent[blue + red]; for (int i = 0; i < blue; i++) { var config = defaultConfig; config.TeamID = "blue"; agents[i] = new Agent(config); } for (int i = 0; i < red; i++) { var config = defaultConfig; config.TeamID = "red"; agents[blue + i] = new Agent(config); } return(agents); }
private static AgentConfiguration CreateAgentConfiguration() { var config = AgentConfiguration.GetDefault(); Console.WriteLine("Do you want to load configuration from file? [Y]/[*]"); ConsoleKey key = Console.ReadKey().Key; Console.WriteLine(); if (key == ConsoleKey.Y) { Console.WriteLine("Enter path: "); var line = Console.ReadLine(); var newConfig = AgentConfiguration.LoadFromFile(line); if (newConfig != null) { config = newConfig; } } return(config); }