Exemplo n.º 1
0
    private void MakeMove()
    {
        if (moveList.Count <= 0)
        {
            Debug.Log("Finished!");
            if (gameFinished != null)
            {
                gameFinished();
            }
            return;
        }

        MoveInstruction instruction = moveList.Dequeue();

        List <Vector3> pathList = new List <Vector3>();

        pathList.Add(towersList[instruction.from].disksStack.Peek().position);
        pathList.Add(towersList[instruction.from].upperPoint);
        pathList.Add(towersList[instruction.to].upperPoint);
        pathList.Add(towersList[instruction.to]
                     .GetPositionForDisk(towersList[instruction.from].disksStack.Peek()));

        towersList[instruction.from].disksStack.Peek().Move(pathList);

        towersList[instruction.to].disksStack.Push(towersList[instruction.from].disksStack.Pop());
    }
Exemplo n.º 2
0
        void InternalTest(Vector origin, Vector dest)
        {
            var critterState = new CritterState
            {
                PositionX = origin.X,
                PositionY = origin.Y,
            };

            var instr = new MoveInstruction(dest.X, dest.Y);
            var ticks = 0;

            for (; ticks < 1000; ticks++)
            {
                var finished = instr.Tick(critterState) == false;
                var pos      = new Vector(critterState.PositionX, critterState.PositionY);
                Console.WriteLine($"pos: {pos}");

                if (finished)
                {
                    Assert.IsTrue(Vector.Distance(pos, dest) < MoveInstruction.StepLength);
                    break;
                }
                else
                {
                    Assert.AreNotEqual(pos, origin);
                    Assert.IsTrue(Vector.Distance(pos, dest) < Vector.Distance(origin, dest));
                }
            }

            Console.WriteLine($"finished after {ticks + 1} ticks");
            if (ticks >= 1000)
            {
                Assert.Fail("Too many ticks");
            }
        }
Exemplo n.º 3
0
        public IList <IInstruction> Parse(string input)
        {
            List <IInstruction> instructions = new List <IInstruction>();

            //e.g. LMLMLMLMM
            foreach (char c in input.ToUpper())
            {
                IInstruction newInstruction = new NullInstruction();;

                switch (c)
                {
                case 'L':
                    newInstruction = new LeftInstruction();
                    break;

                case 'M':
                    newInstruction = new MoveInstruction();
                    break;

                case 'R':
                    newInstruction = new RightInstruction();
                    break;

                default:
                    break;
                }

                instructions.Add(newInstruction);
            }

            return(instructions);
        }
Exemplo n.º 4
0
        public void Ctor_None_NoMoves()
        {
            var instruction = new MoveInstruction();
            var act         = instruction.ToString();
            var exp         = "no_moves";

            Assert.AreEqual(exp, act);
        }
Exemplo n.º 5
0
        public void Ctor_TurnRightRightRightRightLeftDown_TurnRightRightDrop()
        {
            var instruction = new MoveInstruction(ActionType.TurnRight, ActionType.Right, ActionType.Right, ActionType.Right, ActionType.Left, ActionType.Left, ActionType.Down);
            var act         = instruction.ToString();
            var exp         = "turnright,right,drop";

            Assert.AreEqual(exp, act);
        }
Exemplo n.º 6
0
        public void Ctor_Skip_Skip()
        {
            var instruction = new MoveInstruction(ActionType.Skip);
            var act         = instruction.ToString();
            var exp         = "skip";

            Assert.AreEqual(exp, act);
        }
Exemplo n.º 7
0
        public void Ctor_LeftDown_LeftDrop()
        {
            var instruction = new MoveInstruction(ActionType.Left, ActionType.Down);
            var act         = instruction.ToString();
            var exp         = "left,drop";

            Assert.AreEqual(exp, act);
        }
