/// Author: Bert van Montfort /// <summary> /// Solves a concrete condition like "can the robot go forward?" /// or "is the robot at the grocery store?" /// </summary> /// <returns>False if the check failed, true if it succeeded</returns> /// <param name="instruction">Instruction.</param> public bool solvePiece(ECanInstructions instruction) { Robot robot = Robot.Instance; switch (instruction) { case ECanInstructions.Backward: return robot.canMove (ECanInstructions.Backward); case ECanInstructions.Forward: return robot.canMove (ECanInstructions.Forward); case ECanInstructions.Left: return robot.canMove (ECanInstructions.Left); case ECanInstructions.Right: return robot.canMove (ECanInstructions.Right); case ECanInstructions.At: if (shopName != null) { return robot.At (shopName); } else { return false; } case ECanInstructions.None: break; default: break; } return false; }
/// <summary> /// A Switch for checking whether the robot can move to a certain direction /// </summary> /// <returns><c>true</c>, if the robot can move in the specified direction, <c>false</c> if the robot can move in the specified direction</returns> /// <param name="eCanInstructions">E can instructions.</param> public bool canMove(ECanInstructions eCanInstruction) { return level.checkMove (xPosition, yPosition, eCanInstruction, this.orientationEnum); }
public ConcreteInstruction(ECanInstructions instruction , string shopName) { this.instruction = instruction; this.shopName = shopName; }
/// <summary> /// Checks if a move in a certain direction is possible /// </summary> /// <returns><c>true</c>, if move is possible, <c>false</c> otherwise.</returns> /// <param name="x">The x coordinate.</param> /// <param name="y">The y coordinate.</param> /// <param name="canInstruction">Can instruction.</param> public bool checkMove(int x, int y, ECanInstructions canInstruction, EOrientation robotOrientation) { var tile = map [y, x]; switch (canInstruction) { case ECanInstructions.Forward: switch (robotOrientation) { case EOrientation.North: return tile.North; case EOrientation.East: return tile.East; case EOrientation.South: return tile.South; case EOrientation.West: return tile.West; default: return false; } case ECanInstructions.Backward: switch (robotOrientation) { case EOrientation.North: return tile.South; case EOrientation.East: return tile.West; case EOrientation.South: return tile.North; case EOrientation.West: return tile.East; default: return false; } case ECanInstructions.Left: switch (robotOrientation) { case EOrientation.North: return tile.West; case EOrientation.East: return tile.North; case EOrientation.South: return tile.East; case EOrientation.West: return tile.South; default: return false; } case ECanInstructions.Right: switch (robotOrientation) { case EOrientation.North: return tile.East; case EOrientation.East: return tile.South; case EOrientation.South: return tile.West; case EOrientation.West: return tile.North; default: return false; } case ECanInstructions.None: return false; default: return false; } }
public ConcreteInstruction(ECanInstructions instruction) { this.instruction = instruction; }