Ejemplo n.º 1
0
    // Update is called once per frame
    void FixedUpdate()
    {
        rb.AddForce(0, 0, forwardForce * Time.deltaTime);

        if (Input.GetKey("d")) // MOVE RIGHT
        {
            ////////////////////////////////////////////////////////////////////////////
            // --- IMPLEMENTING THE COMMAND PATTERN - START HERE ---
            // instead of just calling addforce, we want to package this up as a command
            // and send to an invoker
            // we'll need a command class, some commands, and an invoker...
            //rb.AddForce(sidewaysForce * Time.deltaTime, 0, 0, ForceMode.VelocityChange);
            Command moveRight = new TurnRight(rb, sidewaysForce);
            Invoker invoker   = new Invoker();
            invoker.SetCommand(moveRight);
            invoker.ExecuteCommand();
        }
        if (Input.GetKey("a")) // MOVE LEFT
        {
            //rb.AddForce(-sidewaysForce * Time.deltaTime, 0, 0, ForceMode.VelocityChange);
            Command moveLeft = new TurnLeft(rb, sidewaysForce);
            Invoker invoker  = new Invoker();
            invoker.SetCommand(moveLeft);
            invoker.ExecuteCommand();
        }

        if (rb.position.y < -1f)
        {
            FindObjectOfType <GameManager>().EndGame(null);
        }
    }
Ejemplo n.º 2
0
        public void TurnLeftWhenFacingWest(int startXCord, int startYCord)
        {
            const Heading startingHeading = Heading.West;

            var         command = new TurnLeft();
            RobotVector result  = command.GenerateNewVector(new RobotVector(new Position(startXCord, startYCord), startingHeading));

            DirectionAssertions.AssertHasTurnedToFaceSouth(startXCord, startYCord, result);
        }
        public void TurnRoverLeftWhenExecuteIsCalled()
        {
            TurnLeft turnLeftCommand = new TurnLeft(rover);

            turnLeftCommand.Execute();

            int  expectedCoordX        = 0;
            int  expectedCoordY        = 0;
            char expectedDirectionInfo = 'W';

            Assert.Equal(expectedCoordX, rover.currentCoordinates.coordX);
            Assert.Equal(expectedCoordY, rover.currentCoordinates.coordY);
            Assert.Equal(expectedDirectionInfo, rover.GetDirection());
        }
Ejemplo n.º 4
0
    public float sidewaysForce = 500f;  // Variable that determines the sideways force

    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.A))
        {
            command TurnLeft = new TurnLeft(rb, sidewaysForce);
            Invoker invoker  = new Invoker();
            invoker.SetCommand(TurnLeft);
            invoker.ExecuteCommand();
        }

        if (Input.GetKeyDown(KeyCode.D))
        {
            command TurnRight = new TurnRight(rb, sidewaysForce);
            Invoker invoker   = new Invoker();
            invoker.SetCommand(TurnRight);
            invoker.ExecuteCommand();
        }
    }
        private void InitalizeCommandMapping()
        {
            var advanceCommand = new Advance(AppSettings.SafeGet <int>(Instructions.A.ToString()));

            CommandMapping.Add(Instructions.A, advanceCommand);
            var backCommand = new Back(AppSettings.SafeGet <int>(Instructions.B.ToString()));

            CommandMapping.Add(Instructions.B, backCommand);
            var cleanCommand = new Clean(AppSettings.SafeGet <int>(Instructions.C.ToString()));

            CommandMapping.Add(Instructions.C, cleanCommand);
            var turnLeft = new TurnLeft(AppSettings.SafeGet <int>(Instructions.TL.ToString()));

            CommandMapping.Add(Instructions.TL, turnLeft);
            var turnRight = new TurnRight(AppSettings.SafeGet <int>(Instructions.TR.ToString()));

            CommandMapping.Add(Instructions.TR, turnRight);
        }