Exemplo n.º 8
0
    // Start is called before the first frame update
    public void LoadMoveInstructions(List <Vector3> dirs)
    {
        instructions = new LinkedList <Instruction>();

        foreach (Vector3 v in dirs)
        {
            MoveInstruction instr = new MoveInstruction(gameController,
                                                        this.gameObject,
                                                        v);
            instructions.AddLast(instr);
        }
        currentInstruction = instructions.First;
    }
Exemplo n.º 9
0
        public BotResponse GetResponse(TimeSpan time)
        {
            SetDuration(time);

            var path = DecisionMaker.GetMove(Field, Opponent, Current, Next, State.Round);
            var move = new MoveInstruction(path.Moves.ToArray());

            var response = new BotResponse()
            {
                Move = move,
                Log  = DecisionMaker.GetLog(),
            };

            return(response);
        }
Exemplo n.º 10
0
        public void Move_Instruction_To_West()
        {
            var startPosition = new Position {
                X = 1, Y = 2, D = 'W'
            };
            var endPosition = new Position {
                X = 0, Y = 2, D = 'W'
            };


            IInstruction instruction = new MoveInstruction();
            var          position    = instruction.Execute(startPosition);

            Assert.AreEqual(endPosition.D, position.D);
            Assert.AreEqual(endPosition.X, position.X);
            Assert.AreEqual(endPosition.Y, position.Y);
        }
Exemplo n.º 11
0
        /// <summary>
        /// Parses a string command into an Instruction.
        /// </summary>
        /// <param name="command">The string command to parse</param>
        /// <returns>An concrete Instruction</returns>
        private Instruction ParseCommand(string command)
        {
            // Check which regex matches the command, and therefore derive the command's type
            var matchingRegex = this.Regexes
                                .DefaultIfEmpty(KeyValuePair.Create(InstructionType.Unknown, new Regex("")))
                                .FirstOrDefault(kvp => kvp.Value.IsMatch(command));

            var matchedType = matchingRegex.Key;
            var rgx         = matchingRegex.Value;

            switch (matchedType)
            {
            default:
            case InstructionType.Unknown:
                return(NoopInstruction.Create(command));

            case InstructionType.Place:
            {
                var matches   = rgx.Match(command);
                int x         = int.Parse(matches.Groups.ElementAt(1).Value);
                int y         = int.Parse(matches.Groups.ElementAt(2).Value);
                var direction = Enum.Parse <MovementDirection>(matches.Groups.ElementAt(3).Value.ToTitleCase());
                return(PlaceInstruction.Create(x, y, direction, command));
            }

            case InstructionType.Move:
                return(MoveInstruction.Create(command));

            case InstructionType.Rotate:
            {
                var matches           = rgx.Match(command);
                var rotationDirection = matches.Groups.ElementAt(1).Value.ToLower() == "right"
                                                        ? RotationDirection.Clockwise
                                                        : RotationDirection.CounterClockwise;
                return(RotateInstruction.Create(rotationDirection, command));
            }

            case InstructionType.Report:
                return(ReportInstruction.Create(command));
            }
        }
Exemplo n.º 12
0
        public void parseCommand(String command)
        {
            String[] parts     = command.Split(" ");
            String   direction = parts[0];
            int      amount    = int.Parse(parts[1]);

            Instruction instruction = null;

            if (direction.Equals("foward"))
            {
                instruction = new MoveInstruction(amount);
            }
            if (direction.Equals("left"))
            {
                instruction = new TurnInstruction(amount);
            }
            if (direction.Equals("right"))
            {
                instruction = new TurnInstruction(-1 * amount);
            }

            instructions.Add(instruction);
        }
Exemplo n.º 13
0
 protected override void SetMyBlockInternalArg()
 {
     myBlockInternalArg = new MoveInstruction(this);
 }
 public void Visit(MoveInstruction instruction)
 {
     lines.Add($"{label}\tMOVE {instruction.Destination.GetAssemblySymbol()},{instruction.Source.GetAssemblySymbol()}");
 }