Beispiel #1
0
        public SquareBoardBase GetSquareFromMove(SquareBoardBase baseSquare, Move toMove)
        {
            int x = baseSquare.x + toMove.gridAdjustment[0];
            int y = baseSquare.y + toMove.gridAdjustment[1];

            return(boardData[x][y]);
        }
Beispiel #2
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);
                }
            }
        }
Beispiel #3
0
        //Copied from another algorithm state
        //We reset some data, so we dont reflect values that aren't true for the new state
        //This constructor is called when a new step is being generated, so we transfer some values appropriately.
        public AlgorithmState(AlgorithmState setFrom)
        {
            cansCollected = setFrom.cansCollected;

            episodeRewards = setFrom.episodeRewards; //Reward data
            totalRewards   = setFrom.totalRewards;

            boardData = new BoardGame(setFrom.boardData); //Copy the board

            //Increase steps in here
            liveQmatrix = new Qmatrix(setFrom.liveQmatrix); //Copy the q matrix

            //The initial location will be the resulting location of the last step
            locationInitial = boardData.GetUnitSquare[UnitType.Bender];

            //Detect if we reached the limit for this episode


            if (liveQmatrix.setNumber == Qmatrix.stepLimit || setFrom.benderAttacked)
            {
                if (liveQmatrix.episodeNumber == Qmatrix.episodeLimit)
                {
                    AlgorithmManager.algorithmEnded = true;
                }
                else
                {
                    StartNewEpisode();
                }
            }
            else
            {
                liveQmatrix.setNumber++;
            }
        }
        //Pretty sure this isn't necessary since a constructor can just do this
        public void copyStatus(SquareBoardBase copyFrom)
        {
            UnitsPresent = new Dictionary <UnitBase, bool>();
            foreach (var i in copyFrom.UnitsPresent)
            {
                UnitsPresent.Add(i.Key, i.Value);
            }

            visitedState   = copyFrom.visitedState;
            beerCanPresent = copyFrom.beerCanPresent;
            x = copyFrom.x;
            y = copyFrom.y;
        }
 public SquareBoardBase(SquareBoardBase setFrom)
 {
     copyStatus(setFrom);
 }