Ejemplo n.º 6
0
        public bool DrivingCar(MonsterTruck mTruck, Room room)
        {
            foreach (var item in LatestInput)
            {
                if (mTruck.XPosition <= room.XAxis && mTruck.YPosition <= room.YAxis && mTruck.XPosition > 0 && mTruck.YPosition > 0)
                {
                    switch (item.ToString().ToUpper())
                    {
                    case "F":
                        DriveForward.DriveCarForward(mTruck);
                        break;

                    case "B":
                        DriveBackwards.DriveCarBackwards(mTruck);
                        break;

                    case "L":
                        TurnLeft.TurnCarLeft(mTruck);
                        break;

                    case "R":
                        TurnRight.TurnCarRight(mTruck);
                        break;
                    }
                }
                else
                {
                    //If it crashes before it is finished, there will be no need to continue the simulation
                    break;
                }
            }
            if (mTruck.XPosition > room.XAxis || mTruck.XPosition < 1 || mTruck.YPosition > room.YAxis || mTruck.YPosition < 1)
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
Ejemplo n.º 7
0
            public AgentPosition apply(AgentPosition state, IAction action)
            {
                if (action is Forward)
                {
                    Forward fa = (Forward)action;

                    return(fa.getToPosition());
                }
                else if (action is TurnLeft)
                {
                    TurnLeft tLeft = (TurnLeft)action;
                    return(new AgentPosition(state.getX(), state.getY(), tLeft.getToOrientation()));
                }
                else if (action is TurnRight)
                {
                    TurnRight tRight = (TurnRight)action;
                    return(new AgentPosition(state.getX(), state.getY(), tRight.getToOrientation()));
                }
                // The Action is not understood or is a NoOp
                // the result will be the current state.
                return(state);
            }
Ejemplo n.º 8
0
    // Start is called before the first frame update
    void Start()
    {
        GenerateBoard();
        GenerateValues();
        Button mov1    = Move1.GetComponent <Button>();
        Button mov2    = Move2.GetComponent <Button>();
        Button back    = BackUp.GetComponent <Button>();
        Button left    = TurnLeft.GetComponent <Button>();
        Button right   = TurnRight.GetComponent <Button>();
        Button turn180 = UTurn.GetComponent <Button>();

        mov1.onClick.AddListener(MovePlayer1);
        mov2.onClick.AddListener(MovePlayer2);
        back.onClick.AddListener(BackPlayerUp);
        left.onClick.AddListener(TurnPlayerLeft);
        right.onClick.AddListener(TurnPlayerRight);
        turn180.onClick.AddListener(TurnPlayerU);

        player.GetComponent <PlayerManager>().ai = ai;
        ai.GetComponent <AIManager>().player     = player;

        endCanvas.SetActive(false);
        normalCanvas.SetActive(true);
    }
Ejemplo n.º 9
0
        /**
         *
         * @param current
         *            the agent's current position
         * @param possibleWumpus
         *            a set of squares where we don't know that there isn't the
         *            wumpus.
         * @param allowed
         *            a set of squares that can form part of the route
         *
         * @return the sequence of actions to reach the nearest square that is in
         *         line with a possible wumpus position. The last action is a shot.
         */
        public ICollection <IAction> planShot(AgentPosition current, ISet <Room> possibleWumpus, ISet <Room> allowed)
        {
            ISet <AgentPosition> shootingPositions = CollectionFactory.CreateSet <AgentPosition>();

            foreach (Room p in possibleWumpus)
            {
                int x = p.getX();
                int y = p.getY();

                for (int i = 1; i <= kb.getCaveXDimension(); i++)
                {
                    if (i < x)
                    {
                        shootingPositions.Add(new AgentPosition(i, y, AgentPosition.Orientation.FACING_EAST));
                    }
                    if (i > x)
                    {
                        shootingPositions.Add(new AgentPosition(i, y, AgentPosition.Orientation.FACING_WEST));
                    }
                    if (i < y)
                    {
                        shootingPositions.Add(new AgentPosition(x, i, AgentPosition.Orientation.FACING_NORTH));
                    }
                    if (i > y)
                    {
                        shootingPositions.Add(new AgentPosition(x, i, AgentPosition.Orientation.FACING_SOUTH));
                    }
                }
            }

            // Can't have a shooting position from any of the rooms the wumpus could
            // reside
            foreach (Room p in possibleWumpus)
            {
                foreach (AgentPosition.Orientation orientation in AgentPosition.Orientation.values())
                {
                    shootingPositions.Remove(new AgentPosition(p.getX(), p.getY(), orientation));
                }
            }

            ISet <Room> shootingPositionsArray = CollectionFactory.CreateSet <Room>();

            foreach (AgentPosition tmp in shootingPositions)
            {
                shootingPositionsArray.Add(new Room(tmp.getX(), tmp.getY()));
            }

            ICollection <IAction> actions = planRoute(current, shootingPositionsArray, allowed);

            AgentPosition newPos = current;

            if (actions.Size() > 0)
            {
                newPos = ((Forward)actions.Get(actions.Size() - 1)).getToPosition();
            }

            while (!shootingPositions.Contains(newPos))
            {
                TurnLeft tLeft = new TurnLeft(newPos.getOrientation());
                newPos = new AgentPosition(newPos.getX(), newPos.getY(), tLeft.getToOrientation());
                actions.Add(tLeft);
            }

            actions.Add(new Shoot());
            return(actions);
        }