private static IEnumerable <ChessMove> MoveWhileValid( ChessboardPosition currentPosition, PositionChange positionChange) { var initialPosition = currentPosition; var chessMoves = new List <ChessMove>(); while (currentPosition.CanMoveBy(positionChange)) { var nextPosition = currentPosition.MovedBy(positionChange); chessMoves.Add(new ChessMove(initialPosition, nextPosition)); currentPosition = nextPosition; } return(chessMoves); }
public IEnumerable <ChessMove> GetPossibleMoves(ChessboardPosition currentPosition) { return(AllowedMoves .Where(currentPosition.CanMoveBy) .Select(move => new ChessMove(currentPosition, currentPosition.MovedBy(move)))); }