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); }
//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); } } }