/// $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ /// Neighbouring Boards codes /// $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ // function to help convert the enum to the appropriate board reference public JSFBoard boardEnumToReference(JSFBoardDirection bd) { switch (bd) { case JSFBoardDirection.Top: return(top); case JSFBoardDirection.Bottom: return(bottom); case JSFBoardDirection.Left: return(left); case JSFBoardDirection.Right: return(right); case JSFBoardDirection.TopLeft: return(topLeft); case JSFBoardDirection.TopRight: return(topRight); case JSFBoardDirection.BottomLeft: return(bottomLeft); case JSFBoardDirection.BottomRight: return(bottomRight); default: return(null); } }
// neighbouring function to get all boards in this specific direction public List <JSFBoard> getAllBoardInDirection(JSFBoardDirection bd) { List <JSFBoard> list = new List <JSFBoard>(); JSFBoard chain = boardEnumToReference(bd); while (chain != null) // recursively add the boards in the specified direction { list.Add(chain); chain = chain.boardEnumToReference(bd); } return(list); // returns the list of boards in the direction }
// neighbouring function to get a board in this specific direction and distance public JSFBoard getBoardFromDirection(JSFBoardDirection bd, int distance) { JSFBoard target = boardEnumToReference(bd); // initial for (int x = 1; x < distance; x++) // recursively find the board in the specified direction { if (target == null) { break; // no board here... do not continue... } target = target.boardEnumToReference(bd); } return(target); }