Esempio n. 1
0
        /// <summary>
        /// Get card priority from user input
        /// </summary>
        /// <param name="deck">Deck to retrieve card from</param>
        /// <param name="card">Card from user input. A priority number or card move abbreviation: U, L, R, B, 1, 2, 3</param>
        /// <returns></returns>
        private int GetCardPriority(Deck deck, string card)
        {
            if (card.Equals("U", StringComparison.InvariantCultureIgnoreCase))
                return deck.GetCard(ProgramCardType.UTurn).Priority;
            if (card.Equals("L", StringComparison.InvariantCultureIgnoreCase))
                return deck.GetCard(ProgramCardType.RotateLeft).Priority;
            if (card.Equals("R", StringComparison.InvariantCultureIgnoreCase))
                return deck.GetCard(ProgramCardType.RotateRight).Priority;
            if (card.Equals("B", StringComparison.InvariantCultureIgnoreCase))
                return deck.GetCard(ProgramCardType.BackUp).Priority;
            if (card.Equals("1", StringComparison.InvariantCultureIgnoreCase))
                return deck.GetCard(ProgramCardType.Move1).Priority;
            if (card.Equals("2", StringComparison.InvariantCultureIgnoreCase))
                return deck.GetCard(ProgramCardType.Move2).Priority;
            if (card.Equals("3", StringComparison.InvariantCultureIgnoreCase))
                return deck.GetCard(ProgramCardType.Move3).Priority;

            return new ProgramCard(int.Parse(card)).Priority;
        }
Esempio n. 2
0
        /// <summary>
        /// Runs simulations on moves based on the cards the robot currently has assigned. 
        /// Robot is expected to be initialized and part of an existing Game.
        /// The robot will not be in the same state after simulation is executed.
        /// </summary>
        /// <param name="robot">Robot to run simulations for</param>
        /// <returns>List of results</returns>
        public static List<List<CardExecutionResult>> Simulate(Robot robot)
        {
            var results = new List<List<CardExecutionResult>>();
            List<List<ProgramCardType>> permutations = CalculateMovePermutations(robot);
            Coordinate position = robot.Position;
            Orientation facing = robot.Facing;

            foreach (var permutation in permutations)
            {
                robot.Position = position;
                robot.Facing = facing;
                robot.Damage = 0;
                robot.PickUpCards();

                var deck = new Deck();
                var permutationResult = new List<CardExecutionResult>();
                for (int i = 0 ; i < permutation.Count; ++i)
                {
                    var card = deck.GetCard(permutation[i]);
                    robot.DealCard(card.Priority, i + 1);
                }

                robot.Game.StartTurn(false /* Deal Cards */);
                int previousDamage = 0;

                while (true)
                {
                    int registersLeft = robot.Game.ExecuteNextRegister();

                    permutationResult.Add(new CardExecutionResult
                    {
                        Card = permutation[permutationResult.Count],
                        Position = robot.Position,
                        Facing = robot.Facing,
                        Damage = robot.Damage - previousDamage
                    });

                    previousDamage = robot.Damage;

                    if (registersLeft == 0)
                        break;
                }

                robot.Game.EndTurn();

                results.Add(permutationResult);
            }

            return results;
        }