public Message ProcessRequest(Map map, Message message, GMConfiguration configuration) { Log.Information("Processing message from agent {Agent}", _agentId); Log.Debug("Received message content: {@Message}", message); ClearHandler(); BaseReadMessage(message); CheckAgentPenaltyIfNeeded(map); if (_hasTimePenalty) { return(GetPenaltyError(map)); } if (CheckRequest(map)) { Execute(map); SetTimeout(configuration, map); } var response = GetResponse(map); if (response.AgentId == null) { response.AgentId = _agentId; } Log.Debug("Prepared response: {@Response}", response); return(response); }
public GameMaster(IGuiMantainer guiMantainer, GMConfiguration config, IMessageHandler messageHandler) { _guiMantainer = guiMantainer; _gmConfiguration = config; _messageHandler = messageHandler; _gameEnder = new GameEnder(); }
protected override void SetTimeout(GMConfiguration config, Map map) { if (_accepted) { map.GetPlayerById(_agentId).TryLock(DateTime.MinValue); } }
public static void Main(string[] args) { Log.Logger.Information("GameMaster started"); GMConfiguration config = GMConfiguration.ReadConfiguration(args); CreateLogger(config.LoggingMode); GameMaster gameMaster = new GameMaster(new GuiMantainer(), config, new ProxyMessageHandler()); gameMaster.Start(); gameMaster.WaitForEnd(); Log.CloseAndFlush(); gameMaster.Dispose(); }
public void TestReceiveRequest() { StubGuiMaintainer guiMantainer = new StubGuiMaintainer(); GMConfiguration config = new GMConfiguration() { BoardX = 40, BoardY = 40, CsIP = "127.0.0.1", CsPort = 8081, MovePenalty = 1500, DiscoveryPenalty = 700, PutPenalty = 500, CheckForShamPenalty = 700, InformationExchangePenalty = 1000, GoalAreaHeight = 5, NumberOfGoals = 5, NumberOfPieces = 10, ShamPieceProbability = 20 }; TcpListener serverSideListener = new TcpListener(IPAddress.Any, config.CsPort); serverSideListener.Start(); TcpClient serverSide = null; var task = new Task(() => serverSide = serverSideListener.AcceptTcpClient()); task.Start(); GameMaster.GameMaster gm = new GameMaster.GameMaster(guiMantainer, config, new ProxyMessageHandler()); gm.Start(); guiMantainer.StartGame(); var gmTask = new Task(() => gm.WaitForEnd()); gmTask.Start(); task.Wait(); serverSideListener.Stop(); IMessageSenderReceiver senderReceiver = new StreamMessageSenderReceiver(serverSide.GetStream(), new Parser()); var message = new Message <DiscoveryRequest>() { AgentId = 1, MessagePayload = new DiscoveryRequest() }; senderReceiver.Send(message); senderReceiver.StartReceiving(m => { Assert.AreEqual(m.MessageId, MessageType.DiscoveryResponse); }); }
public void CreateConfigurationWithGivenPath() { //Given string configuration = "{\"boardX\": 40," + " \"boardY\": 40," + "\"CsIP\": \"127.0.0.1\"," + "\"CsPort\": 8080," + "\"movePenalty\": 1500," + "\"discoveryPenalty\": 700," + "\"putPenalty\": 500," + "\"checkForShamPenalty\": 700," + "\"informationExchangePenalty\": 1000," + "\"goalAreaHeight\": 5," + "\"numberOfGoals\": 5," + "\"numberOfPieces\": 10," + "\"destroyPiecePenalty\": 100," + "\"shamPieceProbability\": 0.5," + "\"teamSize\": 5}"; string pathToTMPFile = "testConfig"; File.WriteAllText(pathToTMPFile, configuration); //When GMConfiguration gmConfig = GMConfiguration.ReadConfiguration(new string[] { "./" + pathToTMPFile }); //Then Assert.AreEqual(40, gmConfig.BoardX); Assert.AreEqual(40, gmConfig.BoardY); Assert.AreEqual("127.0.0.1", gmConfig.CsIP); Assert.AreEqual(8080, gmConfig.CsPort); Assert.AreEqual(1500, gmConfig.MovePenalty); Assert.AreEqual(1000, gmConfig.InformationExchangePenalty); Assert.AreEqual(700, gmConfig.DiscoveryPenalty); Assert.AreEqual(500, gmConfig.PutPenalty); Assert.AreEqual(700, gmConfig.CheckForShamPenalty); Assert.AreEqual(5, gmConfig.TeamSize); Assert.AreEqual(5, gmConfig.NumberOfGoals); Assert.AreEqual(10, gmConfig.NumberOfPieces); Assert.AreEqual(5, gmConfig.TeamSize); Assert.AreEqual(100, gmConfig.DestroyPiecePenalty); Assert.AreEqual(0.5, gmConfig.ShamPieceProbability); File.Delete(pathToTMPFile); }
public GameStarter(IMessageSenderReceiver communicator, GMConfiguration configuration) { _communicator = communicator; _configuration = configuration; }
protected override void SetTimeout(GMConfiguration config, Map map) { return; }
protected override void SetTimeout(GMConfiguration config, Map map) { map.GetPlayerById(_agentId).TryLock(DateTime.Now.AddMilliseconds(config.DestroyPiecePenalty)); }
public Message ProcessRequest(Map map, Message message, GMConfiguration configuration) { return(handlers[message.MessageId].ProcessRequest(map, message, configuration)); }
protected abstract void SetTimeout(GMConfiguration config, Map map);