Example #1
0
        /// <summary>
        /// This method takes care of moves the opponent made, as far
        /// as they are provided by the game engine.
        /// </summary>
        /// <param name="commandLine">Command line.</param>
        public void OpponentMoves(string commandLine)
        {
            commandLine = commandLine.Remove (0, 14);
            commandLine = commandLine.Trim ();
            string[] parts = commandLine.Split (' ');

            if (parts.Length < 4) {
                return;
            }

            List<Move> opponentMoves = new List<Move> ();
            Region sourceRegion;
            Region targetRegion;

            for (int i = 0; i < parts.Length; i += 4) {
                if (parts [i + 1].Equals ("place_armies")) {
                    sourceRegion = State.CompleteMap.Regions [int.Parse (parts [i + 2])];
                    PlaceArmiesMove placeArmiesMove = new PlaceArmiesMove (parts [i], sourceRegion, int.Parse (parts [i + 3]));
                    opponentMoves.Add (placeArmiesMove);
                    State.ProcessPlaceArmiesMove (placeArmiesMove);
                }

                if (parts [i + 1].Equals ("attack/transfer")) {
                    sourceRegion = State.CompleteMap.Regions [int.Parse (parts [i + 2])];
                    targetRegion = State.CompleteMap.Regions [int.Parse (parts [i + 3])];
                    AttackTransferMove attackTransferMove =
                        new AttackTransferMove (parts [i], sourceRegion, targetRegion, int.Parse (parts [i + 4]));
                    opponentMoves.Add (attackTransferMove);
                    State.ProcessAttackTransferMove (attackTransferMove);
                    i++;
                }
            }

            State.EnemyBot.MovesLastTurn = opponentMoves;

            if (Logger.IsDebug ()) {
                Logger.Debug ("Parser:\tProcessed the opponent's moves.");
            }
        }
Example #2
0
        /// <summary>
        /// Process a AttackTransferMove, and updates the number of armies
        /// in the source and target region.
        /// </summary>
        /// <param name="move">Move.</param>
        public void ProcessAttackTransferMove(AttackTransferMove move)
        {
            int sourceId = move.SourceRegion.Id;
            int targetId = move.TargetRegion.Id;

            if (VisibleMap.Regions.ContainsKey (sourceId)) {
                Region sourceRegion = VisibleMap.Regions [move.SourceRegion.Id];
                sourceRegion.Armies -= move.Armies;
            }

            if (VisibleMap.Regions.ContainsKey (targetId)) {
                Region targetRegion = VisibleMap.Regions [move.TargetRegion.Id];
                targetRegion.Armies += move.Armies;
            }

            if (Logger.IsDebug ()) {
                Logger.Debug (string.Format("State:\tProcessed attack/transfer from {0} to {1} with {2} armies.",
                    sourceId, targetId, move.Armies));
            }
        }