public bool IsValidPosition(BoardPosition position) { if(!IsInBounds(position)) return false; Key key = GetKeyInternal(position.X, position.Y); if (key == Key.Invalid) return false; return true; }
private List<BoardPosition> GetPotentialMoves(BoardPosition cp) { List<BoardPosition> potentialMoves = new List<BoardPosition>(); int CX = cp.X; //current X int CY = cp.Y; //current Y //there are 8 possible knight moves potentialMoves.Add(new BoardPosition() { X = CX - 1, Y = CY + 2 }); potentialMoves.Add(new BoardPosition() { X = CX + 1, Y = CY + 2 }); potentialMoves.Add(new BoardPosition() { X = CX - 1, Y = CY - 2 }); potentialMoves.Add(new BoardPosition() { X = CX + 1, Y = CY - 2 }); potentialMoves.Add(new BoardPosition() { X = CX - 2, Y = CY - 1 }); potentialMoves.Add(new BoardPosition() { X = CX - 2, Y = CY + 1 }); potentialMoves.Add(new BoardPosition() { X = CX + 2, Y = CY + 1 }); potentialMoves.Add(new BoardPosition() { X = CX + 2, Y = CY - 1 }); return potentialMoves; }
private bool IsInBounds(BoardPosition position) { return IsValidXPosition(position.X) && IsValidYPosition(position.Y); }
public Key GetKey(BoardPosition position) { if(!IsValidPosition(position)) throw new InvalidPositionException(position.ToString()); return GetKeyInternal(position.X, position.Y); }