Exemplo n.º 1
0
 public VisualizerHost(ExtendedRunnerModel extendedRunnerModel)
 {
     this.extendedRunnerModel = extendedRunnerModel;
     this.extendedRunnerModel.WorldUpdated += OnWorldUpdated;
     this.extendedRunnerModel.BeforeMove   += BeforeMove;
     this.extendedRunnerModel.AfterMove    += AfterMove;
 }
Exemplo n.º 2
0
        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();
            }
        }