示例#1
0
        public ViewModel.Output Execute(ViewModel.Map input)
        {
            ViewModel.Position positionActual = new ViewModel.Position();
            ViewModel.Position positionFuture = new ViewModel.Position();
            ViewModel.Output   output         = new ViewModel.Output();
            output.visited.Add(input.start);

            int batteryInitial     = input.battery;
            int batteryConsumption = 0;

            positionActual = input.start;
            int Max = input.map[0].Count;

            foreach (string command in input.commands)
            {
                OperateCommand(command, ref batteryInitial, ref batteryConsumption, input.map.Count, input.map[0].Count, ref positionActual, ref positionFuture, ref input, ref output);
            }
            return(output);
        }
示例#2
0
        private void DoAction(ViewModel.Map input, ref ViewModel.Position position, ref int batteryConsumption, ref ViewModel.Output output)
        {
            string cellValue = input.map[position.X][position.Y].ToString();

            if (cellValue == "S")
            {
                output.visited.Add(position);
            }
            else if (cellValue == "C")
            {
                output.visited.Add(position);
                output.cleaned.Add(position);
                batteryConsumption = batteryConsumption + 5;
            }
            else if (cellValue == "NULL")
            {
                DoAction(input, ref position, ref batteryConsumption, ref output);
            }
        }
示例#3
0
        private void OperateCommand(string command, ref int batteryInitial, ref int batteryConsumption, int xMax, int yMax, ref ViewModel.Position positionActual, ref ViewModel.Position positionFuture, ref ViewModel.Map input, ref ViewModel.Output output)
        {
            if (batteryInitial > batteryConsumption)
            {
                switch (command)
                {
                case "A":
                    NewPosition(positionActual, ref positionFuture, true, xMax, yMax);
                    batteryConsumption = batteryConsumption + 2;
                    DoAction(input, ref positionActual, ref batteryConsumption, ref output);
                    break;

                case "B":
                    NewPosition(positionActual, ref positionFuture, false, xMax, yMax);
                    batteryConsumption = batteryConsumption + 3;
                    DoAction(input, ref positionActual, ref batteryConsumption, ref output);
                    break;

                case "TL":
                    Turn(command, ref positionActual);
                    batteryConsumption = batteryConsumption + 1;
                    break;

                case "TR":
                    Turn(command, ref positionActual);
                    batteryConsumption = batteryConsumption + 1;
                    break;
                }
            }
        }