public void Run() { try { remoteProcessClient.WriteTokenMessage(token); remoteProcessClient.WriteProtocolVersionMessage(); remoteProcessClient.ReadTeamSizeMessage(); Game game = remoteProcessClient.ReadGameContextMessage(); IStrategy strategy = new MyStrategy(); PlayerContext playerContext; while ((playerContext = remoteProcessClient.ReadPlayerContextMessage()) != null) { Player player = playerContext.Player; if (player == null) { break; } Move move = new Move(); strategy.Move(player, playerContext.World, game, move); remoteProcessClient.WriteMoveMessage(move); } } finally { remoteProcessClient.Close(); } }
public void Run() { try { remoteProcessClient.WriteTokenMessage(token); remoteProcessClient.WriteProtocolVersionMessage(); remoteProcessClient.ReadTeamSizeMessage(); Game game = remoteProcessClient.ReadGameContextMessage(); IStrategy strategy = new MyStrategy(); PlayerContext playerContext; try { while ((playerContext = remoteProcessClient.ReadPlayerContextMessage()) != null) { Player player = playerContext.Player; if (player == null) { break; } Move move = new Move(); strategy.Move(player, playerContext.World, game, move); remoteProcessClient.WriteMoveMessage(move); } } catch (Exception ex) { System.Console.WriteLine("Ошибка... Выход через 3 сек"); System.Console.WriteLine(ex); System.Threading.Thread.Sleep(3000); } } finally { remoteProcessClient.Close(); } }