Exemple #1
0
        //Used when the robot moves *only*, otherwise, the perception will be checked from the state of the unit.
        //Generates percepts, and not MoveResults.
        public Percept PercieveMove(Move moveToCheck, UnitType unitToCheck)
        {
            SquareBoardGame unitLocation = GetUnitSquare[unitToCheck];

            if (moveToCheck != Move.Grab && unitLocation.CheckIfWallsPreventMove(moveToCheck))
            {
                return(Percept.Wall); //Wall percieved
            }
            else
            {
                int percieveX = GetUnitSquare[unitToCheck].x + moveToCheck.gridAdjustment[0];
                int percieveY = GetUnitSquare[unitToCheck].y + moveToCheck.gridAdjustment[1];

                SquareBoardBase percieveLocation = boardData[percieveX][percieveY];
                if (percieveLocation.UnitsPresent[unitToCheck.enemy] == true)
                {
                    return(Percept.Enemy);
                }
                if (percieveLocation.beerCanPresent)
                {
                    return(Percept.Can);
                }
                else
                {
                    return(Percept.Empty);
                }
            }
        }
Exemple #2
0
        public MoveResult ApplyMove(UnitType unitToMove, Move moveToApply)
        {
            SquareBoardGame unitSquare = GetUnitSquare[unitToMove];

            unitSquare.visitedState = SquareVisitedState.Last;

            //Get the move result based on the current condition
            if (unitSquare.CheckIfWallsPreventMove(moveToApply))
            {
                return(MoveResult.TravelFailed); //Walls prevent move
            }
            if (moveToApply != Move.Wait && units[unitToMove].perceptionData.perceptionData[moveToApply] == Percept.Enemy)
            {
                return(MoveResult.EnemyEncountered);
            }

            if (moveToApply == Move.Grab)
            {
                if (GetUnitSquare[unitToMove].beerCanPresent)
                {
                    BenderCollectsCan();
                    return(MoveResult.CanCollected);
                }

                else
                {
                    return(MoveResult.CanMissing);
                }
            }
            //Didn't try to grab a can, and didn't hit a wall. We moved successfully.

            MoveUnit(unitToMove, moveToApply);
            units[unitToMove].SetMoveThisStep(moveToApply);
            return(MoveResult.TravelSucceeded);
        }
Exemple #3
0
        public UnitBase(UnitBase setFrom)
        {
            unitName         = setFrom.unitName;
            perceptionData   = setFrom.perceptionData;
            currentLocation  = setFrom.currentLocation;
            previousLocation = setFrom.previousLocation;

            enemy   = setFrom.enemy;
            ID      = setFrom.ID++;
            chasing = setFrom.chasing;

            //Whenever you copy a unit, you know the starting state is the copied unit's most recent perception
            startingPerceptionState = setFrom.perceptionData;
        }