public void Run() { try { remoteProcessClient.WriteTokenMessage(token); remoteProcessClient.WriteProtocolVersionMessage(); int teamSize = remoteProcessClient.ReadTeamSizeMessage(); Game game = remoteProcessClient.ReadGameContextMessage(); IStrategy[] strategies = new IStrategy[teamSize]; for (int strategyIndex = 0; strategyIndex < teamSize; ++strategyIndex) { strategies[strategyIndex] = new MyStrategy(); } PlayerContext playerContext; while ((playerContext = remoteProcessClient.ReadPlayerContextMessage()) != null) { Wizard[] playerWizards = playerContext.Wizards; if (playerWizards == null || playerWizards.Length != teamSize) { break; } Move[] moves = new Move[teamSize]; for (int wizardIndex = 0; wizardIndex < teamSize; ++wizardIndex) { Wizard playerWizard = playerWizards[wizardIndex]; Move move = new Move(); moves[wizardIndex] = move; strategies[wizardIndex].Move(playerWizard, playerContext.World, game, move); } remoteProcessClient.WriteMovesMessage(moves); } } //catch (Exception e) //{ // File.WriteAllText("G:\\log.txt", e.Message + "\n" + e.StackTrace); //} finally { remoteProcessClient.Close(); } }
public void Run() { try { _remoteProcessClient.WriteTokenMessage(_token); _remoteProcessClient.WriteProtocolVersionMessage(); int teamSize = _remoteProcessClient.ReadTeamSizeMessage(); Game game = _remoteProcessClient.ReadGameContextMessage(); IStrategy[] strategies = new IStrategy[teamSize]; for (int strategyIndex = 0; strategyIndex < teamSize; ++strategyIndex) { strategies[strategyIndex] = new MyStrategy(); } PlayerContext playerContext; while ((playerContext = _remoteProcessClient.ReadPlayerContextMessage()) != null) { Wizard[] playerWizards = playerContext.Wizards; if (playerWizards == null || playerWizards.Length != teamSize) { break; } Move[] moves = new Move[teamSize]; for (int wizardIndex = 0; wizardIndex < teamSize; ++wizardIndex) { Wizard playerWizard = playerWizards[wizardIndex]; Move move = new Move(); moves[wizardIndex] = move; strategies[wizardIndex].Move(playerWizard, playerContext.World, game, move); } _remoteProcessClient.WriteMovesMessage(moves); } } finally { _remoteProcessClient.Close(); } }
public void Run() { try { remoteProcessClient.WriteTokenMessage(token); remoteProcessClient.WriteProtocolVersionMessage(); int teamSize = remoteProcessClient.ReadTeamSizeMessage(); Game game = remoteProcessClient.ReadGameContextMessage(); ExtendedRunnerModel extendedRunner = new ExtendedRunnerModel(game); VisualizerHost host = new VisualizerHost(extendedRunner); host.Start(); MyStrategy[] strategies = new MyStrategy[teamSize]; for (int strategyIndex = 0; strategyIndex < teamSize; ++strategyIndex) { strategies[strategyIndex] = new MyStrategy(host.Visualizer); } PlayerContext playerContext; while ((playerContext = remoteProcessClient.ReadPlayerContextMessage()) != null) { Wizard[] playerWizards = playerContext.Wizards; if (playerWizards == null || playerWizards.Length != teamSize) { break; } extendedRunner.UpdatePlayerContext(playerContext); extendedRunner.OnBeforeMove(); Move[] moves = new Move[teamSize]; for (int wizardIndex = 0; wizardIndex < teamSize; ++wizardIndex) { Wizard playerWizard = playerWizards[wizardIndex]; Move move = new Move(); moves[wizardIndex] = move; strategies[wizardIndex].Move(playerWizard, playerContext.World, game, move); } remoteProcessClient.WriteMovesMessage(moves); extendedRunner.OnAfterMove(); } host.Stop(); } finally { remoteProcessClient.Close(); } }