public override IEnumerable<BoardCoordinate> GetMovesFrom(BoardCoordinate startingLocation, int boardSize) { yield return new BoardCoordinate(startingLocation.X, startingLocation.Y+1); if(!HasMoved) yield return new BoardCoordinate(startingLocation.X, startingLocation.Y + 2); }
public void AddPiece(Piece piece, BoardCoordinate moveTarget) { if(!moveTarget.IsCoordinateValidForBoardSize(BoardSize)) throw new ArgumentException("moveTarget"); _pieces[moveTarget.X, moveTarget.Y] = piece; }
public override IEnumerable<BoardCoordinate> GetMovesFrom(BoardCoordinate startingLocation, int boardSize) { var allDistancesFromStart = Enumerable.Range(1, boardSize+1); var allPossibleBoardCoordinates = allDistancesFromStart.SelectMany(sp => GetRadialDiagonalFrom(startingLocation, sp)); var legalBoardCoordinates = allPossibleBoardCoordinates.Where(bc => bc.IsCoordinateValidForBoardSize(boardSize)); return legalBoardCoordinates; }
private static IEnumerable<BoardCoordinate> GetRadialDiagonalFrom(BoardCoordinate startingPosition, int distance) { yield return new BoardCoordinate(startingPosition.X + distance, startingPosition.Y + distance); yield return new BoardCoordinate(startingPosition.X + distance, startingPosition.Y - distance); yield return new BoardCoordinate(startingPosition.X - distance, startingPosition.Y + distance); yield return new BoardCoordinate(startingPosition.X - distance, startingPosition.Y - distance); }
public override IEnumerable<BoardCoordinate> GetMovesFrom(BoardCoordinate startingLocation, int boardSize) { var availableCoordinates = Enumerable.Range(1, boardSize); var verticalMoves = availableCoordinates.Where(y => startingLocation.Y != y) .Select(y => new BoardCoordinate(startingLocation.X, y)); var horizontalMoves = availableCoordinates.Where(x => startingLocation.X != x) .Select(x => new BoardCoordinate(x, startingLocation.Y)); return verticalMoves.Union(horizontalMoves); }
public abstract IEnumerable<BoardCoordinate> GetMovesFrom(BoardCoordinate startingLocation, int boardSize);
public Piece GetPiece(BoardCoordinate squareInQuestion) { return _pieces[squareInQuestion.X, squareInQuestion.Y]; }