/*UP=1, * RIGHT=2, * DOWN=3, * LEFT=4, * VOID=5 */ // mapping since hte helper functions are diff. public Vector2 GetNewPosition(Vector2 startPos, MovementCommandEnum moveCommand) { Helpers.DirectionEnum newDir; switch (moveCommand) { case MovementCommandEnum.NORTH: newDir = Helpers.DirectionEnum.UP; break; case MovementCommandEnum.SOUTH: newDir = Helpers.DirectionEnum.DOWN; break; case MovementCommandEnum.EAST: newDir = Helpers.DirectionEnum.RIGHT; break; case MovementCommandEnum.WEST: newDir = Helpers.DirectionEnum.LEFT; break; default: throw new Exception("DER FARK?"); } Vector2 retVal = Helpers.MovePos(startPos, newDir); return(retVal); }
public RobotResultCode RunRobotCycle(MovementCommandEnum moveCommand) { // run until there's output. curComputer.AddInputData((int)moveCommand); curComputer.ResumeProgram(); return((RobotResultCode)curComputer.ReadOutputData()); }
void RunRobot() { RobotResultCode resultCode; // Dumb bot // go till wall, then turn right. for (int intI = 0; intI < 4000; intI++) { resultCode = RunRobotCycle(curDir); ProcessRobotResult(resultCode); if (resultCode == RobotResultCode.MOVE_SUCCESFUL_OXYGEN) { oxygenIndex = Helpers.GetIndexFromCoordinate(curPos, xSize); } // forwards or backwards! if (curNode.IsExplored()) { // keep backtracking // we already went ever direction // back up one and check isBackTracking = true; if (fromStartCommands.Count == 0) { return; } MovementCommandEnum prevMove = fromStartCommands.Pop(); curDir = GetOppositeCommand(prevMove); } else { isBackTracking = false; curDir = curNode.GetUnexploredDir(); } } }
public void InitializeExploreNode(RobotResultCode curType, ExploreNode parentNode, MovementCommandEnum enterDir) { parentNode.AssignMovementNode(this, enterDir); MovementCommandEnum exitDir = RepairBot.GetOppositeCommand(enterDir); AssignMovementNode(parentNode, exitDir); nodeType = curType; }
void AssignMovementNode(ExploreNode newNode, MovementCommandEnum curDir) { if (curDir == MovementCommandEnum.NORTH) { northNode = newNode; } if (curDir == MovementCommandEnum.SOUTH) { southNode = newNode; } if (curDir == MovementCommandEnum.EAST) { eastNode = newNode; } if (curDir == MovementCommandEnum.WEST) { westNode = newNode; } }
public static MovementCommandEnum GetOppositeCommand(MovementCommandEnum curCommand) { switch (curCommand) { case MovementCommandEnum.NORTH: return(MovementCommandEnum.SOUTH); case MovementCommandEnum.EAST: return(MovementCommandEnum.WEST); case MovementCommandEnum.SOUTH: return(MovementCommandEnum.NORTH); case MovementCommandEnum.WEST: return(MovementCommandEnum.EAST); default: throw new Exception("DER FARK"); } return(MovementCommandEnum.NORTH); }
MovementCommandEnum TurnRight(MovementCommandEnum startDir) { if (startDir == MovementCommandEnum.NORTH) { return(MovementCommandEnum.EAST); } if (startDir == MovementCommandEnum.SOUTH) { return(MovementCommandEnum.WEST); } if (startDir == MovementCommandEnum.EAST) { return(MovementCommandEnum.SOUTH); } if (startDir == MovementCommandEnum.WEST) { return(MovementCommandEnum.NORTH); } throw new Exception("DER FARK"); return(MovementCommandEnum.EAST); }
ExploreNode GetNodeForDir(MovementCommandEnum curDir) { if (curDir == MovementCommandEnum.NORTH) { return(northNode); } if (curDir == MovementCommandEnum.SOUTH) { return(southNode); } if (curDir == MovementCommandEnum.EAST) { return(eastNode); } if (curDir == MovementCommandEnum.WEST) { return(westNode); } return(null); }